-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
141 lines (122 loc) · 4.3 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
# SPDX-FileCopyrightText: 2024 Johann Klähn <[email protected]>
#
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.20.0)
file(STRINGS "src/tool.cpp" PROJECT_VERSION REGEX "^#define GENPYBIND_VERSION_STRING \"[0-9.]+")
# CMake only supports integer components in version numbers, so ignore any suffix.
string(REGEX MATCH "[0-9]+(\\.[0-9])*" PROJECT_VERSION ${PROJECT_VERSION})
project(genpybind LANGUAGES C CXX VERSION ${PROJECT_VERSION})
message(STATUS "Configuring ${PROJECT_NAME} version ${PROJECT_VERSION}")
set(CMAKE_EXPORT_COMPILE_COMMANDS YES)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
option(ENABLE_ASSERTIONS "Enable assertions" ON)
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
if(ENABLE_ASSERTIONS AND NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
add_definitions(-UNDEBUG)
endif()
add_compile_options(
-Wall -Wextra -Wconversion -pedantic -pedantic-errors
)
find_package(Clang REQUIRED HINTS "/usr/lib64/cmake/clang")
message(STATUS "Found Clang ${Clang_VERSION}; using ClangConfig.cmake in: ${Clang_DIR}")
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}; using LLVMConfig.cmake in: ${LLVM_DIR}")
include(${Clang_DIR}/AddClang.cmake)
include(${LLVM_DIR}/AddLLVM.cmake)
find_program(IWYU_PATH NAMES include-what-you-use iwyu)
if(NOT IWYU_PATH STREQUAL "IWYU_PATH-NOTFOUND")
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
${IWYU_PATH}
-Xiwyu --mapping_file=${CMAKE_CURRENT_SOURCE_DIR}/.iwyu-mapping-file.yaml
-Xiwyu --transitive_includes_only
-Xiwyu --quoted_includes_first
-resource-dir=${LLVM_LIBRARY_DIR}/clang/${Clang_VERSION}
)
endif()
add_library(genpybind-impl STATIC
src/annotated_decl.cpp
src/annotations/annotation.cpp
src/annotations/literal_value.cpp
src/annotations/parser.cpp
src/decl_context_graph.cpp
src/decl_context_graph_builder.cpp
src/decl_context_graph_processing.cpp
src/diagnostics.cpp
src/expose.cpp
src/inspect_graph.cpp
src/instantiate_annotated_templates.cpp
src/instantiate_default_arguments.cpp
src/lookup_context_collector.cpp
src/pragmas.cpp
src/sort_decls.cpp
src/string_utils.cpp
src/visible_decls.cpp
)
# Use same compiler flags as LLVM.
llvm_update_compile_flags(genpybind-impl)
# Link against libLLVM.so, if available.
if(LLVM_LINK_LLVM_DYLIB)
set(llvm_libs LLVM)
else()
llvm_map_components_to_libnames(llvm_libs support)
endif()
target_link_libraries(genpybind-impl PUBLIC ${llvm_libs})
clang_target_link_libraries(genpybind-impl PUBLIC clangTooling)
target_include_directories(genpybind-impl
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
target_include_directories(genpybind-impl
SYSTEM PUBLIC ${LLVM_INCLUDE_DIRS} ${CLANG_INCLUDE_DIRS}
)
target_compile_definitions(genpybind-impl
PUBLIC LLVM_VERSION_MAJOR=${LLVM_VERSION_MAJOR}
)
add_executable(genpybind-tool src/tool.cpp)
add_executable(genpybind::genpybind-tool ALIAS genpybind-tool)
llvm_update_compile_flags(genpybind-tool)
target_link_libraries(genpybind-tool PRIVATE genpybind-impl)
install(TARGETS genpybind-tool
EXPORT genpybindTargets
RUNTIME
)
add_library(genpybind INTERFACE)
add_library(genpybind::genpybind ALIAS genpybind)
target_include_directories(genpybind
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/public>
INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
install(
TARGETS genpybind
EXPORT genpybindTargets
)
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/public/genpybind
TYPE INCLUDE
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
tools/genpybindConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/genpybindConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/genpybind)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/genpybindConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(
EXPORT genpybindTargets
FILE genpybindTargets.cmake
NAMESPACE genpybind::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/genpybind
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/genpybindConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/genpybindConfigVersion.cmake"
tools/genpybind.cmake
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/genpybind")
include("tools/genpybind.cmake")
add_custom_target(test)
add_subdirectory(tests)