From 512c53bbe56cbd8e18b5cabc4915f4e0af17d4fa Mon Sep 17 00:00:00 2001 From: James Robert Hawk Date: Fri, 9 Jan 2026 15:08:30 +0000 Subject: [PATCH 1/3] Combine output static libraries into one for simplified consumption. Produces a simplified artifact that can be easily linked to external projects. Change made in response to requirement of customer that ingests this library. --- CMakeLists.txt | 60 ++++++++++++++++++++++++++++++++++++++++++++ cli/CMakeLists.txt | 3 ++- tools/CMakeLists.txt | 49 ++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 725284b..0ba1e0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,6 +82,57 @@ source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" set_target_properties(resources PROPERTIES OUTPUT_NAME "_resources") + + +# Combine static libraries to single static for distribution +# This is useful for consumers taht just want a simple single +# file to link against + +if (WIN32) + + set(RESOURCES_STANDALONE_LIB_NAME _resources_static_standalone.lib) + + #requires lib.exe to be available msvc + add_custom_command(TARGET resources POST_BUILD + COMMAND lib.exe + /OUT:${RESOURCES_STANDALONE_LIB_NAME} + $ + $ + $ + /VERBOSE + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + +elseif(APPLE) + + set(RESOURCES_STANDALONE_LIB_NAME _resources_static_standalone.a) + + #libtool -static -o new.a old1.a old2.a + add_custom_command(TARGET resources POST_BUILD + COMMAND libtool -static -o ${RESOURCES_STANDALONE_LIB_NAME} + $ + $ + $ + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + +else() + message(FATAL_ERROR "Unsupported platform") + +endif() + +# Add library for static standalone +# This is then used for CLI as a way for testing the library +add_library(resources-static-standalone STATIC IMPORTED GLOBAL) +add_dependencies(resources-static-standalone resources) + +set_target_properties(resources-static-standalone + PROPERTIES + IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${RESOURCES_STANDALONE_LIB_NAME} + INTERFACE_INCLUDE_DIRECTORIES "$;$" + INTERFACE_COMPILE_DEFINITIONS CARBON_RESOURCES_STATIC + ) + add_subdirectory(cli) # Enable testing based on option set (on by default) @@ -140,6 +191,10 @@ if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) ARCHIVE DESTINATION lib/${CCP_PLATFORM}/${CCP_ARCHITECTURE}/${CCP_TOOLSET}/ RUNTIME DESTINATION bin/${CCP_PLATFORM}/${CCP_ARCHITECTURE}/${CCP_TOOLSET}/ ) + + # Copy the standalone static library + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${RESOURCES_STANDALONE_LIB_NAME} + DESTINATION lib/${CCP_PLATFORM}/${CCP_ARCHITECTURE}/${CCP_TOOLSET}/) else () # Install rule to ensure that our runtime and linker files are in the expected, platform-specific folders install( @@ -150,6 +205,11 @@ if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) ARCHIVE DESTINATION lib/${CCP_PLATFORM}/${CCP_ARCHITECTURE}/${CCP_TOOLSET}/ RUNTIME DESTINATION bin/${CCP_PLATFORM}/${CCP_ARCHITECTURE}/${CCP_TOOLSET}/ ) + + # Copy the standalone static library + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${RESOURCES_STANDALONE_LIB_NAME} + DESTINATION lib/${CCP_PLATFORM}/${CCP_ARCHITECTURE}/${CCP_TOOLSET}/) + # Install rule for available public headers install(DIRECTORY include DESTINATION . FILES_MATCHING PATTERN "*.h") diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index be7a225..5fb8dd4 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -30,7 +30,8 @@ set(SRC_FILES ccp_add_executable(resources-cli ${SRC_FILES}) -target_link_libraries(resources-cli PRIVATE resources argparse::argparse yaml-cpp::yaml-cpp) +# Links with resources-static-standalone to ensure that the combine lib is functional +target_link_libraries(resources-cli PRIVATE resources-static-standalone argparse::argparse) get_target_property(_SOURCES resources-cli SOURCES) source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 06b8025..2ab78f9 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -54,3 +54,52 @@ endif () target_link_libraries(resources-tools PRIVATE cryptopp::cryptopp CURL::libcurl ZLIB::ZLIB static_bsdiff) target_include_directories(resources-tools PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) + + +# Combine resource tools into single library +if (WIN32) + + set(RESOURCES_TOOLS_STANDALONE_LIB_NAME _resources_tools_static_standalone.lib) + + add_custom_command(TARGET resources-tools POST_BUILD + COMMAND lib.exe + /OUT:${RESOURCES_TOOLS_STANDALONE_LIB_NAME} + $ + $ + $ + $ + $ + ws2_32.lib + crypt32.lib + /VERBOSE + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + +elseif(APPLE) + + set(RESOURCES_TOOLS_STANDALONE_LIB_NAME _resources_tools_static_standalone.a) + + #libtool -static -o new.a old1.a old2.a + add_custom_command(TARGET resources-tools POST_BUILD + COMMAND libtool -static -o ${RESOURCES_TOOLS_STANDALONE_LIB_NAME} + $ + $ + $ + $ + $ + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + +else() + message(FATAL_ERROR "Unsupported platform") + +endif() + +add_library(resources-tools-static-standalone STATIC IMPORTED GLOBAL) +add_dependencies(resources-tools-static-standalone resources-tools) + +set_target_properties(resources-tools-static-standalone + PROPERTIES + IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${RESOURCES_TOOLS_STANDALONE_LIB_NAME} + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_LIST_DIR}/include" + ) \ No newline at end of file From 287832bf5564d6cf2e03ddc58f96760e507fdc8e Mon Sep 17 00:00:00 2001 From: James Robert Hawk Date: Mon, 12 Jan 2026 13:10:15 +0000 Subject: [PATCH 2/3] Use non combined lib for cli to fix ninja issue --- CMakeLists.txt | 1 - cli/CMakeLists.txt | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ba1e0f..74f86bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,7 +122,6 @@ else() endif() # Add library for static standalone -# This is then used for CLI as a way for testing the library add_library(resources-static-standalone STATIC IMPORTED GLOBAL) add_dependencies(resources-static-standalone resources) diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index 5fb8dd4..747d7dd 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -30,8 +30,7 @@ set(SRC_FILES ccp_add_executable(resources-cli ${SRC_FILES}) -# Links with resources-static-standalone to ensure that the combine lib is functional -target_link_libraries(resources-cli PRIVATE resources-static-standalone argparse::argparse) +target_link_libraries(resources-cli PRIVATE resources argparse::argparse) get_target_property(_SOURCES resources-cli SOURCES) source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" From dffbfe34998c892673673d4f6da09824765a3cbe Mon Sep 17 00:00:00 2001 From: James Robert Hawk Date: Mon, 12 Jan 2026 13:33:28 +0000 Subject: [PATCH 3/3] Indicate to cmake where combine library is build. Requirement of ninja build system. Reinstate cli being built using combined static library. --- CMakeLists.txt | 2 ++ cli/CMakeLists.txt | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 74f86bc..719af28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,6 +101,7 @@ if (WIN32) $ /VERBOSE WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + BYPRODUCTS ${RESOURCES_STANDALONE_LIB_NAME} ) elseif(APPLE) @@ -114,6 +115,7 @@ elseif(APPLE) $ $ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + BYPRODUCTS ${RESOURCES_STANDALONE_LIB_NAME} ) else() diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index 747d7dd..5fb8dd4 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -30,7 +30,8 @@ set(SRC_FILES ccp_add_executable(resources-cli ${SRC_FILES}) -target_link_libraries(resources-cli PRIVATE resources argparse::argparse) +# Links with resources-static-standalone to ensure that the combine lib is functional +target_link_libraries(resources-cli PRIVATE resources-static-standalone argparse::argparse) get_target_property(_SOURCES resources-cli SOURCES) source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}"