forked from kljohann/genpybind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
101 lines (83 loc) · 2.79 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
# SPDX-FileCopyrightText: 2024 Johann Klähn <[email protected]>
#
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.20.0)
project(genpybind LANGUAGES C CXX)
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(AddLLVM)
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}/genpybind.imp
-Xiwyu --transitive_includes_only
-Xiwyu --quoted_includes_first
-resource-dir=${LLVM_LIBRARY_DIR}/clang/${Clang_VERSION}
)
endif()
add_library(genpybind SHARED
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)
# 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 PUBLIC ${llvm_libs} clang-cpp)
target_include_directories(genpybind
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
# PUBLIC $<INSTALL_INTERFACE:...>
)
target_include_directories(genpybind
SYSTEM PUBLIC ${LLVM_INCLUDE_DIRS} ${CLANG_INCLUDE_DIRS}
)
target_compile_definitions(genpybind
PUBLIC LLVM_VERSION_MAJOR=${LLVM_VERSION_MAJOR}
)
add_executable(genpybind-tool
src/tool.cpp
)
llvm_update_compile_flags(genpybind-tool)
target_link_libraries(genpybind-tool PRIVATE genpybind)
add_subdirectory(extern/pybind11)
add_library(genpybind-runtime INTERFACE)
target_include_directories(genpybind-runtime
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/runtime>
# INTERFACE $<INSTALL_INTERFACE:...>
)
add_custom_target(test)
add_subdirectory(tests)