-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
140 lines (111 loc) · 4.48 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
cmake_minimum_required(VERSION 3.6)
if (PROJECT_NAME)
set(IS_SUBPROJECT TRUE)
endif ()
set(CATCH_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/third_party/catch/contrib")
set(DELEGATE_CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
set(DELEGATE_CMAKE_TEMPLATE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/templates")
set(CMAKE_MODULE_PATH "${DELEGATE_CMAKE_MODULE_PATH}" "${CATCH_MODULE_PATH}" "${CMAKE_MODULE_PATH}")
option(DELEGATE_COMPILE_UNIT_TESTS "Compile and run the unit tests for this library" ON)
if (NOT CMAKE_TESTING_ENABLED AND DELEGATE_COMPILE_UNIT_TESTS)
enable_testing()
endif ()
project(Delegate
VERSION "0.0.1"
LANGUAGES CXX
)
set(DELEGATE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR} CACHE INTERNAL "Major version of Delegate")
set(DELEGATE_VERSION_MINOR ${PROJECT_VERSION_MINOR} CACHE INTERNAL "Minor version of Delegate")
set(DELEGATE_VERSION_PATCH ${PROJECT_VERSION_PATCH} CACHE INTERNAL "Patch version of Delegate")
set(DELEGATE_VERSION ${PROJECT_VERSION} CACHE INTERNAL "Version of Delegate")
##############################################################################
# Targets
##############################################################################
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(header_files
include/delegate.hpp
)
add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME}
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
INTERFACE $<INSTALL_INTERFACE:include>
)
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND
"${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
# clang-cl does not appear to implement '-pedantic' or 'pedantic-errors',
# so this case needs to be handled specifically
add_compile_options(-Wall -Werror -Wextra)
# clang-cl treats '-Wall' like '-Weverything' currently; so there are a few
# warnings we need to manually disable.
# Disable unnecessary compatibility and 'newline-eof'. This is a modern C++
# library -- so these serve no purpose
add_compile_options(-Wno-c++98-compat -Wno-c++98-compat-pedantic)
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(-Wall -Werror -Wextra -pedantic -pedantic-errors)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
add_compile_options(/W4 /WX)
endif ()
include(AddSelfContainmentTest)
if (DELEGATE_COMPILE_UNIT_TESTS)
add_subdirectory("third_party/catch")
add_self_containment_test(${PROJECT_NAME}.SelfContainmentTest
TARGET ${PROJECT_NAME}
HEADERS ${header_files}
)
add_subdirectory("test")
endif ()
##############################################################################
# Installation
##############################################################################
if (IS_SUBPROJECT)
return()
endif ()
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
set(DELEGATE_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
# The generated *ConfigVersion is strongly tied to the architecture
# it was generated on, and sets variables such as 'SIZEOF_VOID_P'.
# Since this library is header-only, the host architecture does not
# actually affect the target that consumes this project, so we fake
# the variable to be empty, but reset it after.
#
# Otherwise a 64-bit creator would cause a 32-bit consumer to fail to
# use this library, even though it's header-only.
set(DELEGATE_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
set(CMAKE_SIZEOF_VOID_P "")
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION "${PROJECT_VERSION}"
COMPATIBILITY "SameMajorVersion"
)
set(CMAKE_SIZEOF_VOID_P ${DELEGATE_CMAKE_SIZEOF_VOID_P})
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${DELEGATE_CMAKE_CONFIG_DESTINATION}"
)
# Targets
install(
TARGETS "${PROJECT_NAME}"
EXPORT "${PROJECT_NAME}Targets"
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
install(
EXPORT "${PROJECT_NAME}Targets"
NAMESPACE "${PROJECT_NAME}::"
DESTINATION "${DELEGATE_CMAKE_CONFIG_DESTINATION}"
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION "${DELEGATE_CMAKE_CONFIG_DESTINATION}"
)
# Includes
install(
DIRECTORY "include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)