Skip to content

Commit 6e09d1f

Browse files
committed
✅ Update CMakeLists
1 parent eccb090 commit 6e09d1f

File tree

3 files changed

+64
-43
lines changed

3 files changed

+64
-43
lines changed

CMakeLists.txt

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,58 @@
1-
cmake_minimum_required(VERSION 3.8)
2-
project(iris CXX)
1+
cmake_minimum_required(VERSION 3.12)
2+
project(StrTpl
3+
VERSION 0.1.0
4+
LANGUAGES CXX
5+
)
6+
include(GNUInstallDirs)
37

4-
# Specify build type if not
8+
# Creates a library StrTpl which is an interface (header files only)
9+
add_library(StrTpl INTERFACE)
10+
# If you want to use StrTpl prefer to link against StrTpl using this alias target
11+
add_library(StrTpl::StrTpl ALIAS StrTpl)
12+
13+
# Specify build type ifnot
514
if(NOT CMAKE_BUILD_TYPE)
615
set(CMAKE_BUILD_TYPE "Release")
716
message(STATUS "CMAKE_BUILD_TYPE not specified: Use Release by default.")
817
endif(NOT CMAKE_BUILD_TYPE)
918

1019
# Determine whether this is a standalone project or included by other projects
11-
set(IRIS_STANDALONE_PROJECT OFF)
12-
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
13-
set(IRIS_STANDALONE_PROJECT ON)
20+
set(STRTPL_STANDALONE_PROJECT OFF)
21+
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
22+
set(STRTPL_STANDALONE_PROJECT ON)
1423
endif()
1524

1625
# Project options
17-
option(IRIS_TEST "Build and perform iris tests" ${IRIS_STANDALONE_PROJECT})
26+
option(STRTPL_INSTALL "Generate and install StrTpl target" ${STRTPL_STANDALONE_PROJECT})
27+
option(STRTPL_TEST "Build and perform StrTpl tests" ${STRTPL_STANDALONE_PROJECT})
1828

1929
# Setup include directory
2030
add_subdirectory(include)
2131

22-
# Setup test directory
23-
if (IRIS_TEST)
32+
if(STRTPL_INSTALL)
33+
install(
34+
TARGETS StrTpl
35+
EXPORT StrTplConfig
36+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
37+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
38+
# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
39+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
40+
)
41+
install(
42+
DIRECTORY include/strtpl
43+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
44+
)
45+
# Make library importable by other projects
46+
install(
47+
EXPORT StrTplConfig
48+
NAMESPACE StrTpl::
49+
FILE StrTplConfig.cmake
50+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/StrTpl
51+
# EXPORT_LINK_INTERFACE_LIBRARIES
52+
)
53+
endif()
54+
55+
if(STRTPL_TEST)
2456
include(CTest)
2557
add_subdirectory(tests)
2658
endif()

include/CMakeLists.txt

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
1-
# Creates a library iris which is an interface (header files only)
2-
add_library(iris INTERFACE)
3-
# If you want to use iris prefer to link against iris using this alias target
4-
add_library(iris::iris ALIAS iris)
5-
# Set C++ version
6-
target_compile_features(iris INTERFACE cxx_std_20)
7-
set_target_properties(iris PROPERTIES
8-
CXX_STANDARD_REQUIRED ON
9-
CXX_EXTENSIONS OFF
10-
)
11-
121
# Add include folders to the library and targets that consume it the SYSTEM
132
# keyword suppresses warnings for users of the library
14-
if(IRIS_STANDALONE_PROJECT)
15-
target_include_directories(iris INTERFACE
3+
if(STRTPL_STANDALONE_PROJECT)
4+
target_include_directories(StrTpl INTERFACE
165
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
176
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
187
)
198
else()
20-
target_include_directories(iris SYSTEM INTERFACE
9+
target_include_directories(StrTpl SYSTEM INTERFACE
2110
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
2211
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
2312
)
2413
endif()
25-
26-
# Add (header only) external libraries
27-
# find_package(Boost 1.61.0 REQUIRED)
28-
# target_link_libraries(iris SYSTEM INTERFACE Boost::boost)

tests/CMakeLists.txt

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1-
cmake_minimum_required(VERSION 3.8)
2-
project(iris_tests CXX)
1+
cmake_minimum_required(VERSION 3.12)
2+
project(StrTplTests
3+
LANGUAGES CXX
4+
)
35
include(CTest)
46

7+
# Import the globally installed StrTpl ifCMake has been started independently in
8+
# this directory with tests
9+
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
10+
find_package(StrTpl REQUIRED)
11+
endif()
12+
513
# This interface adds compile options to how the tests are run
6-
add_library(iris_tests_config INTERFACE)
7-
target_compile_options(iris_tests_config INTERFACE
14+
add_library(StrTplTestsConfig INTERFACE)
15+
target_compile_features(StrTplTestsConfig INTERFACE cxx_std_20)
16+
set_target_properties(StrTplTestsConfig PROPERTIES
17+
CXX_STANDARD_REQUIRED ON
18+
CXX_EXTENSIONS OFF
19+
)
20+
target_compile_options(StrTplTestsConfig INTERFACE
821
-fno-strict-aliasing
922
-Wall
1023
-Wcast-align
@@ -31,12 +44,12 @@ target_compile_options(iris_tests_config INTERFACE
3144
>
3245
# $<$<CXX_COMPILER_ID:Clang>:
3346
# $<$<AND:$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,4.99>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,6>>:
34-
# $<$<EQUAL:${IRIS_CXX_STANDARD},17>:-Wno-undefined-func-template>
47+
# $<$<EQUAL:${STRTPL_CXX_STANDARD},17>:-Wno-undefined-func-template>
3548
# >
3649
# >
3750
# $<$<CXX_COMPILER_ID:AppleClang>:
3851
# $<$<AND:$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,9.1>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,10>>:
39-
# $<$<EQUAL:${IRIS_CXX_STANDARD},17>:-Wno-undefined-func-template>
52+
# $<$<EQUAL:${STRTPL_CXX_STANDARD},17>:-Wno-undefined-func-template>
4053
# >
4154
# >
4255
$<$<CXX_COMPILER_ID:GNU>:
@@ -53,19 +66,10 @@ target_compile_options(iris_tests_config INTERFACE
5366
>
5467
)
5568

56-
# Import the globally installed iris if CMake has been started independently in
57-
# this directory with tests
58-
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
59-
find_package(iris::iris REQUIRED)
60-
endif()
61-
62-
# Use Catch2 as a unit testing framework
63-
# find_package(Catch2)
64-
6569
Include(FetchContent)
6670
FetchContent_Declare(Catch2
6771
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
68-
GIT_TAG v2.13.6)
72+
GIT_TAG v3.0.1)
6973
FetchContent_MakeAvailable(Catch2)
7074

7175
add_subdirectory(main)

0 commit comments

Comments
 (0)