mirror of
https://github.com/TheLartians/ModernCppStarter.git
synced 2025-08-30 21:51:12 +02:00
- Upgrade to gitup workflow action v3 - Prepare use of git-flow - Use CMake v3.21 variable PROJECT_IS_TOP_LEVEL - Use CMAKE_DEBUG_POSTFIX to prevent name clashes - Add more config files
58 lines
1.5 KiB
CMake
58 lines
1.5 KiB
CMake
cmake_minimum_required(VERSION 3.21...3.27)
|
|
|
|
project(GreeterStandalone LANGUAGES CXX)
|
|
|
|
if(PROJECT_IS_TOP_LEVEL AND CMAKE_BUILD_TYPE STREQUAL "Release")
|
|
set(CMAKE_SKIP_INSTALL_RULES
|
|
NO
|
|
CACHE BOOL "Forced generation of installation rules" FORCE
|
|
)
|
|
endif()
|
|
|
|
option(OPTION_ENABLE_UNITY "Enable Unity builds of project" ON)
|
|
|
|
# --- Import tools ----
|
|
|
|
include(../cmake/tools.cmake)
|
|
|
|
# ---- Dependencies ----
|
|
|
|
include(../cmake/CPM.cmake)
|
|
|
|
CPMAddPackage(
|
|
GITHUB_REPOSITORY jarro2783/cxxopts
|
|
VERSION 3.1.1
|
|
SYSTEM ON # used in case of cmake v3.25
|
|
OPTIONS "CXXOPTS_BUILD_EXAMPLES NO" "CXXOPTS_BUILD_TESTS NO" "CXXOPTS_ENABLE_INSTALL YES"
|
|
)
|
|
|
|
CPMAddPackage(
|
|
NAME Greeter
|
|
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..
|
|
FORCE ON
|
|
)
|
|
|
|
# ---- Create standalone executable ----
|
|
|
|
file(GLOB sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp)
|
|
|
|
add_executable(${PROJECT_NAME} ${sources})
|
|
if(CMAKE_DEBUG_POSTFIX)
|
|
set_property(TARGET ${PROJECT_NAME} PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
|
endif()
|
|
target_link_libraries(${PROJECT_NAME} Greeter::Greeter cxxopts::cxxopts)
|
|
set_target_properties(${PROJECT_NAME} PROPERTIES UNITY_BUILD ${OPTION_ENABLE_UNITY})
|
|
|
|
# TODO(CK): why is this used? This overrides the CMAKE_DEBUG_POSTFIX!
|
|
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME Greeter)
|
|
|
|
# --- Test it ---
|
|
|
|
enable_testing()
|
|
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME} --help)
|
|
|
|
# --- Install it ---
|
|
|
|
install(TARGETS ${PROJECT_NAME} RUNTIME)
|
|
|
|
include(CPack)
|