mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2024-11-23 01:49:53 +00:00
CMake: Use CMakeAutoGen as CMake AutoGen implementation
* By removing the GNU AutoGen dependency of the cmake, libsndfile can be built using only cmake and a compiler toolchain * Fix non-matching FOR and ENDFOR of template src/test_endswap.tpl * Add pcm_test to test suite Related: https://github.com/erikd/libsndfile/issues/71 Closes: https://github.com/erikd/libsndfile/issues/154
This commit is contained in:
parent
d7efb3bfc6
commit
560cefe607
204
CMakeLists.txt
204
CMakeLists.txt
@ -531,57 +531,25 @@ if (BUILD_TESTING)
|
||||
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/src")
|
||||
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
|
||||
|
||||
# Custom commands to generate tests sources from autogen templates
|
||||
include(${CMAKE_MODULE_PATH}/CMakeAutoGen.cmake)
|
||||
|
||||
add_custom_command (
|
||||
OUTPUT ${CMAKE_BINARY_DIR}/tests/benchmark.c
|
||||
COMMAND ${AUTOGEN_EXECUTABLE} --writable -L ${CMAKE_SOURCE_DIR}/tests ${CMAKE_SOURCE_DIR}/tests/benchmark.def
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
|
||||
# generate tests sources from autogen templates
|
||||
lsf_autogen(tests benchmark c)
|
||||
lsf_autogen(tests floating_point_test c)
|
||||
lsf_autogen(tests header_test c)
|
||||
lsf_autogen(tests pcm_test c)
|
||||
lsf_autogen(tests pipe_test c)
|
||||
lsf_autogen(tests rdwr_test c)
|
||||
lsf_autogen(tests scale_clip_test c)
|
||||
lsf_autogen(tests utils c h)
|
||||
lsf_autogen(tests write_read_test c)
|
||||
|
||||
add_custom_command (
|
||||
OUTPUT ${CMAKE_BINARY_DIR}/tests/floating_point_test.c
|
||||
COMMAND ${AUTOGEN_EXECUTABLE} --writable -L ${CMAKE_SOURCE_DIR}/tests ${CMAKE_SOURCE_DIR}/tests/floating_point_test.def
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
|
||||
lsf_autogen(src test_endswap c)
|
||||
|
||||
add_custom_command (
|
||||
OUTPUT ${CMAKE_BINARY_DIR}/tests/header_test.c
|
||||
COMMAND ${AUTOGEN_EXECUTABLE} --writable -L ${CMAKE_SOURCE_DIR}/tests ${CMAKE_SOURCE_DIR}/tests/header_test.def
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
|
||||
|
||||
add_custom_command (
|
||||
OUTPUT ${CMAKE_BINARY_DIR}/tests/pcm_test.c
|
||||
COMMAND ${AUTOGEN_EXECUTABLE} --writable -L ${CMAKE_SOURCE_DIR}/tests ${CMAKE_SOURCE_DIR}/tests/pcm_test.def
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
|
||||
|
||||
add_custom_command (
|
||||
OUTPUT ${CMAKE_BINARY_DIR}/tests/pipe_test.c
|
||||
COMMAND ${AUTOGEN_EXECUTABLE} --writable -L ${CMAKE_SOURCE_DIR}/tests ${CMAKE_SOURCE_DIR}/tests/pipe_test.def
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
|
||||
|
||||
add_custom_command (
|
||||
OUTPUT ${CMAKE_BINARY_DIR}/tests/rdwr_test.c
|
||||
COMMAND ${AUTOGEN_EXECUTABLE} --writable -L ${CMAKE_SOURCE_DIR}/tests ${CMAKE_SOURCE_DIR}/tests/rdwr_test.def
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
|
||||
|
||||
add_custom_command (
|
||||
OUTPUT ${CMAKE_BINARY_DIR}/tests/scale_clip_test.c
|
||||
COMMAND ${AUTOGEN_EXECUTABLE} --writable -L ${CMAKE_SOURCE_DIR}/tests ${CMAKE_SOURCE_DIR}/tests/scale_clip_test.def
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
|
||||
|
||||
add_custom_command (
|
||||
OUTPUT ${CMAKE_BINARY_DIR}/tests/utils.c ${CMAKE_BINARY_DIR}/tests/utils.h
|
||||
COMMAND ${AUTOGEN_EXECUTABLE} --writable -L ${CMAKE_SOURCE_DIR}/tests ${CMAKE_SOURCE_DIR}/tests/utils.def
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
|
||||
|
||||
add_custom_command (
|
||||
OUTPUT ${CMAKE_BINARY_DIR}/tests/write_read_test.c
|
||||
COMMAND ${AUTOGEN_EXECUTABLE} --writable -L ${CMAKE_SOURCE_DIR}/tests ${CMAKE_SOURCE_DIR}/tests/write_read_test.def
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
|
||||
|
||||
add_custom_command (
|
||||
OUTPUT ${CMAKE_BINARY_DIR}/src/test_endswap.c
|
||||
COMMAND ${AUTOGEN_EXECUTABLE} --writable -L ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/test_endswap.def
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src)
|
||||
# utils static library
|
||||
add_library(test_utils STATIC tests/utils.c)
|
||||
target_link_libraries(test_utils PUBLIC ${SNDFILE_TARGET})
|
||||
target_include_directories(test_utils PUBLIC "${CMAKE_BINARY_DIR}/tests")
|
||||
|
||||
### test_main
|
||||
|
||||
@ -615,27 +583,27 @@ if (BUILD_TESTING)
|
||||
|
||||
### error_test
|
||||
|
||||
set (error_test_SOURCES tests/error_test.c tests/utils.c)
|
||||
set (error_test_SOURCES tests/error_test.c)
|
||||
add_executable (error_test ${error_test_SOURCES})
|
||||
target_link_libraries (error_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (error_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(error_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
add_test (error_test error_test)
|
||||
|
||||
### ulaw_test
|
||||
set (ulaw_test_SOURCES tests/utils.c tests/ulaw_test.c)
|
||||
set (ulaw_test_SOURCES tests/ulaw_test.c)
|
||||
add_executable (ulaw_test ${ulaw_test_SOURCES})
|
||||
target_link_libraries (ulaw_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (ulaw_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(ulaw_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
add_test (ulaw_test ulaw_test)
|
||||
|
||||
### alaw_test
|
||||
set (alaw_test_SOURCES tests/utils.c tests/alaw_test.c)
|
||||
set (alaw_test_SOURCES tests/alaw_test.c)
|
||||
add_executable (alaw_test ${alaw_test_SOURCES})
|
||||
target_link_libraries (alaw_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (alaw_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(alaw_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
@ -643,9 +611,9 @@ if (BUILD_TESTING)
|
||||
|
||||
### dwvw_test
|
||||
|
||||
set (dwvw_test_SOURCES tests/utils.c tests/dwvw_test.c)
|
||||
set (dwvw_test_SOURCES tests/dwvw_test.c)
|
||||
add_executable (dwvw_test ${dwvw_test_SOURCES})
|
||||
target_link_libraries (dwvw_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (dwvw_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(dwvw_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
@ -653,9 +621,9 @@ if (BUILD_TESTING)
|
||||
|
||||
### command_test
|
||||
|
||||
set (command_test_SOURCES tests/command_test.c tests/utils.c)
|
||||
set (command_test_SOURCES tests/command_test.c)
|
||||
add_executable (command_test ${command_test_SOURCES})
|
||||
target_link_libraries (command_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (command_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(command_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
@ -663,9 +631,9 @@ if (BUILD_TESTING)
|
||||
|
||||
### floating_point_test
|
||||
|
||||
set (floating_point_test_SOURCES tests/utils.c tests/dft_cmp.c tests/floating_point_test.c)
|
||||
set (floating_point_test_SOURCES tests/dft_cmp.c tests/floating_point_test.c)
|
||||
add_executable (floating_point_test ${floating_point_test_SOURCES})
|
||||
target_link_libraries (floating_point_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (floating_point_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
target_include_directories(floating_point_test PRIVATE tests)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(floating_point_test PRIVATE ${M_LIBRARY})
|
||||
@ -674,9 +642,9 @@ if (BUILD_TESTING)
|
||||
|
||||
### checksum_test
|
||||
|
||||
set (checksum_test_SOURCES tests/checksum_test.c tests/utils.c)
|
||||
set (checksum_test_SOURCES tests/checksum_test.c)
|
||||
add_executable (checksum_test ${checksum_test_SOURCES})
|
||||
target_link_libraries (checksum_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (checksum_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(checksum_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
@ -684,9 +652,9 @@ if (BUILD_TESTING)
|
||||
|
||||
### scale_clip_test
|
||||
|
||||
set (scale_clip_test_SOURCES tests/scale_clip_test.c tests/utils.c)
|
||||
set (scale_clip_test_SOURCES tests/scale_clip_test.c)
|
||||
add_executable (scale_clip_test ${scale_clip_test_SOURCES})
|
||||
target_link_libraries (scale_clip_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (scale_clip_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(scale_clip_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
@ -694,9 +662,9 @@ if (BUILD_TESTING)
|
||||
|
||||
### headerless_test
|
||||
|
||||
set (headerless_test_SOURCES tests/utils.c tests/headerless_test.c)
|
||||
set (headerless_test_SOURCES tests/headerless_test.c)
|
||||
add_executable (headerless_test ${headerless_test_SOURCES})
|
||||
target_link_libraries (headerless_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (headerless_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(headerless_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
@ -704,9 +672,9 @@ if (BUILD_TESTING)
|
||||
|
||||
### rdwr_test
|
||||
|
||||
set (rdwr_test_SOURCES tests/rdwr_test.c tests/utils.c)
|
||||
set (rdwr_test_SOURCES tests/rdwr_test.c)
|
||||
add_executable (rdwr_test ${rdwr_test_SOURCES})
|
||||
target_link_libraries (rdwr_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (rdwr_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(rdwr_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
@ -714,9 +682,9 @@ if (BUILD_TESTING)
|
||||
|
||||
### locale_test
|
||||
|
||||
set (locale_test_SOURCES tests/locale_test.c tests/utils.c)
|
||||
set (locale_test_SOURCES tests/locale_test.c)
|
||||
add_executable (locale_test ${locale_test_SOURCES})
|
||||
target_link_libraries (locale_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (locale_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(locale_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
@ -728,9 +696,9 @@ if (BUILD_TESTING)
|
||||
|
||||
### cpp_test
|
||||
|
||||
set (cpp_test_SOURCES tests/cpp_test.cc tests/utils.c)
|
||||
set (cpp_test_SOURCES tests/cpp_test.cc)
|
||||
add_executable (cpp_test ${cpp_test_SOURCES})
|
||||
target_link_libraries (cpp_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (cpp_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(cpp_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
@ -738,9 +706,9 @@ if (BUILD_TESTING)
|
||||
|
||||
### external_libs_test
|
||||
|
||||
set (external_libs_test_SOURCES tests/external_libs_test.c tests/utils.c)
|
||||
set (external_libs_test_SOURCES tests/external_libs_test.c)
|
||||
add_executable (external_libs_test ${external_libs_test_SOURCES})
|
||||
target_link_libraries (external_libs_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (external_libs_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(external_libs_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
@ -748,9 +716,9 @@ if (BUILD_TESTING)
|
||||
|
||||
### format_check_test
|
||||
|
||||
set (format_check_test_SOURCES tests/format_check_test.c tests/utils.c)
|
||||
set (format_check_test_SOURCES tests/format_check_test.c)
|
||||
add_executable (format_check_test ${format_check_test_SOURCES})
|
||||
target_link_libraries (format_check_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (format_check_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(format_check_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
@ -758,139 +726,149 @@ if (BUILD_TESTING)
|
||||
|
||||
### channel_test
|
||||
|
||||
set (channel_test_SOURCES tests/channel_test.c tests/utils.c)
|
||||
set (channel_test_SOURCES tests/channel_test.c)
|
||||
add_executable (channel_test ${channel_test_SOURCES})
|
||||
target_link_libraries (channel_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (channel_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(channel_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
add_test (channel_test channel_test)
|
||||
|
||||
### pcm_test
|
||||
|
||||
set (pcm_test_SOURCES tests/pcm_test.c)
|
||||
add_executable (pcm_test ${pcm_test_SOURCES})
|
||||
target_link_libraries (pcm_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(pcm_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
add_test (pcm_test pcm_test)
|
||||
|
||||
### common test executables
|
||||
|
||||
set (write_read_test_SOURCES tests/utils.c tests/generate.c tests/write_read_test.c)
|
||||
set (write_read_test_SOURCES tests/generate.c tests/write_read_test.c)
|
||||
add_executable (write_read_test ${write_read_test_SOURCES})
|
||||
target_link_libraries (write_read_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (write_read_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
target_include_directories(write_read_test PRIVATE tests)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(write_read_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
|
||||
set (lossy_comp_test_SOURCES tests/utils.c tests/lossy_comp_test.c)
|
||||
set (lossy_comp_test_SOURCES tests/lossy_comp_test.c)
|
||||
add_executable (lossy_comp_test ${lossy_comp_test_SOURCES})
|
||||
target_link_libraries (lossy_comp_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (lossy_comp_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(lossy_comp_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
|
||||
set (peak_chunk_test_SOURCES tests/peak_chunk_test.c tests/utils.c)
|
||||
set (peak_chunk_test_SOURCES tests/peak_chunk_test.c)
|
||||
add_executable (peak_chunk_test ${peak_chunk_test_SOURCES})
|
||||
target_link_libraries (peak_chunk_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (peak_chunk_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(peak_chunk_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
|
||||
set (header_test_SOURCES tests/header_test.c tests/utils.c)
|
||||
set (header_test_SOURCES tests/header_test.c)
|
||||
add_executable (header_test ${header_test_SOURCES})
|
||||
target_link_libraries (header_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (header_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(header_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
|
||||
set (misc_test_SOURCES tests/misc_test.c tests/utils.c)
|
||||
set (misc_test_SOURCES tests/misc_test.c)
|
||||
add_executable (misc_test ${misc_test_SOURCES})
|
||||
target_link_libraries (misc_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (misc_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(misc_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
|
||||
set (string_test_SOURCES tests/string_test.c tests/utils.c)
|
||||
set (string_test_SOURCES tests/string_test.c)
|
||||
add_executable (string_test ${string_test_SOURCES})
|
||||
target_link_libraries (string_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (string_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(string_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
|
||||
set (multi_file_test_SOURCES tests/multi_file_test.c tests/utils.c)
|
||||
set (multi_file_test_SOURCES tests/multi_file_test.c)
|
||||
add_executable (multi_file_test ${multi_file_test_SOURCES})
|
||||
target_link_libraries (multi_file_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (multi_file_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(multi_file_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
|
||||
set (aiff_rw_test_SOURCES tests/utils.c tests/aiff_rw_test.c)
|
||||
set (aiff_rw_test_SOURCES tests/aiff_rw_test.c)
|
||||
add_executable (aiff_rw_test ${aiff_rw_test_SOURCES})
|
||||
target_link_libraries (aiff_rw_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (aiff_rw_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(aiff_rw_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
|
||||
set (chunk_test_SOURCES tests/chunk_test.c tests/utils.c)
|
||||
set (chunk_test_SOURCES tests/chunk_test.c)
|
||||
add_executable (chunk_test ${chunk_test_SOURCES})
|
||||
target_link_libraries (chunk_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (chunk_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(chunk_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
|
||||
set (long_read_write_test_SOURCES tests/long_read_write_test.c tests/utils.c)
|
||||
set (long_read_write_test_SOURCES tests/long_read_write_test.c)
|
||||
add_executable (long_read_write_test ${long_read_write_test_SOURCES})
|
||||
target_link_libraries (long_read_write_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (long_read_write_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(long_read_write_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
|
||||
set (raw_test_SOURCES tests/raw_test.c tests/utils.c)
|
||||
set (raw_test_SOURCES tests/raw_test.c)
|
||||
add_executable (raw_test ${raw_test_SOURCES})
|
||||
target_link_libraries (raw_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (raw_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(raw_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
|
||||
set (compression_size_test_SOURCES tests/compression_size_test.c tests/utils.c)
|
||||
set (compression_size_test_SOURCES tests/compression_size_test.c)
|
||||
add_executable (compression_size_test ${compression_size_test_SOURCES})
|
||||
target_link_libraries (compression_size_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (compression_size_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(compression_size_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
|
||||
set (ogg_test_SOURCES tests/ogg_test.c tests/utils.c)
|
||||
set (ogg_test_SOURCES tests/ogg_test.c)
|
||||
add_executable (ogg_test ${ogg_test_SOURCES})
|
||||
target_link_libraries (ogg_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (ogg_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(ogg_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
|
||||
set (stdin_test_SOURCES tests/stdin_test.c tests/utils.c)
|
||||
set (stdin_test_SOURCES tests/stdin_test.c)
|
||||
add_executable (stdin_test ${stdin_test_SOURCES})
|
||||
target_link_libraries (stdin_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (stdin_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(stdin_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
|
||||
set (stdout_test_SOURCES tests/stdout_test.c)
|
||||
add_executable (stdout_test ${stdout_test_SOURCES})
|
||||
target_link_libraries (stdout_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (stdout_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(stdout_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
|
||||
set (stdio_test_SOURCES tests/stdio_test.c tests/utils.c)
|
||||
set (stdio_test_SOURCES tests/stdio_test.c)
|
||||
add_executable (stdio_test ${stdio_test_SOURCES})
|
||||
target_link_libraries (stdio_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (stdio_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(stdio_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
|
||||
set (pipe_test_SOURCES tests/pipe_test.c tests/utils.c tests/utils.h)
|
||||
set (pipe_test_SOURCES tests/pipe_test.c)
|
||||
add_executable (pipe_test ${pipe_test_SOURCES})
|
||||
target_link_libraries (pipe_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (pipe_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(pipe_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
|
||||
set (virtual_io_test_SOURCES tests/virtual_io_test.c tests/utils.c)
|
||||
set (virtual_io_test_SOURCES tests/virtual_io_test.c)
|
||||
add_executable (virtual_io_test ${virtual_io_test_SOURCES})
|
||||
target_link_libraries (virtual_io_test PRIVATE ${SNDFILE_TARGET})
|
||||
target_link_libraries (virtual_io_test PRIVATE ${SNDFILE_TARGET} test_utils)
|
||||
if (BUILD_SHARED_LIBS AND LIBM_REQUIRED)
|
||||
target_link_libraries(virtual_io_test PRIVATE ${M_LIBRARY})
|
||||
endif ()
|
||||
|
46
cmake/CMakeAutoGen.cmake
Normal file
46
cmake/CMakeAutoGen.cmake
Normal file
@ -0,0 +1,46 @@
|
||||
# CMake implementation of AutoGen
|
||||
# Copyright (C) 2017 Anonymous Maarten <anonymous.maarten@gmail.com>
|
||||
|
||||
set(AUTOGEN_SCRIPT "${CMAKE_MODULE_PATH}/CMakeAutoGenScript.cmake")
|
||||
|
||||
function(lsf_autogen DIR_REL NAME_WE)
|
||||
set(EXTS ${ARGN})
|
||||
set(INPUT "${CMAKE_SOURCE_DIR}/${DIR_REL}/${NAME_WE}.def")
|
||||
set(OUTPUTS)
|
||||
foreach(EXT ${EXTS})
|
||||
list(APPEND OUTPUTS "${NAME_WE}.${EXT}")
|
||||
endforeach()
|
||||
add_autogen_target("${INPUT}" "${DIR_REL}" ${OUTPUTS})
|
||||
endfunction()
|
||||
|
||||
function(add_autogen_target INPUT OUTPUTDIR)
|
||||
set(OUTPUTFILES "${ARGN}")
|
||||
|
||||
if (OUTPUTDIR)
|
||||
set(PREFIX "${OUTPUTDIR}/")
|
||||
else()
|
||||
set(PREFIX "")
|
||||
endif()
|
||||
|
||||
set(ARTIFACTS)
|
||||
foreach(OUTPUTFILE ${OUTPUTFILES})
|
||||
list(APPEND ARTIFACTS "${PREFIX}${OUTPUTFILE}")
|
||||
endforeach()
|
||||
|
||||
set(EXTRA_ARGS)
|
||||
if (AUTOGEN_DEBUG)
|
||||
list(APPEND EXTRA_ARGS "-DDEBUG=1")
|
||||
endif()
|
||||
if (OUTPUTDIR)
|
||||
list(APPEND EXTRA_ARGS "-DOUTPUTDIR=${OUTPUTDIR}")
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${ARTIFACTS}
|
||||
COMMAND ${CMAKE_COMMAND} "-DDEFINITION=${INPUT}" ${EXTRA_ARGS} -P "${AUTOGEN_SCRIPT}"
|
||||
MAIN_DEPENDENCY "${INPUT}"
|
||||
DEPENDS "${AUTOGEN_SCRIPT}"
|
||||
COMMENT "CMakeAutoGen: generating ${OUTPUTFILES}"
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
|
||||
)
|
||||
endfunction()
|
442
cmake/CMakeAutoGenScript.cmake
Normal file
442
cmake/CMakeAutoGenScript.cmake
Normal file
@ -0,0 +1,442 @@
|
||||
# CMake implementation of AutoGen
|
||||
# Copyright (C) 2017 Anonymous Maarten <anonymous.maarten@gmail.com>
|
||||
|
||||
set(WS " \t\r\n")
|
||||
|
||||
function(cutoff_first_occurrence TEXT OCCURRENCE RESULT)
|
||||
string(FIND "${TEXT}" "${OCCURRENCE}" OCCURRENCE_INDEX)
|
||||
if (OCCURRENCE_INDEX EQUAL -1)
|
||||
set(${TEXT} "" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
string(LENGTH "${OCCURRENCE}" OCCURRENCE_LENGTH)
|
||||
math(EXPR CUTOFF_INDEX "${OCCURRENCE_INDEX}+${OCCURRENCE_LENGTH}")
|
||||
string(SUBSTRING "${TEXT}" ${CUTOFF_INDEX} -1 TEXT_REMAINDER)
|
||||
set(${RESULT} "${TEXT_REMAINDER}" PARENT_SCOPE)
|
||||
|
||||
endfunction()
|
||||
|
||||
function(read_definition DEFINITION_FILENAME TEMPLATE_FILENAME DATA)
|
||||
file(READ "${DEFINITION_FILENAME}" DEFINITION_CONTENTS)
|
||||
|
||||
string(REGEX MATCH "autogen definitions ([a-zA-Z\\._-]+);[${WS}]*" TEMPLATE_MATCH "${DEFINITION_CONTENTS}")
|
||||
if (NOT TEMPLATE_MATCH)
|
||||
message(FATAL_ERROR "${DEFINITION_FILENAME} doest not contain an AutoGen definition.")
|
||||
endif()
|
||||
|
||||
get_filename_component(DEFINITION_DIR "${DEFINITION_FILENAME}" PATH)
|
||||
set(${TEMPLATE_FILENAME} "${DEFINITION_DIR}/${CMAKE_MATCH_1}" PARENT_SCOPE)
|
||||
if (DEBUG)
|
||||
message("found: TEMPLATE_FILENAME=${CMAKE_MATCH_1}")
|
||||
endif()
|
||||
|
||||
cutoff_first_occurrence("${DEFINITION_CONTENTS}" "${TEMPLATE_MATCH}" DEFINITION_CONTENTS)
|
||||
|
||||
set(DEFINITION "")
|
||||
|
||||
while (1)
|
||||
string(REGEX MATCH "([a-zA-Z_][a-zA-Z0-9_]*)[${WS}]*=[${WS}]*{[${WS}]*" GROUPSTART_MATCH "${DEFINITION_CONTENTS}")
|
||||
if (NOT GROUPSTART_MATCH)
|
||||
break()
|
||||
endif()
|
||||
set(GROUPNAME "${CMAKE_MATCH_1}")
|
||||
cutoff_first_occurrence("${DEFINITION_CONTENTS}" "${GROUPSTART_MATCH}" DEFINITION_CONTENTS)
|
||||
if (DEBUG)
|
||||
message("found: GROUPNAME=${GROUPNAME}")
|
||||
endif()
|
||||
set(NBKEYS 0)
|
||||
set(GROUP_KEY_VALUES "")
|
||||
while (1)
|
||||
string(REGEX MATCH "^([a-zA-Z_][a-zA-Z0-9_]*)[${WS}]*=[${WS}]*(([\"']([${WS}a-zA-Z0-9_%\\\"<>\(\)\\.*+/?:,\\-]+)[\"'])|([a-zA-Z0-9_%\\]+))[${WS}]*;[${WS}]*" KEY_VALUE_MATCH "${DEFINITION_CONTENTS}")
|
||||
if (NOT KEY_VALUE_MATCH)
|
||||
break()
|
||||
endif()
|
||||
set(KEY "${CMAKE_MATCH_1}")
|
||||
if ("${CMAKE_MATCH_4}" STREQUAL "")
|
||||
set(VALUE "${CMAKE_MATCH_5}")
|
||||
else()
|
||||
string(REPLACE "\\\"" "\"" VALUE "${CMAKE_MATCH_4}")
|
||||
#set(VALUE "${CMAKE_MATCH_4}")
|
||||
endif()
|
||||
|
||||
if (DEBUG)
|
||||
message("found: KEY=${KEY}, VALUE=${VALUE}")
|
||||
endif()
|
||||
math(EXPR NBKEYS "${NBKEYS}+1")
|
||||
list(APPEND GROUP_KEY_VALUES "${KEY}" "${VALUE}")
|
||||
cutoff_first_occurrence("${DEFINITION_CONTENTS}" "${KEY_VALUE_MATCH}" DEFINITION_CONTENTS)
|
||||
endwhile()
|
||||
string(REGEX MATCH "^[${WS}]*}[${WS}]*;[${WS}]*" GROUPEND_MATCH "${DEFINITION_CONTENTS}")
|
||||
if (NOT GROUPEND_MATCH)
|
||||
message(FATAL_ERROR "Group ${GROUPNAME} did not finish.")
|
||||
endif()
|
||||
cutoff_first_occurrence("${DEFINITION_CONTENTS}" "${GROUPEND_MATCH}" DEFINITION_CONTENTS)
|
||||
list(APPEND DEFINITION "${GROUPNAME}" ${NBKEYS} ${GROUP_KEY_VALUES})
|
||||
endwhile()
|
||||
set(${DATA} "${DEFINITION}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(match_autogen_group TEXT START POS0 POS1 MATCH FOUND)
|
||||
string(SUBSTRING "${TEXT}" "${START}" -1 TEXT)
|
||||
string(REGEX MATCH "\\[\\+[${WS}]*([ a-zA-Z0-9=_$%\\(\\)\"\\+\\-]+)[${WS}]*\\+\\]" MATCH_GROUP "${TEXT}")
|
||||
if ("${MATCH_GROUP}" STREQUAL "")
|
||||
set(${FOUND} 0 PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
string(FIND "${TEXT}" "${MATCH_GROUP}" START_TEXT)
|
||||
math(EXPR POS0_var "${START}+${START_TEXT}")
|
||||
string(LENGTH "${MATCH_GROUP}" MATCH_LENGTH)
|
||||
math(EXPR POS1_var "${POS0_var}+${MATCH_LENGTH}")
|
||||
set(${POS0} "${POS0_var}" PARENT_SCOPE)
|
||||
set(${POS1} "${POS1_var}" PARENT_SCOPE)
|
||||
set(${FOUND} 1 PARENT_SCOPE)
|
||||
string(STRIP "${CMAKE_MATCH_1}" CONTENT)
|
||||
set("${MATCH}" "${CONTENT}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(append_output SUFFICES_FILENAMES TEXT POS0 POS1 FILTER)
|
||||
math(EXPR POS_LENGTH "${POS1}-${POS0}")
|
||||
string(LENGTH "${TEXT}" TEXT_LENGTH)
|
||||
string(SUBSTRING "${TEXT}" "${POS0}" "${POS_LENGTH}" TEXT_APPEND)
|
||||
if (DEBUG)
|
||||
message("appending ${POS0}:${POS1}, length=${POS_LENGTH}")
|
||||
endif()
|
||||
append_output_text("${SUFFICES_FILENAMES}" "${TEXT_APPEND}" "${FILTER}")
|
||||
endfunction()
|
||||
|
||||
function(append_output_text SUFFICES_FILENAMES TEXT_APPEND FILTER)
|
||||
string(LENGTH "${TEXT_APPEND}" TEXT_LENGTH)
|
||||
list(LENGTH SUFFICES_FILENAMES NB)
|
||||
math(EXPR NB_END "${NB}-1")
|
||||
foreach(INDEX RANGE 0 ${NB_END} 3)
|
||||
math(EXPR INDEX_1 "${INDEX}+1")
|
||||
math(EXPR INDEX_2 "${INDEX}+2")
|
||||
list(GET SUFFICES_FILENAMES ${INDEX} SUFFIX)
|
||||
list(GET SUFFICES_FILENAMES ${INDEX_1} FILENAME)
|
||||
list(GET SUFFICES_FILENAMES ${INDEX_2} TEMPFILENAME)
|
||||
set(WRITE_OK 1)
|
||||
if (FILTER)
|
||||
if (NOT "${SUFFIX}" STREQUAL "${FILTER}")
|
||||
set(WRITE_OK 0)
|
||||
endif()
|
||||
endif()
|
||||
if (WRITE_OK)
|
||||
if (DEBUG)
|
||||
message("Write: ${TEXT_LENGTH} characters to ${FILENAME}")
|
||||
endif()
|
||||
file(APPEND "${TEMPFILENAME}" "${TEXT_APPEND}")
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
function(output_finish SUFFICES_FILENAMES)
|
||||
list(LENGTH SUFFICES_FILENAMES NB)
|
||||
math(EXPR NB_END "${NB}-1")
|
||||
foreach(INDEX RANGE 0 ${NB_END} 3)
|
||||
math(EXPR INDEX_1 "${INDEX}+1")
|
||||
math(EXPR INDEX_2 "${INDEX}+2")
|
||||
list(GET SUFFICES_FILENAMES ${INDEX_1} FILENAME)
|
||||
list(GET SUFFICES_FILENAMES ${INDEX_2} TEMPFILENAME)
|
||||
file(RENAME "${TEMPFILENAME}" "${FILENAME}")
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
function(stack_push STACK_ARG)
|
||||
set(STACK_LIST "${${STACK_ARG}}")
|
||||
string(REPLACE ";" " " NEWITEM "${ARGN}")
|
||||
if (DEBUG)
|
||||
list(LENGTH STACK_LIST STACK_LENGTH)
|
||||
message("Pushing \"${NEWITEM}\" onto stack (length=${STACK_LENGTH})")
|
||||
endif()
|
||||
list(APPEND STACK_LIST "${NEWITEM}")
|
||||
set(${STACK_ARG} "${STACK_LIST}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(stack_pop STACK_ARG ITEM)
|
||||
set(STACK_LIST "${${STACK_ARG}}")
|
||||
list(LENGTH STACK_LIST STACK_LENGTH)
|
||||
if (STACK_LENGTH EQUAL 0)
|
||||
message(FATAL_ERROR "ENDFOR: stack is empty")
|
||||
endif()
|
||||
math(EXPR LAST_ITEM_INDEX "${STACK_LENGTH}-1")
|
||||
list(GET STACK_LIST "${LAST_ITEM_INDEX}" LAST_ITEM)
|
||||
list(REMOVE_AT STACK_LIST "${LAST_ITEM_INDEX}")
|
||||
string(REPLACE " " ";" LAST_ITEM_LIST "${LAST_ITEM}")
|
||||
if (DEBUG)
|
||||
message("Popping \"${LAST_ITEM}\" from stack (length=${STACK_LENGTH})")
|
||||
endif()
|
||||
set(${ITEM} "${LAST_ITEM_LIST}" PARENT_SCOPE)
|
||||
set(${STACK_ARG} "${STACK_LIST}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(stack_top STACK_ARG ITEM)
|
||||
set(STACK_LIST "${${STACK_ARG}}")
|
||||
list(LENGTH STACK_LIST STACK_LENGTH)
|
||||
if (STACK_LENGTH EQUAL 0)
|
||||
message(FATAL_ERROR "ENDFOR: stack is empty")
|
||||
endif()
|
||||
math(EXPR LAST_ITEM_INDEX "${STACK_LENGTH}-1")
|
||||
list(GET STACK_LIST "${LAST_ITEM_INDEX}" LAST_ITEM)
|
||||
string(REPLACE " " ";" LAST_ITEM_LIST "${LAST_ITEM}")
|
||||
if (DEBUG)
|
||||
message("Top of stack: \"${LAST_ITEM}\" from stack (length=${STACK_LENGTH})")
|
||||
endif()
|
||||
set(${ITEM} "${LAST_ITEM_LIST}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(stack_find_key STACK_LIST TEMPLATE_PARAMETERS KEY VALUE)
|
||||
list(REVERSE STACK_LIST)
|
||||
foreach(STACK_ITEM ${STACK_LIST})
|
||||
string(REPLACE " " ";" STACK_ITEM_LIST "${STACK_ITEM}")
|
||||
list(GET STACK_ITEM_LIST 3 TP_INDEX)
|
||||
math(EXPR TP_SIZE_INDEX "${TP_INDEX}+1")
|
||||
list(GET TEMPLATE_PARAMETERS ${TP_SIZE_INDEX} TP_SIZE)
|
||||
math(EXPR TP_KV_INDEX_START "${TP_INDEX}+2")
|
||||
math(EXPR TP_KV_INDEX_END "${TP_KV_INDEX_START}+2*${TP_SIZE}-1")
|
||||
foreach(TP_KV_INDEX RANGE ${TP_KV_INDEX_START} ${TP_KV_INDEX_END} 2)
|
||||
list(GET TEMPLATE_PARAMETERS ${TP_KV_INDEX} TP_KEY)
|
||||
if("${TP_KEY}" STREQUAL "${KEY}")
|
||||
math(EXPR TP_VALUE_INDEX "${TP_KV_INDEX}+1")
|
||||
list(GET TEMPLATE_PARAMETERS ${TP_VALUE_INDEX} TP_VALUE)
|
||||
set(${VALUE} "${TP_VALUE}" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
message(FATAL_ERROR "Unknown KEY=${KEY}")
|
||||
endfunction()
|
||||
|
||||
function(template_parameters_find_next_groupname_index TEMPLATE_PARAMETERS GROUPNAME INDEX_LAST INDEX_NEXT)
|
||||
if (${INDEX_LAST} LESS 0)
|
||||
set(INDEX 0)
|
||||
else ()
|
||||
math(EXPR INDEX_1 "1+(${INDEX_LAST})")
|
||||
list(GET TEMPLATE_PARAMETERS ${INDEX_1} GROUPNAME_INDEX_SIZE)
|
||||
math(EXPR INDEX "${INDEX_LAST}+1+2*${GROUPNAME_INDEX_SIZE}+1")
|
||||
endif()
|
||||
list(LENGTH TEMPLATE_PARAMETERS PARAMETERS_LENGTH)
|
||||
while (${INDEX} LESS ${PARAMETERS_LENGTH})
|
||||
list(GET TEMPLATE_PARAMETERS ${INDEX} GROUPNAME_AT_INDEX)
|
||||
if ("${GROUPNAME}" STREQUAL "${GROUPNAME_AT_INDEX}")
|
||||
set("${INDEX_NEXT}" ${INDEX} PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
math(EXPR INDEX_1 "${INDEX}+1")
|
||||
list(GET TEMPLATE_PARAMETERS ${INDEX_1} GROUPNAME_INDEX_SIZE)
|
||||
math(EXPR INDEX "${INDEX}+1+2*${GROUPNAME_INDEX_SIZE}+1")
|
||||
endwhile()
|
||||
set("${INDEX_NEXT}" -1 PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(calculate_line_number TEXT POSITION LINENUMBER_ARG)
|
||||
#math(EXPR INDEX_MAX "${POSITION}-1")
|
||||
string(SUBSTRING "${TEXT}" 0 ${POSITION} SUBTEXT)
|
||||
string(REGEX MATCHALL "\n" MATCH_NEWLINES "${SUBTEXT}")
|
||||
list(LENGTH MATCH_NEWLINES NBLINES)
|
||||
math(EXPR NBLINES "${NBLINES}+1")
|
||||
set(${LINENUMBER_ARG} ${NBLINES} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(parse_template TEMPLATE_FILENAME OUTPUT_DIR TEMPLATE_PARAMETERS)
|
||||
file(READ ${TEMPLATE_FILENAME} TEMPLATE_CONTENTS)
|
||||
set(POSITION 0)
|
||||
match_autogen_group("${TEMPLATE_CONTENTS}" "${POSITION}" POS0 POS1 AUTOGEN FOUND)
|
||||
if (NOT FOUND)
|
||||
message(FATAL_ERROR "Header of template not found")
|
||||
endif()
|
||||
string(REGEX MATCH "AutoGen5 template ([ a-zA-Z0-9]*)" SUFFICES_MATCH "${AUTOGEN}")
|
||||
if (NOT SUFFICES_MATCH)
|
||||
message(FATAL_ERROR "No output suffices found")
|
||||
endif()
|
||||
string(STRIP "${CMAKE_MATCH_1}" SUFFICES)
|
||||
string(REPLACE " " ";" SUFFICES "${SUFFICES}")
|
||||
set(SUFFICES_FILENAMES "")
|
||||
get_filename_component(TEMPLATE_NAME_WE "${TEMPLATE_FILENAME}" NAME_WE)
|
||||
foreach(SUFFIX ${SUFFICES})
|
||||
if ("${OUTPUT_DIR}" STREQUAL "")
|
||||
set(DIR_PREFIX "")
|
||||
else()
|
||||
set(DIR_PREFIX "${OUTPUT_DIR}/")
|
||||
endif()
|
||||
string(RANDOM LENGTH 64 RANDOMSTRING)
|
||||
set(FILENAME "${DIR_PREFIX}${TEMPLATE_NAME_WE}.${SUFFIX}")
|
||||
set(TEMPFILENAME "${DIR_PREFIX}${TEMPLATE_NAME_WE}${RANDOMSTRING}.${SUFFIX}")
|
||||
list(APPEND SUFFICES_FILENAMES "${SUFFIX}" "${FILENAME}" "${TEMPFILENAME}")
|
||||
file(WRITE "${FILENAME}" "")
|
||||
endforeach()
|
||||
if (DEBUG)
|
||||
message("Output files: ${SUFFICES_FILENAMES}")
|
||||
endif()
|
||||
set(WRITE_FILTER "")
|
||||
append_output("${SUFFICES_FILENAMES}" "${TEMPLATE_CONTENTS}" 0 "${POS0}" "${WRITE_FILTER}")
|
||||
math(EXPR POS1 "${POS1}+1")
|
||||
set(POSITION "${POS1}")
|
||||
if (DEBUG)
|
||||
message("Output: ${SUFFICES_FILENAMES}")
|
||||
endif()
|
||||
|
||||
set(STACK "")
|
||||
while (1)
|
||||
match_autogen_group("${TEMPLATE_CONTENTS}" "${POSITION}" POS0 POS1 GROUP_MATCH FOUND)
|
||||
if (NOT FOUND)
|
||||
if (DEBUG)
|
||||
message("No group found. Dumping rest of file.")
|
||||
endif()
|
||||
if (NOT "${STACK}" STREQUAL "")
|
||||
message(FATAL_ERROR "Stack not empty at end of file")
|
||||
endif()
|
||||
string(LENGTH "${TEMPLATE_CONTENTS}" TEXT_LENGTH)
|
||||
append_output("${SUFFICES_FILENAMES}" "${TEMPLATE_CONTENTS}" ${POSITION} ${TEXT_LENGTH} "${WRITE_FILTER}")
|
||||
break()
|
||||
endif()
|
||||
append_output("${SUFFICES_FILENAMES}" "${TEMPLATE_CONTENTS}" ${POSITION} ${POS0} "${WRITE_FILTER}")
|
||||
set(POSITION "${POS1}")
|
||||
|
||||
if (GROUP_MATCH MATCHES "^FOR")
|
||||
string(REPLACE " " ";" GROUP_MATCH_LIST "${GROUP_MATCH}")
|
||||
list(GET GROUP_MATCH_LIST 1 FOR_KEY)
|
||||
template_parameters_find_next_groupname_index("${TEMPLATE_PARAMETERS}" "${FOR_KEY}" -1 FOR_INDEX)
|
||||
if (DEBUG)
|
||||
message("FOR_KEY: ${FOR_KEY}")
|
||||
message("FOR_INDEX: ${FOR_INDEX}")
|
||||
endif()
|
||||
if (${FOR_KEY} LESS 0)
|
||||
message(FATAL_ERROR "FOR has key with empty list. Not implemented yet..")
|
||||
endif()
|
||||
stack_push(STACK FOR ${POSITION} ${FOR_KEY} ${FOR_INDEX})
|
||||
elseif (GROUP_MATCH MATCHES "^ENDFOR")
|
||||
string(REPLACE " " ";" GROUP_MATCH_LIST "${GROUP_MATCH}")
|
||||
list(GET GROUP_MATCH_LIST 1 ENDFOR_KEY)
|
||||
stack_pop(STACK FOR_ITEM)
|
||||
list(GET FOR_ITEM 0 FOR_FOR)
|
||||
if (NOT "${FOR_FOR}" STREQUAL "FOR")
|
||||
message(FATAL_ERROR "ENDFOR does not match last item: ${FOR_FOR}")
|
||||
endif()
|
||||
list(GET FOR_ITEM 1 FOR_POSITION)
|
||||
list(GET FOR_ITEM 2 FOR_KEY)
|
||||
if (NOT "${FOR_KEY}" STREQUAL "${ENDFOR_KEY}")
|
||||
calculate_line_number("${TEMPLATE_CONTENTS}" "${POSITION}" LINENUMBER)
|
||||
message("FOR and ENDFOR do not match. (line number ${LINENUMBER}) (FOR:${FOR_KEY}, ENDFOR:${ENDFOR_KEY})")
|
||||
endif()
|
||||
list(GET FOR_ITEM 3 FOR_INDEX_PREV)
|
||||
template_parameters_find_next_groupname_index("${TEMPLATE_PARAMETERS}" "${FOR_KEY}" ${FOR_INDEX_PREV} FOR_INDEX)
|
||||
if (DEBUG)
|
||||
message("FOR_INDEX was ${FOR_INDEX_PREV}, is now ${FOR_INDEX}")
|
||||
endif()
|
||||
if (${FOR_INDEX} LESS 0)
|
||||
if (DEBUG)
|
||||
message("ENDFOR: FOR_INDEX < 0 (no more key) ==> Continue")
|
||||
endif()
|
||||
else()
|
||||
set(POSITION ${FOR_POSITION})
|
||||
stack_push(STACK FOR ${FOR_POSITION} ${FOR_KEY} ${FOR_INDEX})
|
||||
if (DEBUG)
|
||||
message("ENDFOR: FOR_INDEX >= 0 (more keys available) ==> Back to position=${FOR_POSITION}")
|
||||
endif()
|
||||
endif()
|
||||
elseif (GROUP_MATCH MATCHES "^CASE")
|
||||
string(REGEX MATCH "^CASE[${WS}]+\\(([a-zA-Z]+)\\)" CASE_MATCH "${GROUP_MATCH}")
|
||||
if ("${CASE_MATCH}" STREQUAL "")
|
||||
message(FATAL_ERROR "Wrong CASE syntax")
|
||||
endif()
|
||||
set(CASE_KEY "${CMAKE_MATCH_1}")
|
||||
if (DEBUG)
|
||||
message("CASE: KEY=${CASE_KEY}")
|
||||
endif()
|
||||
stack_push(STACK CASE "${CASE_KEY}" ${POSITION})
|
||||
elseif (GROUP_MATCH MATCHES "^==")
|
||||
math(EXPR POSITION "${POSITION}+1")
|
||||
string(REGEX MATCH "^==[${WS}]+([a-zA-Z_][a-zA-Z0-9_]*)" CASE_MATCH "${GROUP_MATCH}")
|
||||
if ("${CASE_MATCH}" STREQUAL "")
|
||||
message(FATAL_ERROR "Wrong == syntax")
|
||||
endif()
|
||||
stack_top(STACK CASE_ITEM)
|
||||
list(GET CASE_ITEM 0 CASE_CASE)
|
||||
if(NOT "${CASE_CASE}" STREQUAL "CASE")
|
||||
message(FATAL_ERROR "== block must be in CASE. Top of stack=${CASE_CASE}")
|
||||
endif()
|
||||
set(CASE_VALUE "${CMAKE_MATCH_1}")
|
||||
if (DEBUG)
|
||||
message("case: == VALUE=${CASE_VALUE}")
|
||||
endif()
|
||||
list(GET CASE_ITEM 1 CASE_KEY)
|
||||
if ("${CASE_KEY}" STREQUAL "suffix")
|
||||
if (DEBUG)
|
||||
message("Setting write filter to ${CASE_VALUE}")
|
||||
endif()
|
||||
set(WRITE_FILTER "${CASE_VALUE}")
|
||||
else()
|
||||
message(FATAL_ERROR "CASE: unsupported argument ${CASE_KEY}")
|
||||
endif()
|
||||
elseif (GROUP_MATCH MATCHES "^ESAC")
|
||||
stack_pop(STACK CASE_ITEM)
|
||||
if (DEBUG)
|
||||
message("ESAC")
|
||||
endif()
|
||||
list(GET CASE_ITEM 0 CASE_CASE)
|
||||
if (NOT "${CASE_CASE}" STREQUAL "CASE")
|
||||
message(FATAL_ERROR "ESAC does not match last item: ${CASE_CASE}")
|
||||
endif()
|
||||
if ("${CASE_KEY}" STREQUAL "suffix")
|
||||
if (DEBUG)
|
||||
message("Removing write filter")
|
||||
endif()
|
||||
set(WRITE_FILTER "")
|
||||
else()
|
||||
message(FATAL_ERROR "CASE: unsupported argument ${CASE_KEY}")
|
||||
endif()
|
||||
else()
|
||||
string(REGEX MATCH "\\(([a-zA-Z0-9_$%\"${WS}\\+\\-]+)\\)" PARENTHESE_MATCH "${GROUP_MATCH}")
|
||||
if (NOT "${PARENTHESE_MATCH}" STREQUAL "")
|
||||
set(PARENTHESE_CONTENT "${CMAKE_MATCH_1}")
|
||||
string(REPLACE " " ";" PARENTHESE_LIST "${PARENTHESE_CONTENT}")
|
||||
list(GET PARENTHESE_LIST 0 PARENTHESE_COMMAND)
|
||||
if ("${PARENTHESE_COMMAND}" STREQUAL "get")
|
||||
list(GET PARENTHESE_LIST 1 KEY_QUOTED)
|
||||
string(REGEX MATCH "\\\"([a-zA-Z_${WS}]+)\\\"" KEY_MATCH "${KEY_QUOTED}")
|
||||
if ("${KEY_MATCH}" STREQUAL "")
|
||||
message(FATAL_ERROR "get: empty key")
|
||||
endif()
|
||||
set(KEY "${CMAKE_MATCH_1}")
|
||||
if (DEBUG)
|
||||
message("Get: key=${KEY}")
|
||||
endif()
|
||||
stack_find_key("${STACK}" "${TEMPLATE_PARAMETERS}" "${KEY}" VALUE)
|
||||
if (DEBUG)
|
||||
message("Get key=${KEY} ==> value=${VALUE}")
|
||||
endif()
|
||||
append_output_text("${SUFFICES_FILENAMES}" "${VALUE}" "${WRITE_FILTER}")
|
||||
elseif("${PARENTHESE_COMMAND}" STREQUAL "tpl-file-line")
|
||||
list(GET PARENTHESE_LIST 1 FORMAT_LINE)
|
||||
calculate_line_number("${TEMPLATE_CONTENTS}" "${POSITION}" LINENUMBER)
|
||||
append_output_text("${SUFFICES_FILENAMES}" "${LINENUMBER}" "${WRITE_FILTER}")
|
||||
else()
|
||||
message(FATAL_ERROR "Unknown parenthese command: ${PARENTHESE_COMMAND}")
|
||||
endif()
|
||||
else()
|
||||
message(FATAL_ERROR "Unknown command: ${GROUP_MATCH}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
endwhile()
|
||||
if (NOT "${STACK}" STREQUAL "")
|
||||
message(FATAL_ERROR "STACK was not empty at EOF")
|
||||
endif()
|
||||
output_finish("${SUFFICES_FILENAMES}")
|
||||
endfunction()
|
||||
|
||||
if ("${DEFINITION}" STREQUAL "")
|
||||
message(FATAL_ERROR "Need definition file")
|
||||
endif()
|
||||
if (NOT EXISTS "${DEFINITION}")
|
||||
message(FATAL_ERROR "Definition file does not exist (${DEFINITION})")
|
||||
endif()
|
||||
|
||||
read_definition("${DEFINITION}" TEMPLATE_FILENAME DATA)
|
||||
if (DEBUG)
|
||||
message("${TEMPLATE_FILENAME}")
|
||||
message("${DATA}")
|
||||
endif()
|
||||
|
||||
parse_template("${TEMPLATE_FILENAME}" "${OUTPUTDIR}" "${DATA}")
|
@ -190,9 +190,3 @@ test_inline ()
|
||||
if (NOT DISABLE_CPU_CLIP)
|
||||
clip_mode ()
|
||||
endif ()
|
||||
|
||||
find_program (AUTOGEN_EXECUTABLE NAMES autogen)
|
||||
if (NOT AUTOGEN_EXECUTABLE)
|
||||
message ("autogen tool not found: tests will not be build.")
|
||||
SET (BUILD_TESTING OFF)
|
||||
endif ()
|
||||
|
@ -146,7 +146,7 @@ test_endswap (void)
|
||||
|
||||
[+ FOR int_size
|
||||
+] test_psf_put_be[+ (get "name") +] () ;
|
||||
[+ ENDFOR int_endsize
|
||||
[+ ENDFOR int_size
|
||||
+]
|
||||
|
||||
} /* test_endswap */
|
||||
|
Loading…
Reference in New Issue
Block a user