From a5547c7d62a41b784d88e5eabe9355921384b03a Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Wed, 5 Jun 2024 11:46:54 +0200 Subject: CMake: Make the build work the first time Use execute_process instead of add_custom_target to make sure the generated files are found on the first configure run. Set CMAKE_CONFIGURE_DEPENDS so that touching the script generating files will automatically trigger a re-configre, which will re-run the make process. --- CMakeLists.txt | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 51e3b6e..11c58d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,20 @@ set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_STANDARD_REQUIRED ON) +# Some sources and includes are generated, such as the protocol headers. +# We defer to generate.make for these rules. +# Note that these are raw Makefile rules, not CMake rules, so a simple +# add_custom_command() won't work. +execute_process(COMMAND make -f ${CMAKE_SOURCE_DIR}/generate.mk + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) + +# The generate target must be re-run when the scripts change +set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS + "${PROJECT_SOURCE_DIR}/generate.mk" + "${PROJECT_SOURCE_DIR}/tools/config.py" + "${PROJECT_SOURCE_DIR}/tools/protocol.py" +) + # Search through the tree for sources # For each subfolder in src, add all .cpp files to a subfolder's SOURCES # variable. @@ -152,22 +166,5 @@ target_link_libraries(tmwa-admin tmwa-shared) #add_executable(tmwa-test ${strtest_SOURCES}) #target_link_libraries(tmwa-test tmwa-shared) -# Some sources and includes are generated, such as the protocol headers. -# We defer to generate.make for these rules. -# Note that these are raw Makefile rules, not CMake rules, so a simple -# add_custom_command() won't work. -add_custom_target(generate - COMMAND make -f ${CMAKE_SOURCE_DIR}/generate.mk - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - COMMENT "Generating sources and includes" -) - # Call make -f ${CMAKE_SOURCE_DIR}/generate.mk clean to clean up the generated # files. We want this to be run every time we call make clean. - - -# The generate target must be run before building the binaries -add_dependencies(tmwa-login generate) -add_dependencies(tmwa-char generate) -add_dependencies(tmwa-map generate) -add_dependencies(tmwa-admin generate) -- cgit v1.2.3-70-g09d2