-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
106 lines (90 loc) · 3.41 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
cmake_minimum_required(VERSION 3.14)
project(cturtle VERSION 1.0.0.0)
message( STATUS "Building cturtle v${cturtle_VERSION}..." )
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads)
link_libraries(Threads::Threads)
include(CMakeDependentOption)
option(ENABLE_INSTALL "enable installation" ON)
option(ENABLE_TESTS "enable building of unit tests" OFF)
include(FetchContent)
# ##################################################################################################
# Add dependencies.
# ##################################################################################################
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt
GIT_TAG master
)
FetchContent_GetProperties(fmt)
if (NOT fmt_POPULATED)
set(FMT_INSTALL ON)
FetchContent_MakeAvailable(fmt)
endif()
add_library(cturtle INTERFACE)
target_include_directories(cturtle INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
add_library(bluegrass::cturtle ALIAS cturtle)
target_link_libraries(cturtle INTERFACE fmt::fmt-header-only)
if(ENABLE_TESTS)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2
GIT_TAG devel
)
FetchContent_GetProperties(Catch2)
if (NOT Catch2_POPULATED)
FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH "${catch2_SOURCE_DIR}/contrib")
endif()
include(CTest)
include(Catch)
enable_testing()
add_subdirectory(tests)
endif()
# ##################################################################################################
# Configure version info.
# ##################################################################################################
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/modules/cturtle-config-version.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cturtle-config-version.cmake @ONLY)
# ##################################################################################################
# Installation.
# ##################################################################################################
if(ENABLE_INSTALL)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
message(STATUS "Installing bluegrass cturtle ...")
set(cturtle_INCLUDE_DIRS ${CMAKE_INSTALL_INCLUDEDIR})
configure_package_config_file(modules/cturtle-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cturtle-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cturtle
PATH_VARS cturtle_INCLUDE_DIRS
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/cturtle-config-version.cmake
VERSION ${cturtle_VERSION}
COMPATIBILITY SameMajorVersion
)
install(TARGETS cturtle
EXPORT cturtle-targets
LIBRARY
PUBLIC_HEADER
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT Headers
)
install(EXPORT cturtle-targets
NAMESPACE bluegrass::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cturtle
)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/bluegrass
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cturtle-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/cturtle-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cturtle
)
endif()