forked from Naios/function2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
128 lines (108 loc) · 3.81 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
cmake_minimum_required(VERSION 3.11)
project(function2 VERSION 4.0.0 LANGUAGES CXX)
if (NOT FU2_IS_FIND_INCLUDED)
string(COMPARE EQUAL ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}
FU2_IS_TOP_LEVEL_PROJECT)
endif()
if (FU2_IS_TOP_LEVEL_PROJECT)
add_library(function2 INTERFACE)
else()
add_library(function2 INTERFACE IMPORTED GLOBAL)
endif()
add_library(function2::function2 ALIAS function2)
target_include_directories(function2
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_features(function2
INTERFACE
cxx_alias_templates
cxx_auto_type
cxx_constexpr
cxx_decltype
cxx_decltype_auto
cxx_final
cxx_lambdas
cxx_lambda_init_captures
cxx_generic_lambdas
cxx_variadic_templates
cxx_defaulted_functions
cxx_nullptr
cxx_trailing_return_types
cxx_return_type_deduction)
if (FU2_IS_TOP_LEVEL_PROJECT)
include(ExternalProject)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
# Create an install target:
# Headers and license files
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/function2"
DESTINATION "include")
install(FILES "LICENSE.txt" DESTINATION .)
install(FILES "Readme.md" DESTINATION .)
# Config.cmake
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
# ConfigVersion.cmake
configure_package_config_file("cmake/config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
# PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
# Targets.cmake
export(TARGETS ${PROJECT_NAME}
NAMESPACE ${PROJECT_NAME}::
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
install(TARGETS ${PROJECT_NAME}
EXPORT "${PROJECT_NAME}Targets"
INCLUDES DESTINATION "include")
install(EXPORT "${PROJECT_NAME}Targets"
NAMESPACE ${PROJECT_NAME}::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
# Setup CPack for bundling
set(CPACK_GENERATOR "ZIP")
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
# Since the header only library is platform independent
# we name the packages after the native line feed
if(WIN32)
set(CPACK_SYSTEM_NAME "crlf")
else()
set(CPACK_SYSTEM_NAME "lf")
endif()
include(CPack)
if (MSVC)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-")
endif()
enable_testing()
option(FU2_WITH_NO_EXCEPTIONS
"Test without exceptions"
OFF)
option(FU2_WITH_NO_DEATH_TESTS
"Test without death tests"
OFF)
option(FU2_WITH_CPP_LATEST
"Enable the highest C++ standard available for testing polyfills"
OFF)
if (FU2_WITH_NO_EXCEPTIONS)
message(STATUS "Testing with exceptions disabled")
add_definitions(-DTESTS_NO_EXCEPTIONS)
endif()
if (FU2_WITH_NO_DEATH_TESTS)
message(STATUS "Testing without death tests")
add_definitions(-DTESTS_NO_DEATH_TESTS)
endif()
include(cmake/CMakeLists.txt)
add_subdirectory(test)
endif ()