From a98707c9c37f5f3bff32b85e6efb1c2cceaa8e31 Mon Sep 17 00:00:00 2001 From: Marco Antonio Jaguaribe Costa Date: Thu, 26 Jan 2023 19:43:57 -0300 Subject: [PATCH 1/5] There's no need to make a copy of this list, really --- CMakeLists.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a11c0c4427..9dec52d6fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,14 +126,11 @@ foreach(lang IN LISTS LangTargets) foreach(exe IN LISTS ApplicationTargets) set(targPrefix ${exe}_${lang}) - # make a copy of the library list for each language/library combination - list(SUBLIST Ja2_Libs 0 -1 ${targPrefix}_Targets) - add_executable(${targPrefix} WIN32) target_sources(${targPrefix} PRIVATE ${Ja2Src}) target_link_libraries(${targPrefix} PRIVATE ${Ja2_Libraries}) - foreach(lib IN LISTS ${targPrefix}_Targets) + foreach(lib IN LISTS Ja2_Libs) set(tgt ${targPrefix}_${lib}) add_library(${tgt}) From 8c72ef6ac91db2946ebddf481c17f802a5d7c7a4 Mon Sep 17 00:00:00 2001 From: Marco Antonio Jaguaribe Costa Date: Thu, 26 Jan 2023 19:45:46 -0300 Subject: [PATCH 2/5] Extract Debug definitions to some syntactic sugar this will be used in more targets in the future, this will avoid repetition --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9dec52d6fd..d0cc87ff54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,6 +118,7 @@ ValidateOptions("${ValidLanguages}" "Languages" "${Languages}" "LangTargets") set(ValidApplications JA2 JA2MAPEDITOR JA2UB JA2UBMAPEDITOR) ValidateOptions("${ValidApplications}" "Applications" "${Applications}" "ApplicationTargets") +set(debugFlags $,JA2BETAVERSION;JA2TESTVERSION;DEBUG_ATTACKBUSY,>) # Due to widespread preprocessor definition abuse in the codebase, practically # every library-language-executable combination is its own compilation target @@ -144,7 +145,7 @@ foreach(lang IN LISTS LangTargets) $ $ $ - $,JA2BETAVERSION;JA2TESTVERSION;DEBUG_ATTACKBUSY,> + ${debugFlags} ${lang} ) target_link_libraries(${targPrefix} PUBLIC ${tgt}) From 20d2dede9ce0ad5e739c5c8f11a55e558e411300 Mon Sep 17 00:00:00 2001 From: Marco Antonio Jaguaribe Costa Date: Thu, 26 Jan 2023 20:04:51 -0300 Subject: [PATCH 3/5] improve the comments on root CMakeLists.txt file --- CMakeLists.txt | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d0cc87ff54..aa280796ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,10 +25,14 @@ target_link_libraries(bfVFS PRIVATE 7z) # ja2export utility add_subdirectory("ext/export/src") -# internal libraries that are Good +# static libraries whose source files, header files or header files included +# by header files do not rely on Applications or Languages preprocessor definitions, +# and therefore only need to be compiled once. Good. add_subdirectory(Lua) -# internal libraries that live in Preprocessor Hell, because they are Bad +# static libraries whose source files, header files or header files included +# by header files rely on Application and Language preprocessor definitions, and +# therefore need to be compiled multiple times. Very Bad. add_subdirectory(TileEngine) add_subdirectory(TacticalAI) add_subdirectory(Utils) @@ -110,6 +114,7 @@ bfVFS "ws2_32.lib" ) +# simple function to validate Languages and Application choices include(cmake/ValidateOptions.cmake) set(ValidLanguages CHINESE DUTCH ENGLISH FRENCH GERMAN ITALIAN POLISH RUSSIAN) @@ -118,6 +123,8 @@ ValidateOptions("${ValidLanguages}" "Languages" "${Languages}" "LangTargets") set(ValidApplications JA2 JA2MAPEDITOR JA2UB JA2UBMAPEDITOR) ValidateOptions("${ValidApplications}" "Applications" "${Applications}" "ApplicationTargets") + +# preprocessor definitions for Debug build, per the legacy MSBuild set(debugFlags $,JA2BETAVERSION;JA2TESTVERSION;DEBUG_ATTACKBUSY,>) # Due to widespread preprocessor definition abuse in the codebase, practically @@ -127,20 +134,26 @@ foreach(lang IN LISTS LangTargets) foreach(exe IN LISTS ApplicationTargets) set(targPrefix ${exe}_${lang}) + # executable for an application/language combination, e.g. JA2_ENGLISH.exe add_executable(${targPrefix} WIN32) target_sources(${targPrefix} PRIVATE ${Ja2Src}) + + # Good libraries have already been built, can be simply linked here target_link_libraries(${targPrefix} PRIVATE ${Ja2_Libraries}) + # for each app/lang combination, the Very Bad libraries need to be built, + # with the appropriate preprocessor definitions foreach(lib IN LISTS Ja2_Libs) + # syntactic sugar to hopefully make this more readable set(tgt ${targPrefix}_${lib}) - - add_library(${tgt}) - target_sources(${tgt} PRIVATE ${${lib}Src}) - set(isEditor $) set(isUb $) set(isUbEditor $) + # static library for an app/lang combination, e.g. JA2_ENGLISH_SGP.lib + add_library(${tgt}) + target_sources(${tgt} PRIVATE ${${lib}Src}) + target_compile_definitions(${tgt} PUBLIC $ $ @@ -151,7 +164,7 @@ foreach(lang IN LISTS LangTargets) target_link_libraries(${targPrefix} PUBLIC ${tgt}) endforeach() - # SGP is the only one calling these, so they can go here + # only SGP depends on these target_link_libraries(${targPrefix}_SGP PRIVATE "ddraw.lib" "${PROJECT_SOURCE_DIR}/fmodvc.lib") target_link_libraries(${targPrefix}_SGP PUBLIC libpng) endforeach() From d923f8990b47a2c2abca109cec2a4271ea53c0ad Mon Sep 17 00:00:00 2001 From: Marco Antonio Jaguaribe Costa Date: Thu, 26 Jan 2023 20:11:58 -0300 Subject: [PATCH 4/5] better name for the executable target --- CMakeLists.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aa280796ef..e3d74ae6cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,20 +132,20 @@ set(debugFlags $,JA2BETAVERSION;JA2TESTVERSION;DEBUG_ATTACKBU # TODO: refactor preprocessor usage onto, ideally, a single translation unit foreach(lang IN LISTS LangTargets) foreach(exe IN LISTS ApplicationTargets) - set(targPrefix ${exe}_${lang}) + set(Executable ${exe}_${lang}) # executable for an application/language combination, e.g. JA2_ENGLISH.exe - add_executable(${targPrefix} WIN32) - target_sources(${targPrefix} PRIVATE ${Ja2Src}) + add_executable(${Executable} WIN32) + target_sources(${Executable} PRIVATE ${Ja2Src}) # Good libraries have already been built, can be simply linked here - target_link_libraries(${targPrefix} PRIVATE ${Ja2_Libraries}) + target_link_libraries(${Executable} PRIVATE ${Ja2_Libraries}) # for each app/lang combination, the Very Bad libraries need to be built, # with the appropriate preprocessor definitions foreach(lib IN LISTS Ja2_Libs) # syntactic sugar to hopefully make this more readable - set(tgt ${targPrefix}_${lib}) + set(tgt ${Executable}_${lib}) set(isEditor $) set(isUb $) set(isUbEditor $) @@ -161,11 +161,11 @@ foreach(lang IN LISTS LangTargets) ${debugFlags} ${lang} ) - target_link_libraries(${targPrefix} PUBLIC ${tgt}) + target_link_libraries(${Executable} PUBLIC ${tgt}) endforeach() # only SGP depends on these - target_link_libraries(${targPrefix}_SGP PRIVATE "ddraw.lib" "${PROJECT_SOURCE_DIR}/fmodvc.lib") - target_link_libraries(${targPrefix}_SGP PUBLIC libpng) + target_link_libraries(${Executable}_SGP PRIVATE "ddraw.lib" "${PROJECT_SOURCE_DIR}/fmodvc.lib") + target_link_libraries(${Executable}_SGP PUBLIC libpng) endforeach() endforeach() From f7fd0c8e90f4fbae74f345046a01ae194fab4c4c Mon Sep 17 00:00:00 2001 From: Marco Antonio Jaguaribe Costa Date: Thu, 26 Jan 2023 20:13:30 -0300 Subject: [PATCH 5/5] better name for the app/lang dependent shared lib targets --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e3d74ae6cb..0f00af0f61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,23 +145,23 @@ foreach(lang IN LISTS LangTargets) # with the appropriate preprocessor definitions foreach(lib IN LISTS Ja2_Libs) # syntactic sugar to hopefully make this more readable - set(tgt ${Executable}_${lib}) + set(VeryBadLib ${Executable}_${lib}) set(isEditor $) set(isUb $) set(isUbEditor $) # static library for an app/lang combination, e.g. JA2_ENGLISH_SGP.lib - add_library(${tgt}) - target_sources(${tgt} PRIVATE ${${lib}Src}) + add_library(${VeryBadLib}) + target_sources(${VeryBadLib} PRIVATE ${${lib}Src}) - target_compile_definitions(${tgt} PUBLIC + target_compile_definitions(${VeryBadLib} PUBLIC $ $ $ ${debugFlags} ${lang} ) - target_link_libraries(${Executable} PUBLIC ${tgt}) + target_link_libraries(${Executable} PUBLIC ${VeryBadLib}) endforeach() # only SGP depends on these