-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCMakeLists.txt
62 lines (48 loc) · 1.92 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
cmake_minimum_required(VERSION 3.1)
option(SCOPE_EXIT_BUILD_SAMPLES "Build scope exit's samples." ON)
project(ScopeExit VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# make sure install paths work on all platforms
if(NOT CMAKE_INSTALL_INCLUDEDIR)
include(GNUInstallDirs)
endif()
add_library(ScopeExit INTERFACE)
target_include_directories(ScopeExit
INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
add_library(ScopeExit::ScopeExit ALIAS ScopeExit)
# workaround for stand-alone build detection under windows (as it's case insensitive)
get_filename_component(CURRENT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} ABSOLUTE)
get_filename_component(SOURCE_DIR ${CMAKE_SOURCE_DIR} ABSOLUTE)
# check if building as a stand-alone project
if(${CURRENT_SOURCE_DIR} STREQUAL ${SOURCE_DIR} AND SCOPE_EXIT_BUILD_SAMPLES)
# add a pseudo-project to make project headers visible in IDE
file(GLOB_RECURSE SCOPE_EXIT_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
add_library(ScopeExit-h STATIC ${SCOPE_EXIT_HEADERS})
set_target_properties(ScopeExit-h PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(ScopeExit-h PROPERTIES FOLDER Include)
add_subdirectory(samples)
endif()
install(TARGETS ScopeExit EXPORT ScopeExitConfig)
install(
EXPORT ScopeExitConfig
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ScopeExit
NAMESPACE ScopeExit::
)
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ScopeExit
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h" # headers only
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/ScopeExitConfigVersion.cmake"
COMPATIBILITY AnyNewerVersion
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/ScopeExitConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ScopeExit
)