From 512375c4d7bf0f0efeb3c3c674f9f27de1c133b4 Mon Sep 17 00:00:00 2001 From: Peter Csajtai Date: Sat, 27 Jul 2024 21:40:05 +0200 Subject: [PATCH] Fixup CMake files --- CMakeLists.txt | 34 +++++++++++++++++----------------- test/CMakeLists.txt | 4 ++-- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0037b6d..9ebb793 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,9 @@ endif() option(SEMVER_BUILD_TESTS "Enable builds of tests" ${TOP_PROJECT}) option(SEMVER_INSTALL "Enable install target" ${TOP_PROJECT}) -option(SEMVER_CPP20_MODULE "Build as C++20 module" ${TOP_PROJECT}) +option(SEMVER_BUILD_MODULE "Build as C++20 module" ${TOP_PROJECT}) -if (SEMVER_CPP20_MODULES) +if (SEMVER_BUILD_MODULE) cmake_minimum_required(VERSION 3.28) else() cmake_minimum_required(VERSION 3.14) @@ -26,30 +26,30 @@ message(VERBOSE " CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}") message(VERBOSE " CMAKE_CXX_COMPILER_VERSION: ${CMAKE_CXX_COMPILER_VERSION}") message(VERBOSE " CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") -add_library(${PROJECT_NAME} INTERFACE) -add_library (${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) -target_include_directories( - ${PROJECT_NAME} INTERFACE - $ - $) - -target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17) - -if(SEMVER_CPP20_MODULE) - add_library(${PROJECT_NAME}-module) - set_target_properties(${PROJECT_NAME}-module PROPERTIES +if(SEMVER_BUILD_MODULE) + add_library(${PROJECT_NAME}) + set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF) - target_compile_features(${PROJECT_NAME}-module PUBLIC cxx_std_20) - target_sources(${PROJECT_NAME}-module + target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) + target_sources(${PROJECT_NAME} PUBLIC FILE_SET CXX_MODULES FILES module/semver.cppm) + target_include_directories(${PROJECT_NAME} + PUBLIC + $ + $) +else() + add_library(${PROJECT_NAME} INTERFACE) target_include_directories( - ${PROJECT_NAME}-module PUBLIC + ${PROJECT_NAME} INTERFACE $ $) + target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17) endif() +add_library (${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) + ## -------------------------------------------------------------------- ## TESTS ## -------------------------------------------------------------------- diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index fa85aa5..65a3ea0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -23,9 +23,9 @@ catch_discover_tests(${PROJECT_NAME}-tests-17) # add c++20 tests set(TARGET_LIBS Catch2::Catch2WithMain ${PROJECT_NAME}) -if(SEMVER_CPP20_MODULE) +if(SEMVER_BUILD_MODULE) list(APPEND TEST_SRC module/module_tests.cpp) - list(APPEND TARGET_LIBS ${PROJECT_NAME}-module) + list(APPEND TARGET_LIBS ${PROJECT_NAME}) endif() add_executable(${PROJECT_NAME}-tests-20 ${TEST_SRC}) set_target_properties(${PROJECT_NAME}-tests-20 PROPERTIES CXX_STANDARD 20)