Skip to content

Commit

Permalink
experiment with static linking
Browse files Browse the repository at this point in the history
  • Loading branch information
janjurca committed May 28, 2024
1 parent 2ff97bd commit 15d3e29
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ CPMAddPackage("gh:TheLartians/[email protected]")
# CPMAddPackage( NAME nlohmann_json GITHUB_REPOSITORY nlohmann/json VERSION 3.9.1 OPTIONS
# "JSON_BuildTests OFF" )

# Ensure static linking by setting CMAKE_FIND_LIBRARY_SUFFIXES
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")

# Prefer static libraries over shared ones
set(BUILD_SHARED_LIBS OFF)

find_package(fmt REQUIRED)
find_package(spdlog REQUIRED)
find_package(cxxopts REQUIRED)
Expand All @@ -45,7 +51,7 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/
# ---- Create library ----
# add_library(filestorm ${headers} ${sources}) Note: for header-only libraries change all PUBLIC
# flags to INTERFACE and create an interface target: add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME} ${headers} ${sources})
add_library(${PROJECT_NAME} STATIC ${headers} ${sources})
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17)

# being a cross-platform target, we enforce standards conformance on MSVC
Expand Down Expand Up @@ -75,7 +81,7 @@ packageProject(
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
VERSION_HEADER "${VERSION_HEADER_LOCATION}"
COMPATIBILITY SameMajorVersion
DEPENDENCIES "spdlog;fmt" CPACK YES
# DEPENDENCIES "spdlog;fmt" CPACK YES
)

file(GLOB standalone_sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/standalone/source/*.cpp)
Expand All @@ -92,7 +98,7 @@ install(TARGETS ${PROJECT_NAME}Executable RUNTIME DESTINATION ${CMAKE_INSTALL_BI
COMPONENT "${PROJECT_NAME}_Runtime"
)

set(CPACK_RPM_PACKAGE_REQUIRES "spdlog, fmt")
# set(CPACK_RPM_PACKAGE_REQUIRES "spdlog, fmt")
set(CPACK_RPM_BUILDREQUIRES
"cmake, gcc-c++, spdlog-devel, fmt-devel, git, cxxopts-devel, json-devel"
)
Expand Down

0 comments on commit 15d3e29

Please sign in to comment.