CMakeLists.txt: clean up and fix build rules

The multiple-output custom command ran separately for each binary.
This commit is contained in:
Přemysl Eric Janouch 2020-10-28 11:13:48 +01:00
parent 500c83231f
commit 577fd1b446
Signed by: p
GPG Key ID: A0420B94F92B9493

View File

@ -84,7 +84,7 @@ list (APPEND degesch_libraries ${libffi_LIBRARIES})
include_directories (${libffi_INCLUDE_DIRS}) include_directories (${libffi_INCLUDE_DIRS})
link_directories (${libffi_LIBRARY_DIRS}) link_directories (${libffi_LIBRARY_DIRS})
# FIXME: other Lua versions may be acceptable, don't know yet # XXX: other Lua versions may be acceptable, don't know yet
pkg_search_module (lua lua53 lua5.3 lua-5.3 lua54 lua5.4 lua-5.4 lua>=5.3) pkg_search_module (lua lua53 lua5.3 lua-5.3 lua54 lua5.4 lua-5.4 lua>=5.3)
option (WITH_LUA "Enable support for Lua plugins" ${lua_FOUND}) option (WITH_LUA "Enable support for Lua plugins" ${lua_FOUND})
@ -137,51 +137,35 @@ set (zyklonb_plugin_dir ${CMAKE_INSTALL_LIBDIR}/zyklonb/plugins)
configure_file (${PROJECT_SOURCE_DIR}/config.h.in ${PROJECT_BINARY_DIR}/config.h) configure_file (${PROJECT_SOURCE_DIR}/config.h.in ${PROJECT_BINARY_DIR}/config.h)
include_directories (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR}) include_directories (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
# Project source files # Generate IRC replies--we need a custom target because of the multiple outputs
set (common_sources)
set (common_headers ${PROJECT_BINARY_DIR}/config.h)
add_custom_command (OUTPUT kike-replies.c kike.msg add_custom_command (OUTPUT kike-replies.c kike.msg
COMMAND ${PROJECT_SOURCE_DIR}/kike-gen-replies.sh COMMAND ${PROJECT_SOURCE_DIR}/kike-gen-replies.sh
> kike-replies.c < ${PROJECT_SOURCE_DIR}/kike-replies > kike-replies.c < ${PROJECT_SOURCE_DIR}/kike-replies
DEPENDS ${PROJECT_SOURCE_DIR}/kike-replies DEPENDS ${PROJECT_SOURCE_DIR}/kike-replies
COMMENT "Generating files from the list of server numerics") COMMENT "Generating files from the list of server numerics")
set_source_files_properties (${PROJECT_BINARY_DIR}/kike-replies.c add_custom_target (replies DEPENDS ${PROJECT_BINARY_DIR}/kike-replies.c)
PROPERTIES HEADER_FILE_ONLY TRUE)
# Build # Build
add_executable (zyklonb zyklonb.c ${common_sources} ${common_headers}) foreach (name zyklonb degesch kike)
target_link_libraries (zyklonb ${project_libraries}) add_executable (${name} ${name}.c ${PROJECT_BINARY_DIR}/config.h)
add_threads (zyklonb) target_link_libraries (${name} ${project_libraries})
add_threads (${name})
endforeach (name)
add_executable (degesch degesch.c kike-replies.c add_dependencies (kike replies)
${common_sources} ${common_headers}) add_dependencies (degesch replies)
target_link_libraries (degesch ${project_libraries} ${degesch_libraries}) target_link_libraries (degesch ${degesch_libraries})
add_threads (degesch)
add_executable (kike kike.c kike-replies.c ${common_sources} ${common_headers})
target_link_libraries (kike ${project_libraries})
add_threads (kike)
# Tests # Tests
function (make_tests_for target_name)
get_target_property (sources ${target_name} SOURCES)
get_target_property (libraries ${target_name} LINK_LIBRARIES)
get_target_property (options ${target_name} COMPILE_OPTIONS)
set (test test-${target_name})
add_executable (${test} ${sources})
target_link_libraries (${test} ${libraries})
set_target_properties (${test} PROPERTIES
COMPILE_DEFINITIONS TESTING
COMPILE_OPTIONS "${options}")
add_test (NAME ${test} COMMAND ${test})
endfunction (make_tests_for)
include (CTest) include (CTest)
if (BUILD_TESTING) if (BUILD_TESTING)
make_tests_for (degesch) add_executable (test-degesch $<TARGET_PROPERTY:degesch,SOURCES>)
set_target_properties (test-degesch PROPERTIES COMPILE_DEFINITIONS TESTING)
target_link_libraries (test-degesch $<TARGET_PROPERTY:degesch,LINK_LIBRARIES>)
add_threads (test-degesch)
add_dependencies (test-degesch replies)
add_test (NAME test-degesch COMMAND test-degesch)
add_test (NAME custom-static-analysis add_test (NAME custom-static-analysis
COMMAND ${PROJECT_SOURCE_DIR}/test-static) COMMAND ${PROJECT_SOURCE_DIR}/test-static)
endif (BUILD_TESTING) endif (BUILD_TESTING)