aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2025-02-26 12:07:40 +0100
committerFelix Morgner <felix.morgner@gmail.com>2025-02-26 12:07:40 +0100
commit0384acce9fe18c59605835300c52d4b5bc38db45 (patch)
tree4b7e3363ccf71d6f426dd2d95aaee0f98175f24a
parent440d47cae6431de3332ac934b6056a970cc1a0d7 (diff)
downloadnewtype-0384acce9fe18c59605835300c52d4b5bc38db45.tar.xz
newtype-0384acce9fe18c59605835300c52d4b5bc38db45.zip
build: clean up CMakeLists.txt files
-rw-r--r--CMakeLists.txt22
-rw-r--r--examples/CMakeLists.txt2
-rw-r--r--lib/CMakeLists.txt13
-rw-r--r--tests/CMakeLists.txt30
4 files changed, 47 insertions, 20 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 36b5b62..e154430 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,15 +5,25 @@ project("newtype"
DESCRIPTION "A library of types and functions to create strong type aliases"
)
-enable_testing()
-
# Project Options
-option(BUILD_EXAMPLES "Build the library examples" OFF)
+option(NEWTYPE_BUILD_DOCS "Build the library documentation" ON)
+option(NEWTYPE_BUILD_EXAMPLES "Build the library examples" ON)
+option(NEWTYPE_BUILD_TESTS "Build the library tests" ON)
# Project Components
-add_subdirectory("doc")
-add_subdirectory("examples")
add_subdirectory("lib")
-#add_subdirectory("tests") \ No newline at end of file
+
+if(NEWTYPE_BUILD_DOCS)
+ add_subdirectory("doc")
+endif()
+
+if(NEWTYPE_BUILD_EXAMPLES)
+ add_subdirectory("examples")
+endif()
+
+if(NEWTYPE_BUILD_TESTS)
+ enable_testing()
+ add_subdirectory("tests")
+endif() \ No newline at end of file
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 73d961e..a25b061 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -7,7 +7,7 @@ file(GLOB SOURCES
foreach(EXAMPLE IN LISTS SOURCES)
get_filename_component(NAME "${EXAMPLE}" NAME_WE)
add_executable("ex_${NAME}" "${EXAMPLE}")
- target_link_libraries("ex_${NAME}" "newtype::newtype")
+ target_link_libraries("ex_${NAME}" "newtype::lib")
endforeach()
install(DIRECTORY "src/"
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 0219803..9a36e3d 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -1,16 +1,21 @@
-add_library("${PROJECT_NAME}" INTERFACE)
+add_library("newtype" INTERFACE)
-target_include_directories("${PROJECT_NAME}" INTERFACE
+target_include_directories("newtype" INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>"
)
-target_compile_features("${PROJECT_NAME}" INTERFACE
+target_compile_features("newtype" INTERFACE
"cxx_std_20"
)
+set_target_properties("newtype" PROPERTIES
+ CMAKE_CXX_EXTENSIONS OFF
+ CMAKE_CXX_STANDARD_REQUIRED YES
+)
+
install(DIRECTORY "include/"
TYPE INCLUDE
)
-add_library("${PROJECT_NAME}::${PROJECT_NAME}" ALIAS "${PROJECT_NAME}")
+add_library("newtype::lib" ALIAS "newtype")
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 47b8331..8e5e798 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,9 +1,17 @@
-find_package("Catch2" "3.1"
+include("FetchContent")
+
+FetchContent_Declare(
+ "Catch2"
+ URL "https://github.com/catchorg/Catch2/archive/refs/tags/v3.7.0.zip"
+ URL_HASH "SHA256=75b04c94471a70680f10f5d0d985bd1a96b8941d040d6a7bfd43f6c6b1de9daf"
+ EXCLUDE_FROM_ALL
+ FIND_PACKAGE_ARGS
+ "3.7.0" EXACT
COMPONENTS "Catch2WithMain"
- REQUIRED
)
-include("CTest")
+FetchContent_MakeAvailable("Catch2")
+
include("Catch")
file(GLOB SOURCES
@@ -12,17 +20,16 @@ file(GLOB SOURCES
"src/*.cpp"
)
-
-add_executable("${PROJECT_NAME}_tests"
+add_executable("newtype_tests"
${SOURCES}
)
-target_link_libraries("${PROJECT_NAME}_tests"
- "${PROJECT_NAME}::${PROJECT_NAME}"
+target_link_libraries("newtype_tests"
+ "newtype::lib"
"Catch2::Catch2WithMain"
)
-target_compile_options("${PROJECT_NAME}_tests" PRIVATE
+target_compile_options("newtype_tests" PRIVATE
"$<$<CXX_COMPILER_ID:GNU,Clang>:-Wall>"
"$<$<CXX_COMPILER_ID:GNU,Clang>:-Wextra>"
"$<$<CXX_COMPILER_ID:GNU,Clang>:-Werror>"
@@ -30,4 +37,9 @@ target_compile_options("${PROJECT_NAME}_tests" PRIVATE
"$<$<CXX_COMPILER_ID:GNU>:-fconcepts-diagnostics-depth=5>"
)
-catch_discover_tests("${PROJECT_NAME}_tests")
+set_target_properties("newtype_tests" PROPERTIES
+ CMAKE_CXX_EXTENSIONS OFF
+ CMAKE_CXX_STANDARD_REQUIRED YES
+)
+
+catch_discover_tests("newtype_tests")