forked from dmikushin/res_embed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
121 lines (94 loc) · 4.1 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
cmake_minimum_required(VERSION 3.17 FATAL_ERROR) # CMAKE_CURRENT_FUNCTION_LIST_DIR
project(
res_embed
VERSION 1.0.0
LANGUAGES C CXX)
option(BUILD_SHARED_LIBS
"Build and use shared library for ${PROJECT_NAME} (default: OFF)" OFF)
option(BUILD_EXAMPLE "Build the examples (default: ON)" ON)
if(NOT DEFINED ITERATOR_DEBUG_VALUE)
set(ITERATOR_DEBUG_VALUE 0)
endif()
option(MSVC_ITERATOR_DEBUG "Define _ITERATOR_DEBUG_LEVEL (defaults to 0, can be set using ITERATOR_DEBUG_VALUE)" OFF)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(ResEmbed)
# Only modify the parent's CMAKE_MODULE_PATH if it exists
get_directory_property(has_parent PARENT_DIRECTORY)
if(has_parent)
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
PARENT_SCOPE)
endif()
# ------------------------------------------------------------------------------
include(GNUInstallDirs)
set(RE_INSTALL_BINDIR "${CMAKE_INSTALL_BINDIR}")
set(RE_INSTALL_SBINDIR "${CMAKE_INSTALL_SBINDIR}")
set(RE_INSTALL_SYSCONFDIR "${CMAKE_INSTALL_SYSCONFDIR}")
set(RE_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}")
set(RE_INSTALL_DATADIR "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}")
set(RE_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}")
set(RE_INSTALL_DOCDIR "${CMAKE_INSTALL_DATADIR}/doc/${PROJECT_NAME}")
set(RE_INSTALL_CMAKEDIR "${RE_INSTALL_DATADIR}/cmake")
set(RE_INSTALL_3RDPARTYDIR "${RE_INSTALL_LIBDIR}/third_party")
# ==============================================================================
if(BUILD_SHARED_LIBS)
set(_tgt_name ${PROJECT_NAME})
set(_alias_name res::embed)
set(_tgt_defines)
else()
set(_tgt_name ${PROJECT_NAME}_static)
set(_alias_name res::embed::static)
set(_tgt_defines ${PROJECT_NAME}_STATIC)
endif()
if(NOT TARGET ${_tgt_name})
add_library(${_tgt_name} ${CMAKE_CURRENT_SOURCE_DIR}/src/${PROJECT_NAME}.cpp)
target_compile_features(${_tgt_name} PUBLIC cxx_std_11)
set_property(TARGET ${_tgt_name} PROPERTY POSITION_INDEPENDENT_CODE ON)
target_compile_definitions(${_tgt_name} PUBLIC ${_tgt_defines})
target_include_directories(
${_tgt_name} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${RE_INSTALL_INCLUDEDIR}>)
add_library(${_alias_name} ALIAS ${_tgt_name})
if(MSVC AND MSVC_ITERATOR_DEBUG)
target_compile_definitions(${_tgt_name} PUBLIC _ITERATOR_DEBUG=${ITERATOR_DEBUG_VALUE})
endif()
endif()
# ==============================================================================
include(CMakePackageConfigHelpers)
set(_namespace ${PROJECT_NAME}::)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${RE_INSTALL_CMAKEDIR})
write_basic_package_version_file(
${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
COMPATIBILITY SameMajorVersion)
install(FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${RE_INSTALL_CMAKEDIR})
install(DIRECTORY ${PROJECT_SOURCE_DIR}/cmake
DESTINATION ${RE_INSTALL_CMAKEDIR})
install(
FILES ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}.cpp.in
${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}.gas.in
${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}.h
${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}.nasm.in
DESTINATION ${RE_INSTALL_INCLUDEDIR})
# ==============================================================================
if(BUILD_EXAMPLE)
add_subdirectory(example)
endif()
# ==============================================================================
install(
TARGETS ${_tgt_name}
EXPORT ${PROJECT_NAME}Targets
PRIVATE_HEADER DESTINATION ${RE_INSTALL_INCLUDEDIR}
PUBLIC_HEADER DESTINATION ${RE_INSTALL_INCLUDEDIR}
ARCHIVE DESTINATION ${RE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${RE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${RE_INSTALL_BINDIR})
install(
EXPORT ${PROJECT_NAME}Targets
NAMESPACE ${_namespace}
DESTINATION ${RE_INSTALL_CMAKEDIR})
# ==============================================================================