Skip to content

Commit 30bf9f0

Browse files
pks-tttaylorr
authored andcommitted
cmake: set up proper dependencies for generated clar headers
The auto-generated headers used by clar are written at configure time and thus do not get regenerated automatically. Refactor the build recipes such that we use custom commands instead, which also has the benefit that we can reuse the same infrastructure as our Makefile. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent a4f8a59 commit 30bf9f0

File tree

1 file changed

+12
-38
lines changed

1 file changed

+12
-38
lines changed

contrib/buildsystems/CMakeLists.txt

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,46 +1002,20 @@ foreach(unit_test ${unit_test_PROGRAMS})
10021002
endforeach()
10031003

10041004
parse_makefile_for_scripts(clar_test_SUITES "CLAR_TEST_SUITES" "")
1005-
1006-
set(clar_decls "")
1007-
set(clar_cbs "")
1008-
set(clar_cbs_count 0)
1009-
set(clar_suites "static struct clar_suite _clar_suites[] = {\n")
1010-
list(LENGTH clar_test_SUITES clar_suites_count)
1011-
foreach(suite ${clar_test_SUITES})
1012-
file(STRINGS "${CMAKE_SOURCE_DIR}/t/unit-tests/${suite}.c" decls
1013-
REGEX "^void test_${suite}__[a-zA-Z_0-9][a-zA-Z_0-9]*\\(void\\)$")
1014-
1015-
list(LENGTH decls decls_count)
1016-
string(REGEX REPLACE "void (test_${suite}__([a-zA-Z_0-9]*))\\(void\\)" " { \"\\2\", &\\1 },\n" cbs ${decls})
1017-
string(JOIN "" cbs ${cbs})
1018-
list(TRANSFORM decls PREPEND "extern ")
1019-
string(JOIN ";\n" decls ${decls})
1020-
1021-
string(APPEND clar_decls "${decls};\n")
1022-
string(APPEND clar_cbs
1023-
"static const struct clar_func _clar_cb_${suite}[] = {\n"
1024-
${cbs}
1025-
"};\n")
1026-
string(APPEND clar_suites
1027-
" {\n"
1028-
" \"${suite}\",\n"
1029-
" { NULL, NULL },\n"
1030-
" { NULL, NULL },\n"
1031-
" _clar_cb_${suite}, ${decls_count}, 1\n"
1032-
" },\n")
1033-
math(EXPR clar_cbs_count "${clar_cbs_count}+${decls_count}")
1034-
endforeach()
1035-
string(APPEND clar_suites
1036-
"};\n"
1037-
"static const size_t _clar_suite_count = ${clar_suites_count};\n"
1038-
"static const size_t _clar_callback_count = ${clar_cbs_count};\n")
1039-
file(WRITE "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h" "${clar_decls}")
1040-
file(WRITE "${CMAKE_BINARY_DIR}/t/unit-tests/clar.suite" "${clar_decls}" "${clar_cbs}" "${clar_suites}")
1041-
10421005
list(TRANSFORM clar_test_SUITES PREPEND "${CMAKE_SOURCE_DIR}/t/unit-tests/")
10431006
list(TRANSFORM clar_test_SUITES APPEND ".c")
1044-
add_library(unit-tests-lib ${clar_test_SUITES} "${CMAKE_SOURCE_DIR}/t/unit-tests/clar/clar.c")
1007+
add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h"
1008+
COMMAND ${CMAKE_SOURCE_DIR}/t/unit-tests/generate-clar-decls.sh "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h" ${clar_test_SUITES}
1009+
DEPENDS ${CMAKE_SOURCE_DIR}/t/unit-tests/generate-clar-decls.sh ${clar_test_SUITES})
1010+
add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/t/unit-tests/clar.suite"
1011+
COMMAND awk -f "${CMAKE_SOURCE_DIR}/t/unit-tests/clar-generate.awk" "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h" > "${CMAKE_BINARY_DIR}/t/unit-tests/clar.suite"
1012+
DEPENDS "${CMAKE_SOURCE_DIR}/t/unit-tests/clar-generate.awk" "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h")
1013+
1014+
add_library(unit-tests-lib ${clar_test_SUITES}
1015+
"${CMAKE_SOURCE_DIR}/t/unit-tests/clar/clar.c"
1016+
"${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h"
1017+
"${CMAKE_BINARY_DIR}/t/unit-tests/clar.suite"
1018+
)
10451019
target_include_directories(unit-tests-lib PUBLIC "${CMAKE_BINARY_DIR}/t/unit-tests")
10461020
add_executable(unit-tests "${CMAKE_SOURCE_DIR}/t/unit-tests/unit-test.c")
10471021
target_link_libraries(unit-tests unit-tests-lib common-main)

0 commit comments

Comments
 (0)