This commit is contained in:
@ -5,11 +5,14 @@ execute_process(
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
if(NOT DEFINED PROJECT_NAME)
|
||||
message(FATAL_ERROR "PROJECT_NAME is not defined. Pass it via -DPROJECT_NAME=<name>")
|
||||
endif()
|
||||
|
||||
# Include required modules
|
||||
include(FetchContent)
|
||||
|
||||
project(${PROJECT_NAME} VERSION ${PROJECT_VERSION} LANGUAGES CXX)
|
||||
set(PROJECT_EXE_NAME ${PROJECT_NAME})
|
||||
|
||||
@ -19,16 +22,16 @@ set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries" FORCE)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static -rdynamic")
|
||||
set(ZLIB_USE_STATIC_LIBS "ON")
|
||||
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_C_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Set default build type to Release if not specified
|
||||
# Set default build type to Debug if not specified
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build (Debug or Release)" FORCE)
|
||||
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build (Debug or Release)" FORCE)
|
||||
endif()
|
||||
|
||||
# Configure build-specific compiler flags
|
||||
@ -69,24 +72,6 @@ target_include_directories(${PROJECT_EXE_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/autogen
|
||||
)
|
||||
|
||||
|
||||
# Configure libassert
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
libassert
|
||||
GIT_REPOSITORY https://github.com/jeremy-rifkin/libassert.git
|
||||
GIT_TAG v2.1.5
|
||||
)
|
||||
FetchContent_MakeAvailable(libassert)
|
||||
|
||||
# Add cpptrace
|
||||
FetchContent_Declare(
|
||||
cpptrace
|
||||
GIT_REPOSITORY https://github.com/jeremy-rifkin/cpptrace.git
|
||||
GIT_TAG v0.8.3
|
||||
)
|
||||
FetchContent_MakeAvailable(cpptrace)
|
||||
|
||||
# Add nlohmann/json
|
||||
FetchContent_Declare(
|
||||
nlohmann_json
|
||||
@ -95,17 +80,31 @@ FetchContent_Declare(
|
||||
)
|
||||
FetchContent_MakeAvailable(nlohmann_json)
|
||||
|
||||
# Link libraries
|
||||
target_link_libraries(${PROJECT_EXE_NAME} PRIVATE
|
||||
libassert::assert
|
||||
cpptrace::cpptrace
|
||||
nlohmann_json::nlohmann_json
|
||||
# Find required libraries using pkg-config
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(LIBUNWIND REQUIRED IMPORTED_TARGET libunwind)
|
||||
|
||||
# Additional required libraries for static linking
|
||||
set(EXTRA_LIBS
|
||||
${LIBUNWIND_LIBRARIES}
|
||||
-lunwind
|
||||
-lunwind-x86_64
|
||||
-llzma
|
||||
-lz
|
||||
-ldl
|
||||
)
|
||||
|
||||
# Add execinfo to linker flags
|
||||
set_target_properties(${PROJECT_EXE_NAME} PROPERTIES
|
||||
LINK_FLAGS "-static"
|
||||
# Link libraries
|
||||
target_link_libraries(${PROJECT_EXE_NAME} PRIVATE
|
||||
nlohmann_json::nlohmann_json
|
||||
${EXTRA_LIBS}
|
||||
)
|
||||
|
||||
# Set static linking flags
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
|
||||
|
||||
# Add musl's backtrace headers
|
||||
include_directories(/usr/include/musl)
|
Reference in New Issue
Block a user