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}) # --- Test it --- enable_testing() add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME} --help) # --- Install it --- install(TARGETS ${PROJECT_NAME} RUNTIME) include(CPack)