-
Notifications
You must be signed in to change notification settings - Fork 445
/
CMakeLists.txt
162 lines (139 loc) · 5.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
cmake_minimum_required(VERSION 3.14)
project(
magic_enum
VERSION "0.9.7"
HOMEPAGE_URL "https://github.com/Neargye/magic_enum"
DESCRIPTION
"A library that provides static reflection for enums, work with any enum type without any macro or boilerplate code."
LANGUAGES CXX
)
set(CPACK_PACKAGE_VENDOR "Daniil Goncharov")
include(GNUInstallDirs)
set(ADDITIONAL_MODULES_DIR "${CMAKE_CURRENT_LIST_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${ADDITIONAL_MODULES_DIR}")
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(IS_TOPLEVEL_PROJECT TRUE)
else()
set(IS_TOPLEVEL_PROJECT FALSE)
endif()
option(MAGIC_ENUM_OPT_BUILD_EXAMPLES "Build magic_enum examples" ${IS_TOPLEVEL_PROJECT})
option(MAGIC_ENUM_OPT_BUILD_TESTS "Build and perform magic_enum tests" ${IS_TOPLEVEL_PROJECT})
option(MAGIC_ENUM_OPT_INSTALL "Generate and install magic_enum target" ${IS_TOPLEVEL_PROJECT})
option(MAGIC_ENUM_OPT_INSTALL_PACKAGE_XML "Include package.xml when installing"
${MAGIC_ENUM_OPT_INSTALL}
)
option(MAGIC_ENUM_OPT_TEST_INSTALLED_VERSION "When configuring tests, try use
a local magic_enum." NO
)
option(MAGIC_ENUM_OPT_TEST_INSTALLED_VERSION_PKGCONFIG "When configuring tests, try use
a local magic_enum via pkgconfig" NO
)
if(${MAGIC_ENUM_OPT_TEST_INSTALLED_VERSION} OR ${MAGIC_ENUM_OPT_TEST_INSTALLED_VERSION_PKGCONFIG})
add_subdirectory(test)
return()
endif()
set(INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/include/magic_enum")
set(EXPORT_NAMESPACE "${PROJECT_NAME}::")
add_library(${PROJECT_NAME} INTERFACE)
add_library(${EXPORT_NAMESPACE}${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_include_directories(
${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
if(MAGIC_ENUM_OPT_BUILD_EXAMPLES)
add_subdirectory(example)
endif()
if(MAGIC_ENUM_OPT_BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()
if(MAGIC_ENUM_OPT_INSTALL)
list(APPEND CMAKE_MODULE_PATH "${ADDITIONAL_MODULES_DIR}/GenPkgConfig")
include(GenPkgConfig)
include(CPackComponent)
include(CMakePackageConfigHelpers)
install(
TARGETS "${PROJECT_NAME}"
EXPORT ${PROJECT_NAME}
INCLUDES
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
# COMPONENT "${SDK_COMPONENT_NAME}" # component is not allowed for
# includes!
# Headers are installed separately! Includes only marks the headers for
# export
)
if(NOT DEFINED PROJECT_INCLUDE_HEADER_PATTERN)
set(PROJECT_INCLUDE_HEADER_PATTERN "*")
endif()
install(
DIRECTORY ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING
PATTERN "${PROJECT_INCLUDE_HEADER_PATTERN}"
)
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "all")
set(CPACK_DEBIAN_PACKAGE_NAME "libmagicenum-dev")
set(CPACK_RPM_PACKAGE_NAME "libmagicenum-devel")
set(CPACK_PACKAGE_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}")
set(CPACK_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_MAINTAINER}")
set(CPACK_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_NSIS_COMPONENT_INSTALL ON)
set(CPACK_DEBIAN_COMPRESSION_TYPE "xz")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CMAKE_CONFIG_FILE_BASENAME "${PROJECT_NAME}Config.cmake")
set(CMAKE_EXPORT_FILE_BASENAME "${PROJECT_NAME}Export.cmake")
set(CMAKE_CONFIG_VERSION_FILE_BASENAME "${PROJECT_NAME}ConfigVersion.cmake")
set(CMAKE_CONFIG_VERSION_FILE_NAME
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CONFIG_VERSION_FILE_BASENAME}"
)
export(
TARGETS "${PROJECT_NAME}"
NAMESPACE "${EXPORT_NAMESPACE}"
FILE "${CMAKE_EXPORT_FILE_BASENAME}"
EXPORT_LINK_INTERFACE_LIBRARIES
)
install(
EXPORT "${PROJECT_NAME}"
FILE "${CMAKE_CONFIG_FILE_BASENAME}"
NAMESPACE "${EXPORT_NAMESPACE}"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}"
)
write_basic_package_version_file(
"${CMAKE_CONFIG_VERSION_FILE_NAME}"
# VERSION "100500.100500.100500" # any version of same bitness suits. CMake cannot compare to
# infinity, so use a large number we expect to be greater than any future version
VERSION ${_VERSION}
COMPATIBILITY AnyNewerVersion ARCH_INDEPENDENT
)
install(FILES "${CMAKE_CONFIG_VERSION_FILE_NAME}"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}"
)
configure_pkg_config_file(
"${PROJECT_NAME}"
NAME
"${PROJECT_NAME}"
VERSION
"${PROJECT_VERSION}"
DESCRIPTION
"${CPACK_PACKAGE_DESCRIPTION}"
URL
"${CPACK_PACKAGE_HOMEPAGE_URL}"
INSTALL_LIB_DIR
"${CMAKE_INSTALL_DATAROOTDIR}"
INSTALL_INCLUDE_DIR
"${CMAKE_INSTALL_INCLUDEDIR}"
)
if(MAGIC_ENUM_OPT_INSTALL_PACKAGE_XML)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/package.xml
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}
)
endif()
include(CPack)
endif()