From b621502e07b15f90f0a2391bbf6963b7632a4e8a Mon Sep 17 00:00:00 2001 From: Dima Korolev Date: Sun, 28 Jul 2024 12:16:14 +0200 Subject: [PATCH 01/16] Use the `current-deps` Github org. --- cmake/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index e390faea..b92558bb 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -71,7 +71,7 @@ UseGitOrClone(https://github.com/c5t/current) # Set `C5T_NO_GTEST` in the `Makefile` to any non-empty value to speed up the builds that do not need `googletest`. if("$ENV{C5T_NO_GTEST}" STREQUAL "") - UseGitOrClone(https://github.com/c5t/googletest) + UseGitOrClone(https://github.com/current-deps/googletest) else() message(STATUS "Skipping `googletest` as `C5T_NO_GTEST` is set.") endif() @@ -83,7 +83,7 @@ if(NOT "${C5T_DEPS_1}" STREQUAL "") string(REPLACE ":" ";" C5T_DEPS_2 "${C5T_DEPS_1}") string(REPLACE " " ";" C5T_DEPS_3 "${C5T_DEPS_2}") foreach(C5T_DEP IN LISTS C5T_DEPS_3) - UseGitOrClone("https://github.com/c5t/${C5T_DEP}") + UseGitOrClone("https://github.com/current-deps/${C5T_DEP}") endforeach() endif() From aba980a5cf00f8c1f24e7712b8daf9bd2f18bac2 Mon Sep 17 00:00:00 2001 From: Dima Korolev Date: Tue, 30 Jul 2024 14:07:06 +0200 Subject: [PATCH 02/16] Including all symbols from user-defined libraries. --- cmake/CMakeLists.txt | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index b92558bb..4071d686 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -117,25 +117,25 @@ foreach(SHARED_LIBRARY_SOURCE_FILE ${BINARY_SOURCE_FILES}) target_link_libraries(${SHARED_LIBRARY_TARGET_NAME} PRIVATE "${C5T_LIBRARIES}") endforeach() -# Declare libraries as library targets. First, and add them into the `ALL_LIBRARIES` list. -set(ALL_LIBRARIES "${C5T_LIBRARIES}") +# Declare user-defined libraries as library targets. +set(USR_LIBRARIES) file(GLOB_RECURSE LIBRARY_SOURCE_FILES "${C5T_PROJECT_ROOT_SRC}/lib_*.cc") foreach(LIBRARY_SOURCE_FILE ${LIBRARY_SOURCE_FILES}) get_filename_component(LIBRARY_TARGET_NAME "${LIBRARY_SOURCE_FILE}" NAME_WE) - list(APPEND ALL_LIBRARIES "${LIBRARY_TARGET_NAME}") + list(APPEND USR_LIBRARIES "${LIBRARY_TARGET_NAME}") endforeach() # Then build all the libraries, such that every library is linked against every other library. file(GLOB_RECURSE LIBRARY_SOURCE_FILES "${C5T_PROJECT_ROOT_SRC}/lib_*.cc") foreach(LIBRARY_SOURCE_FILE ${LIBRARY_SOURCE_FILES}) get_filename_component(LIBRARY_TARGET_NAME "${LIBRARY_SOURCE_FILE}" NAME_WE) - add_library(${LIBRARY_TARGET_NAME} "${LIBRARY_SOURCE_FILE}") + add_library(${LIBRARY_TARGET_NAME} STATIC "${LIBRARY_SOURCE_FILE}") add_dependencies(${LIBRARY_TARGET_NAME} C5T_CURRENT_BUILD_INFO_H_TARGET) target_compile_definitions(${LIBRARY_TARGET_NAME} PRIVATE C5T_CMAKE_PROJECT) target_include_directories(${LIBRARY_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/inc") - set(LIBRARY_DEPS_WO_SELF "${ALL_LIBRARIES}") - list(REMOVE_ITEM LIBRARY_DEPS_WO_SELF ${LIBRARY_TARGET_NAME}) - target_link_libraries(${LIBRARY_TARGET_NAME} PRIVATE "${LIBRARY_DEPS_WO_SELF}") + set(USR_LIBRARIES_WO_SELF "${USR_LIBRARIES}") + list(REMOVE_ITEM USR_LIBRARIES_WO_SELF ${LIBRARY_TARGET_NAME}) + target_link_libraries(${LIBRARY_TARGET_NAME} PRIVATE -Wl,--whole-archive "${USR_LIBRARIES_WO_SELF}" -Wl,--no-whole-archive,--allow-multiple-definition) endforeach() # Declare binaries as binary targets. And link them against all the libraries. @@ -147,7 +147,8 @@ foreach(BINARY_SOURCE_FILE ${BINARY_SOURCE_FILES}) add_dependencies(${BINARY_TARGET_NAME} C5T_CURRENT_BUILD_INFO_H_TARGET) target_compile_definitions(${BINARY_TARGET_NAME} PRIVATE C5T_CMAKE_PROJECT) target_include_directories(${BINARY_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/inc") - target_link_libraries(${BINARY_TARGET_NAME} PRIVATE "${ALL_LIBRARIES}") + target_link_libraries(${BINARY_TARGET_NAME} PRIVATE "${C5T_LIBRARIES}") + target_link_libraries(${BINARY_TARGET_NAME} PRIVATE -Wl,--whole-archive "${USR_LIBRARIES}" -Wl,--no-whole-archive,--allow-multiple-definition) endif() endforeach() @@ -159,6 +160,7 @@ foreach(TEST_SOURCE_FILE ${TEST_SOURCE_FILES}) add_executable(${TEST_TARGET_NAME} "${TEST_SOURCE_FILE}") add_dependencies(${TEST_TARGET_NAME} C5T_CURRENT_BUILD_INFO_H_TARGET) target_include_directories(${TEST_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/inc") - target_link_libraries(${TEST_TARGET_NAME} PRIVATE gtest_main "${ALL_LIBRARIES}") + target_link_libraries(${TEST_TARGET_NAME} PRIVATE gtest_main "${C5T_LIBRARIES}") + target_link_libraries(${TEST_TARGET_NAME} PRIVATE -Wl,--whole-archive "${USR_LIBRARIES}" -Wl,--no-whole-archive) add_test(NAME ${TEST_TARGET_NAME} COMMAND ${TEST_TARGET_NAME}) endforeach() From 77e74727c4c00d12b8312f0a20a8d44b5b8e0075 Mon Sep 17 00:00:00 2001 From: Dima Korolev Date: Tue, 30 Jul 2024 14:17:18 +0200 Subject: [PATCH 03/16] Pleasing `APPLE`. --- cmake/CMakeLists.txt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 4071d686..ea0d4769 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -135,7 +135,11 @@ foreach(LIBRARY_SOURCE_FILE ${LIBRARY_SOURCE_FILES}) target_include_directories(${LIBRARY_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/inc") set(USR_LIBRARIES_WO_SELF "${USR_LIBRARIES}") list(REMOVE_ITEM USR_LIBRARIES_WO_SELF ${LIBRARY_TARGET_NAME}) - target_link_libraries(${LIBRARY_TARGET_NAME} PRIVATE -Wl,--whole-archive "${USR_LIBRARIES_WO_SELF}" -Wl,--no-whole-archive,--allow-multiple-definition) + if(APPLE) + target_link_libraries(${LIBRARY_TARGET_NAME} PRIVATE "${USR_LIBRARIES_WO_SELF}" -all_load -force_load) + else() + target_link_libraries(${LIBRARY_TARGET_NAME} PRIVATE -Wl,--whole-archive "${USR_LIBRARIES_WO_SELF}" -Wl,--no-whole-archive,--allow-multiple-definition) + endif() endforeach() # Declare binaries as binary targets. And link them against all the libraries. @@ -148,7 +152,11 @@ foreach(BINARY_SOURCE_FILE ${BINARY_SOURCE_FILES}) target_compile_definitions(${BINARY_TARGET_NAME} PRIVATE C5T_CMAKE_PROJECT) target_include_directories(${BINARY_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/inc") target_link_libraries(${BINARY_TARGET_NAME} PRIVATE "${C5T_LIBRARIES}") - target_link_libraries(${BINARY_TARGET_NAME} PRIVATE -Wl,--whole-archive "${USR_LIBRARIES}" -Wl,--no-whole-archive,--allow-multiple-definition) + if(APPLE) + target_link_libraries(${BINARY_TARGET_NAME} PRIVATE "${USR_LIBRARIES}" -all_load -force_load) + else() + target_link_libraries(${BINARY_TARGET_NAME} PRIVATE -Wl,--whole-archive "${USR_LIBRARIES}" -Wl,--no-whole-archive,--allow-multiple-definition) + endif() endif() endforeach() @@ -161,6 +169,10 @@ foreach(TEST_SOURCE_FILE ${TEST_SOURCE_FILES}) add_dependencies(${TEST_TARGET_NAME} C5T_CURRENT_BUILD_INFO_H_TARGET) target_include_directories(${TEST_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/inc") target_link_libraries(${TEST_TARGET_NAME} PRIVATE gtest_main "${C5T_LIBRARIES}") - target_link_libraries(${TEST_TARGET_NAME} PRIVATE -Wl,--whole-archive "${USR_LIBRARIES}" -Wl,--no-whole-archive) + if (APPLE) + target_link_libraries(${TEST_TARGET_NAME} PRIVATE "${USR_LIBRARIES}" -all_load -force_load) + else() + target_link_libraries(${TEST_TARGET_NAME} PRIVATE -Wl,--whole-archive "${USR_LIBRARIES}" -Wl,--no-whole-archive) + endif() add_test(NAME ${TEST_TARGET_NAME} COMMAND ${TEST_TARGET_NAME}) endforeach() From 101a454a7bc427d398b349f156e267c9198dba13 Mon Sep 17 00:00:00 2001 From: Dima Korolev Date: Tue, 30 Jul 2024 14:22:18 +0200 Subject: [PATCH 04/16] More `APPLE` tweaks. --- cmake/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index ea0d4769..c08dd1ef 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -136,7 +136,7 @@ foreach(LIBRARY_SOURCE_FILE ${LIBRARY_SOURCE_FILES}) set(USR_LIBRARIES_WO_SELF "${USR_LIBRARIES}") list(REMOVE_ITEM USR_LIBRARIES_WO_SELF ${LIBRARY_TARGET_NAME}) if(APPLE) - target_link_libraries(${LIBRARY_TARGET_NAME} PRIVATE "${USR_LIBRARIES_WO_SELF}" -all_load -force_load) + target_link_libraries(${LIBRARY_TARGET_NAME} PRIVATE -force_load "${USR_LIBRARIES_WO_SELF}") else() target_link_libraries(${LIBRARY_TARGET_NAME} PRIVATE -Wl,--whole-archive "${USR_LIBRARIES_WO_SELF}" -Wl,--no-whole-archive,--allow-multiple-definition) endif() @@ -153,7 +153,7 @@ foreach(BINARY_SOURCE_FILE ${BINARY_SOURCE_FILES}) target_include_directories(${BINARY_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/inc") target_link_libraries(${BINARY_TARGET_NAME} PRIVATE "${C5T_LIBRARIES}") if(APPLE) - target_link_libraries(${BINARY_TARGET_NAME} PRIVATE "${USR_LIBRARIES}" -all_load -force_load) + target_link_libraries(${BINARY_TARGET_NAME} PRIVATE -force_load "${USR_LIBRARIES}") else() target_link_libraries(${BINARY_TARGET_NAME} PRIVATE -Wl,--whole-archive "${USR_LIBRARIES}" -Wl,--no-whole-archive,--allow-multiple-definition) endif() @@ -170,7 +170,7 @@ foreach(TEST_SOURCE_FILE ${TEST_SOURCE_FILES}) target_include_directories(${TEST_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/inc") target_link_libraries(${TEST_TARGET_NAME} PRIVATE gtest_main "${C5T_LIBRARIES}") if (APPLE) - target_link_libraries(${TEST_TARGET_NAME} PRIVATE "${USR_LIBRARIES}" -all_load -force_load) + target_link_libraries(${TEST_TARGET_NAME} PRIVATE -force_load "${USR_LIBRARIES}") else() target_link_libraries(${TEST_TARGET_NAME} PRIVATE -Wl,--whole-archive "${USR_LIBRARIES}" -Wl,--no-whole-archive) endif() From cba45d4172f1c020e63fa43e267a9b5e1d024133 Mon Sep 17 00:00:00 2001 From: Dima Korolev Date: Tue, 30 Jul 2024 14:26:01 +0200 Subject: [PATCH 05/16] Added `-Wl` to `-force_load`. --- cmake/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index c08dd1ef..92014f8f 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -136,7 +136,7 @@ foreach(LIBRARY_SOURCE_FILE ${LIBRARY_SOURCE_FILES}) set(USR_LIBRARIES_WO_SELF "${USR_LIBRARIES}") list(REMOVE_ITEM USR_LIBRARIES_WO_SELF ${LIBRARY_TARGET_NAME}) if(APPLE) - target_link_libraries(${LIBRARY_TARGET_NAME} PRIVATE -force_load "${USR_LIBRARIES_WO_SELF}") + target_link_libraries(${LIBRARY_TARGET_NAME} PRIVATE -Wl,-force_load "${USR_LIBRARIES_WO_SELF}") else() target_link_libraries(${LIBRARY_TARGET_NAME} PRIVATE -Wl,--whole-archive "${USR_LIBRARIES_WO_SELF}" -Wl,--no-whole-archive,--allow-multiple-definition) endif() @@ -153,7 +153,7 @@ foreach(BINARY_SOURCE_FILE ${BINARY_SOURCE_FILES}) target_include_directories(${BINARY_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/inc") target_link_libraries(${BINARY_TARGET_NAME} PRIVATE "${C5T_LIBRARIES}") if(APPLE) - target_link_libraries(${BINARY_TARGET_NAME} PRIVATE -force_load "${USR_LIBRARIES}") + target_link_libraries(${BINARY_TARGET_NAME} PRIVATE -Wl,-force_load "${USR_LIBRARIES}") else() target_link_libraries(${BINARY_TARGET_NAME} PRIVATE -Wl,--whole-archive "${USR_LIBRARIES}" -Wl,--no-whole-archive,--allow-multiple-definition) endif() @@ -170,7 +170,7 @@ foreach(TEST_SOURCE_FILE ${TEST_SOURCE_FILES}) target_include_directories(${TEST_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/inc") target_link_libraries(${TEST_TARGET_NAME} PRIVATE gtest_main "${C5T_LIBRARIES}") if (APPLE) - target_link_libraries(${TEST_TARGET_NAME} PRIVATE -force_load "${USR_LIBRARIES}") + target_link_libraries(${TEST_TARGET_NAME} PRIVATE -Wl,-force_load "${USR_LIBRARIES}") else() target_link_libraries(${TEST_TARGET_NAME} PRIVATE -Wl,--whole-archive "${USR_LIBRARIES}" -Wl,--no-whole-archive) endif() From 8d4df6645bcdc48ef153eeefcaa165a86a748203 Mon Sep 17 00:00:00 2001 From: Dima Korolev Date: Tue, 30 Jul 2024 15:21:57 +0200 Subject: [PATCH 06/16] Specifically added the `current` dir as the dir for `#include`-s. --- cmake/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 92014f8f..75f80728 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -113,7 +113,7 @@ foreach(SHARED_LIBRARY_SOURCE_FILE ${BINARY_SOURCE_FILES}) # TODO(dkorolev): Might be worth it to `grep` this `dlib_*.cc` source file for required library dependencies. target_compile_definitions(${SHARED_LIBRARY_TARGET_NAME} PRIVATE C5T_CMAKE_PROJECT) target_compile_definitions(${SHARED_LIBRARY_TARGET_NAME} PRIVATE C5T_DLIB) - target_include_directories(${SHARED_LIBRARY_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/inc") + target_include_directories(${SHARED_LIBRARY_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/inc" ${C5T_DEP_DIR_current}) target_link_libraries(${SHARED_LIBRARY_TARGET_NAME} PRIVATE "${C5T_LIBRARIES}") endforeach() @@ -132,7 +132,7 @@ foreach(LIBRARY_SOURCE_FILE ${LIBRARY_SOURCE_FILES}) add_library(${LIBRARY_TARGET_NAME} STATIC "${LIBRARY_SOURCE_FILE}") add_dependencies(${LIBRARY_TARGET_NAME} C5T_CURRENT_BUILD_INFO_H_TARGET) target_compile_definitions(${LIBRARY_TARGET_NAME} PRIVATE C5T_CMAKE_PROJECT) - target_include_directories(${LIBRARY_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/inc") + target_include_directories(${LIBRARY_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/inc" ${C5T_DEP_DIR_current}) set(USR_LIBRARIES_WO_SELF "${USR_LIBRARIES}") list(REMOVE_ITEM USR_LIBRARIES_WO_SELF ${LIBRARY_TARGET_NAME}) if(APPLE) From 6ecf7a10fe717bb0c8f72440dc6eb833f53b3d0f Mon Sep 17 00:00:00 2001 From: Dima Korolev Date: Tue, 30 Jul 2024 23:34:50 +0200 Subject: [PATCH 07/16] Running the pre-build script if present. --- cmake/CMakeLists.txt | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 75f80728..c05e2fec 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -90,13 +90,27 @@ endif() get_property(C5T_LIBRARIES GLOBAL PROPERTY C5T_LIBRARIES_PROPERTY) add_custom_target(C5T_CURRENT_BUILD_INFO_H_TARGET ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/inc/current_build_info.h") +add_custom_target(C5T_CUSTOM_PER_BUILD_SCRIPT_TARGET ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/inc/pre_build_sh_output.h") add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/inc/current_build_info.h" COMMAND "${C5T_DEP_DIR_current}/scripts/gen-current-build.sh" ARGS "${CMAKE_CURRENT_BINARY_DIR}/inc/current_build_info.h" DEPENDS inc/current_build_info.h.force_rebuild) +file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/inc") +if(EXISTS "${CMAKE_SOURCE_DIR}/src/pre_build.sh") + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/inc/pre_build_sh_output.h" + COMMAND "${CMAKE_SOURCE_DIR}/src/pre_build.sh" + ARGS "${CMAKE_CURRENT_BINARY_DIR}/inc/pre_build_sh_output.h" + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + DEPENDS inc/pre_build_sh_output.h.force_rebuild) +else() + file(TOUCH "${CMAKE_CURRENT_BINARY_DIR}/inc/pre_build_sh_output.h") + file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/inc/pre_build_sh_output.h" "#pragma once\n// No `src/pre_build.sh` found.\n") +endif() + add_custom_command(OUTPUT inc/current_build_info.h.force_rebuild COMMAND cmake -E echo >/dev/null) +add_custom_command(OUTPUT inc/pre_build_sh_output.h.force_rebuild COMMAND cmake -E echo >/dev/null) if("${C5T_PROJECT_ROOT}" STREQUAL "") set(C5T_PROJECT_ROOT_SRC "src") @@ -109,7 +123,7 @@ file(GLOB_RECURSE BINARY_SOURCE_FILES "${C5T_PROJECT_ROOT_SRC}/dlib_*.cc") foreach(SHARED_LIBRARY_SOURCE_FILE ${BINARY_SOURCE_FILES}) get_filename_component(SHARED_LIBRARY_TARGET_NAME "${SHARED_LIBRARY_SOURCE_FILE}" NAME_WE) add_library(${SHARED_LIBRARY_TARGET_NAME} SHARED "${SHARED_LIBRARY_SOURCE_FILE}") - add_dependencies(${SHARED_LIBRARY_TARGET_NAME} C5T_CURRENT_BUILD_INFO_H_TARGET) + add_dependencies(${SHARED_LIBRARY_TARGET_NAME} C5T_CURRENT_BUILD_INFO_H_TARGET C5T_CUSTOM_PER_BUILD_SCRIPT_TARGET) # TODO(dkorolev): Might be worth it to `grep` this `dlib_*.cc` source file for required library dependencies. target_compile_definitions(${SHARED_LIBRARY_TARGET_NAME} PRIVATE C5T_CMAKE_PROJECT) target_compile_definitions(${SHARED_LIBRARY_TARGET_NAME} PRIVATE C5T_DLIB) @@ -130,7 +144,7 @@ file(GLOB_RECURSE LIBRARY_SOURCE_FILES "${C5T_PROJECT_ROOT_SRC}/lib_*.cc") foreach(LIBRARY_SOURCE_FILE ${LIBRARY_SOURCE_FILES}) get_filename_component(LIBRARY_TARGET_NAME "${LIBRARY_SOURCE_FILE}" NAME_WE) add_library(${LIBRARY_TARGET_NAME} STATIC "${LIBRARY_SOURCE_FILE}") - add_dependencies(${LIBRARY_TARGET_NAME} C5T_CURRENT_BUILD_INFO_H_TARGET) + add_dependencies(${LIBRARY_TARGET_NAME} C5T_CURRENT_BUILD_INFO_H_TARGET C5T_CUSTOM_PER_BUILD_SCRIPT_TARGET) target_compile_definitions(${LIBRARY_TARGET_NAME} PRIVATE C5T_CMAKE_PROJECT) target_include_directories(${LIBRARY_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/inc" ${C5T_DEP_DIR_current}) set(USR_LIBRARIES_WO_SELF "${USR_LIBRARIES}") @@ -148,7 +162,7 @@ foreach(BINARY_SOURCE_FILE ${BINARY_SOURCE_FILES}) get_filename_component(BINARY_TARGET_NAME "${BINARY_SOURCE_FILE}" NAME_WE) if(NOT (BINARY_TARGET_NAME MATCHES "^lib_.*$" OR BINARY_TARGET_NAME MATCHES "^test_.*$" OR BINARY_TARGET_NAME MATCHES "^dlib_.*$")) add_executable(${BINARY_TARGET_NAME} "${BINARY_SOURCE_FILE}") - add_dependencies(${BINARY_TARGET_NAME} C5T_CURRENT_BUILD_INFO_H_TARGET) + add_dependencies(${BINARY_TARGET_NAME} C5T_CURRENT_BUILD_INFO_H_TARGET C5T_CUSTOM_PER_BUILD_SCRIPT_TARGET) target_compile_definitions(${BINARY_TARGET_NAME} PRIVATE C5T_CMAKE_PROJECT) target_include_directories(${BINARY_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/inc") target_link_libraries(${BINARY_TARGET_NAME} PRIVATE "${C5T_LIBRARIES}") @@ -166,7 +180,7 @@ file(GLOB_RECURSE TEST_SOURCE_FILES "${C5T_PROJECT_ROOT_SRC}/test_*.cc") foreach(TEST_SOURCE_FILE ${TEST_SOURCE_FILES}) get_filename_component(TEST_TARGET_NAME "${TEST_SOURCE_FILE}" NAME_WE) add_executable(${TEST_TARGET_NAME} "${TEST_SOURCE_FILE}") - add_dependencies(${TEST_TARGET_NAME} C5T_CURRENT_BUILD_INFO_H_TARGET) + add_dependencies(${TEST_TARGET_NAME} C5T_CURRENT_BUILD_INFO_H_TARGET C5T_CUSTOM_PER_BUILD_SCRIPT_TARGET) target_include_directories(${TEST_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/inc") target_link_libraries(${TEST_TARGET_NAME} PRIVATE gtest_main "${C5T_LIBRARIES}") if (APPLE) From 0a3315a304db00959f4595e416857807480117e0 Mon Sep 17 00:00:00 2001 From: Dima Korolev Date: Tue, 30 Jul 2024 23:37:50 +0200 Subject: [PATCH 08/16] Back to a "simple" `CMakeLists.txt`. --- cmake/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index c05e2fec..dd898d30 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -152,7 +152,7 @@ foreach(LIBRARY_SOURCE_FILE ${LIBRARY_SOURCE_FILES}) if(APPLE) target_link_libraries(${LIBRARY_TARGET_NAME} PRIVATE -Wl,-force_load "${USR_LIBRARIES_WO_SELF}") else() - target_link_libraries(${LIBRARY_TARGET_NAME} PRIVATE -Wl,--whole-archive "${USR_LIBRARIES_WO_SELF}" -Wl,--no-whole-archive,--allow-multiple-definition) + target_link_libraries(${LIBRARY_TARGET_NAME} PRIVATE "${USR_LIBRARIES_WO_SELF}") endif() endforeach() @@ -169,7 +169,7 @@ foreach(BINARY_SOURCE_FILE ${BINARY_SOURCE_FILES}) if(APPLE) target_link_libraries(${BINARY_TARGET_NAME} PRIVATE -Wl,-force_load "${USR_LIBRARIES}") else() - target_link_libraries(${BINARY_TARGET_NAME} PRIVATE -Wl,--whole-archive "${USR_LIBRARIES}" -Wl,--no-whole-archive,--allow-multiple-definition) + target_link_libraries(${BINARY_TARGET_NAME} PRIVATE "${USR_LIBRARIES}") endif() endif() endforeach() @@ -186,7 +186,7 @@ foreach(TEST_SOURCE_FILE ${TEST_SOURCE_FILES}) if (APPLE) target_link_libraries(${TEST_TARGET_NAME} PRIVATE -Wl,-force_load "${USR_LIBRARIES}") else() - target_link_libraries(${TEST_TARGET_NAME} PRIVATE -Wl,--whole-archive "${USR_LIBRARIES}" -Wl,--no-whole-archive) + target_link_libraries(${TEST_TARGET_NAME} PRIVATE "${USR_LIBRARIES}") endif() add_test(NAME ${TEST_TARGET_NAME} COMMAND ${TEST_TARGET_NAME}) endforeach() From 2c67c93a846875a8c55870e65cc07212cbeb693a Mon Sep 17 00:00:00 2001 From: Dima Korolev Date: Wed, 31 Jul 2024 00:05:33 +0200 Subject: [PATCH 09/16] `s/\./.inl/g`. --- cmake/CMakeLists.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index dd898d30..7b771a4c 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -90,7 +90,7 @@ endif() get_property(C5T_LIBRARIES GLOBAL PROPERTY C5T_LIBRARIES_PROPERTY) add_custom_target(C5T_CURRENT_BUILD_INFO_H_TARGET ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/inc/current_build_info.h") -add_custom_target(C5T_CUSTOM_PER_BUILD_SCRIPT_TARGET ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/inc/pre_build_sh_output.h") +add_custom_target(C5T_CUSTOM_PER_BUILD_SCRIPT_TARGET ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/inc/pre_build_sh_output.inl") add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/inc/current_build_info.h" COMMAND "${C5T_DEP_DIR_current}/scripts/gen-current-build.sh" @@ -99,18 +99,18 @@ add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/inc/current_build_info.h" file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/inc") if(EXISTS "${CMAKE_SOURCE_DIR}/src/pre_build.sh") - add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/inc/pre_build_sh_output.h" + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/inc/pre_build_sh_output.inl" COMMAND "${CMAKE_SOURCE_DIR}/src/pre_build.sh" - ARGS "${CMAKE_CURRENT_BINARY_DIR}/inc/pre_build_sh_output.h" + ARGS "${CMAKE_CURRENT_BINARY_DIR}/inc/pre_build_sh_output.inl" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" - DEPENDS inc/pre_build_sh_output.h.force_rebuild) + DEPENDS inc/pre_build_sh_output.inl.force_rebuild) else() - file(TOUCH "${CMAKE_CURRENT_BINARY_DIR}/inc/pre_build_sh_output.h") - file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/inc/pre_build_sh_output.h" "#pragma once\n// No `src/pre_build.sh` found.\n") + file(TOUCH "${CMAKE_CURRENT_BINARY_DIR}/inc/pre_build_sh_output.inl") + file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/inc/pre_build_sh_output.inl" "#pragma once\n// No `src/pre_build.sh` found.\n") endif() add_custom_command(OUTPUT inc/current_build_info.h.force_rebuild COMMAND cmake -E echo >/dev/null) -add_custom_command(OUTPUT inc/pre_build_sh_output.h.force_rebuild COMMAND cmake -E echo >/dev/null) +add_custom_command(OUTPUT inc/pre_build_sh_output.inl.force_rebuild COMMAND cmake -E echo >/dev/null) if("${C5T_PROJECT_ROOT}" STREQUAL "") set(C5T_PROJECT_ROOT_SRC "src") From 5e1dd04afe1859f5a4e89862ceb039820960c27a Mon Sep 17 00:00:00 2001 From: Dima Korolev Date: Wed, 31 Jul 2024 12:19:00 +0200 Subject: [PATCH 10/16] Reverted most changes, just keeping the `.inl` pre-build script now. --- cmake/CMakeLists.txt | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 7b771a4c..89e01d2d 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -149,11 +149,7 @@ foreach(LIBRARY_SOURCE_FILE ${LIBRARY_SOURCE_FILES}) target_include_directories(${LIBRARY_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/inc" ${C5T_DEP_DIR_current}) set(USR_LIBRARIES_WO_SELF "${USR_LIBRARIES}") list(REMOVE_ITEM USR_LIBRARIES_WO_SELF ${LIBRARY_TARGET_NAME}) - if(APPLE) - target_link_libraries(${LIBRARY_TARGET_NAME} PRIVATE -Wl,-force_load "${USR_LIBRARIES_WO_SELF}") - else() - target_link_libraries(${LIBRARY_TARGET_NAME} PRIVATE "${USR_LIBRARIES_WO_SELF}") - endif() + target_link_libraries(${LIBRARY_TARGET_NAME} PRIVATE "${USR_LIBRARIES_WO_SELF}") endforeach() # Declare binaries as binary targets. And link them against all the libraries. @@ -166,11 +162,7 @@ foreach(BINARY_SOURCE_FILE ${BINARY_SOURCE_FILES}) target_compile_definitions(${BINARY_TARGET_NAME} PRIVATE C5T_CMAKE_PROJECT) target_include_directories(${BINARY_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/inc") target_link_libraries(${BINARY_TARGET_NAME} PRIVATE "${C5T_LIBRARIES}") - if(APPLE) - target_link_libraries(${BINARY_TARGET_NAME} PRIVATE -Wl,-force_load "${USR_LIBRARIES}") - else() - target_link_libraries(${BINARY_TARGET_NAME} PRIVATE "${USR_LIBRARIES}") - endif() + target_link_libraries(${BINARY_TARGET_NAME} PRIVATE "${USR_LIBRARIES}") endif() endforeach() @@ -183,10 +175,6 @@ foreach(TEST_SOURCE_FILE ${TEST_SOURCE_FILES}) add_dependencies(${TEST_TARGET_NAME} C5T_CURRENT_BUILD_INFO_H_TARGET C5T_CUSTOM_PER_BUILD_SCRIPT_TARGET) target_include_directories(${TEST_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/inc") target_link_libraries(${TEST_TARGET_NAME} PRIVATE gtest_main "${C5T_LIBRARIES}") - if (APPLE) - target_link_libraries(${TEST_TARGET_NAME} PRIVATE -Wl,-force_load "${USR_LIBRARIES}") - else() - target_link_libraries(${TEST_TARGET_NAME} PRIVATE "${USR_LIBRARIES}") - endif() + target_link_libraries(${TEST_TARGET_NAME} PRIVATE "${USR_LIBRARIES}") add_test(NAME ${TEST_TARGET_NAME} COMMAND ${TEST_TARGET_NAME}) endforeach() From b37d9c3da7b3075bcb42a7b84b4d1274a047fc91 Mon Sep 17 00:00:00 2001 From: Dima Korolev Date: Wed, 31 Jul 2024 12:23:55 +0200 Subject: [PATCH 11/16] Fixed `gen-current-build.sh` to always output one line (ugly). --- scripts/gen-current-build.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/gen-current-build.sh b/scripts/gen-current-build.sh index 484cc05b..cc5bc672 100755 --- a/scripts/gen-current-build.sh +++ b/scripts/gen-current-build.sh @@ -15,9 +15,9 @@ if [[ $? -ne 0 ]]; then fi COMPILER_INFO=${COMPILER_INFO//$'\n'/\\n} # JSON-friendly newlines. -GIT_COMMIT="$(git rev-parse HEAD 2>/dev/null || echo '')" -GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo '')" -GIT_STATUS="$(git status 2>/dev/null || echo '')" +GIT_COMMIT="$($(git rev-parse HEAD 2>/dev/null || echo '') | tail -n 1)" +GIT_BRANCH="$($(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo '') | tail -n 1)" +GIT_STATUS="$($(git status 2>/dev/null || echo '') | tail -n 1)" # NOTE(dkorolev): Removing the commands that may potentially run for a long time. #GIT_DIFF_NAMES_MULTILINE="$(git diff --name-only 2>/dev/null || echo '')" From 69b9a5a4981712a7f3b8e5e5cebc0def20cc81b7 Mon Sep 17 00:00:00 2001 From: Dima Korolev Date: Wed, 31 Jul 2024 12:28:12 +0200 Subject: [PATCH 12/16] Running `make test` is `make debug_test` by default. --- cmake/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/Makefile b/cmake/Makefile index b30d6220..effad900 100644 --- a/cmake/Makefile +++ b/cmake/Makefile @@ -38,7 +38,7 @@ release_dir: ${RELEASE_BUILD_DIR} .gitignore ${RELEASE_BUILD_DIR}: CMakeLists.txt src @C5T_DEPS="${C5T_DEPS}" C5T_NO_GTEST="${C5T_NO_GTEST}" cmake -DCMAKE_BUILD_TYPE=Release -B "${RELEASE_BUILD_DIR}" . -test: release +release_test: release @(cd "${RELEASE_BUILD_DIR}"; make test) debug: debug_dir CMakeLists.txt @@ -53,7 +53,7 @@ ${DEBUG_BUILD_DIR}: CMakeLists.txt src debug_test: debug @(cd "${DEBUG_BUILD_DIR}"; make test) -test: release_test +test: debug_test fmt: ${CLANG_FORMAT} -i src/*.cc src/*.h From a30cc1529af46343276329369d6a10838162c356 Mon Sep 17 00:00:00 2001 From: Dima Korolev Date: Wed, 31 Jul 2024 12:36:38 +0200 Subject: [PATCH 13/16] Oops, fix. --- scripts/gen-current-build.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/gen-current-build.sh b/scripts/gen-current-build.sh index cc5bc672..5ba2e4c3 100755 --- a/scripts/gen-current-build.sh +++ b/scripts/gen-current-build.sh @@ -15,9 +15,9 @@ if [[ $? -ne 0 ]]; then fi COMPILER_INFO=${COMPILER_INFO//$'\n'/\\n} # JSON-friendly newlines. -GIT_COMMIT="$($(git rev-parse HEAD 2>/dev/null || echo '') | tail -n 1)" -GIT_BRANCH="$($(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo '') | tail -n 1)" -GIT_STATUS="$($(git status 2>/dev/null || echo '') | tail -n 1)" +GIT_COMMIT="$( (git rev-parse HEAD 2>/dev/null || echo '') | tail -n 1)" +GIT_BRANCH="$( (git rev-parse --abbrev-ref HEAD 2>/dev/null || echo '') | tail -n 1)" +GIT_STATUS="$( (git status 2>/dev/null || echo '') | tail -n 1)" # NOTE(dkorolev): Removing the commands that may potentially run for a long time. #GIT_DIFF_NAMES_MULTILINE="$(git diff --name-only 2>/dev/null || echo '')" From 0eda091a58d29b08d0758908f58a6a85eaf01663 Mon Sep 17 00:00:00 2001 From: Dima Korolev Date: Wed, 31 Jul 2024 12:41:26 +0200 Subject: [PATCH 14/16] fixes (will create a new, cleaner, PR). --- cmake/run-cmake-test.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cmake/run-cmake-test.sh b/cmake/run-cmake-test.sh index 238138c5..e6db5716 100755 --- a/cmake/run-cmake-test.sh +++ b/cmake/run-cmake-test.sh @@ -173,7 +173,7 @@ touch CMakeLists.txt echo echo "::group::release_test" -make test +make release_test echo "::endgroup::" echo "::group::debug_test" @@ -185,14 +185,14 @@ echo touch src/test_gtest.cc T0_GTEST=$(date +%s) echo "::group::one line change google gtest release" -make test +make release_test echo "::endgroup::" T1_GTEST=$(date +%s) touch src/test_current_gtest.cc T0_CURRENT_GTEST=$(date +%s) echo "::group::one line change current gtest release" -make test +make release_test echo "::endgroup::" T1_CURRENT_GTEST=$(date +%s) @@ -269,7 +269,6 @@ touch CMakeLists.txt echo "::group::build .current/libdlib_mul.{so|dylib} and .current/call_dynamic_mul" make echo "::endgroup::" - echo "::group::build .current_debug/libdlib_mul.{so|dylib} and .current_debug/call_dynamic_mul" make debug echo "::endgroup::" From 522910240cc7cc43f050b92bf3d474131f0647ce Mon Sep 17 00:00:00 2001 From: Dima Korolev Date: Wed, 31 Jul 2024 12:46:16 +0200 Subject: [PATCH 15/16] Minor, for tab completion. --- cmake/Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmake/Makefile b/cmake/Makefile index effad900..6af22f57 100644 --- a/cmake/Makefile +++ b/cmake/Makefile @@ -7,7 +7,7 @@ # # Besides, this `Makefiles` makes `:mak` in Vim work like a charm! -.PHONY: release debug release_dir debug_dir release_test debug_test test fmt clean +.PHONY: release debug _release_dir _debug_dir release_test debug_test test fmt clean # When this `Makefile` is used to run a `cmake`-based Current build, user-defined dependencies go here. # No quotes needed. Space- or colon- or semicolon-separated all work fine. @@ -29,10 +29,10 @@ endif CLANG_FORMAT=$(shell echo "$${CLANG_FORMAT:-clang-format}") -release: release_dir CMakeLists.txt +release: _release_dir CMakeLists.txt @MAKEFLAGS=--no-print-directory cmake --build "${RELEASE_BUILD_DIR}" -j ${CORES} -release_dir: ${RELEASE_BUILD_DIR} .gitignore +_release_dir: ${RELEASE_BUILD_DIR} .gitignore @grep "^${RELEASE_BUILD_DIR}/$$" .gitignore >/dev/null || echo "${RELEASE_BUILD_DIR}/" >>.gitignore ${RELEASE_BUILD_DIR}: CMakeLists.txt src @@ -41,10 +41,10 @@ ${RELEASE_BUILD_DIR}: CMakeLists.txt src release_test: release @(cd "${RELEASE_BUILD_DIR}"; make test) -debug: debug_dir CMakeLists.txt +debug: _debug_dir CMakeLists.txt @MAKEFLAGS=--no-print-directory cmake --build "${DEBUG_BUILD_DIR}" -j ${CORES} -debug_dir: ${DEBUG_BUILD_DIR} .gitignore +_debug_dir: ${DEBUG_BUILD_DIR} .gitignore @grep "^${DEBUG_BUILD_DIR}/$$" .gitignore >/dev/null || echo "${DEBUG_BUILD_DIR}/" >>.gitignore ${DEBUG_BUILD_DIR}: CMakeLists.txt src From e0740d4924fbc23e1099cb1394b962e34e030f8f Mon Sep 17 00:00:00 2001 From: Dima Korolev Date: Wed, 31 Jul 2024 13:19:17 +0200 Subject: [PATCH 16/16] More interactive debugging. --- CMakeLists.txt | 10 +++++----- cmake/CMakeLists.txt | 12 +++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eddda01b..5bb596ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,8 @@ cmake_minimum_required(VERSION 3.14.1) - project(C5T LANGUAGES C CXX) -message(STATUS "Add `C5T` into `target_link_libraries()` of your `CMakeLists.txt` to use `current` headers.") - -add_library(C5T INTERFACE) -target_include_directories(C5T INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}") +if (NOT TARGET C5T) + message(STATUS "Add `C5T` into `target_link_libraries()` of your `CMakeLists.txt` to use `current` headers.") + add_library(C5T INTERFACE) + target_include_directories(C5T INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}") +endif() diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 89e01d2d..5be5d346 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -67,13 +67,15 @@ function(UseGitOrCloneBranch remote branch) UseGitOrCloneImpl("${remote}" TRUE "${branch}") endfunction() -UseGitOrClone(https://github.com/c5t/current) +UseGitOrCloneBranch(https://github.com/dkorolev/current use_current_deps_github_org) # Set `C5T_NO_GTEST` in the `Makefile` to any non-empty value to speed up the builds that do not need `googletest`. -if("$ENV{C5T_NO_GTEST}" STREQUAL "") - UseGitOrClone(https://github.com/current-deps/googletest) -else() - message(STATUS "Skipping `googletest` as `C5T_NO_GTEST` is set.") +if(NOT TARGET gtest) + if("$ENV{C5T_NO_GTEST}" STREQUAL "") + UseGitOrClone(https://github.com/current-deps/googletest) + else() + message(STATUS "Skipping `googletest` as `C5T_NO_GTEST` is set.") + endif() endif() set_property(GLOBAL PROPERTY C5T_PATH ${C5T_DEP_DIR_current})