-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
104 lines (88 loc) · 2.39 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
cmake_minimum_required(VERSION 3.18...3.22)
project(
python-qalculate
LANGUAGES CXX
VERSION 0.0.1
)
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/BuildWheel.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/Qalculate.cmake")
find_package(
Python 3.6
COMPONENTS Interpreter Development.Module
REQUIRED
)
find_package(pybind11 CONFIG REQUIRED)
file(GLOB GENERATOR_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/generate/*.py")
list(APPEND GENERATOR_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/types.pyi")
set(GENERATED_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
set(REGENERATE OFF)
foreach(SOURCE_FILE ${GENERATOR_SOURCES})
if("${SOURCE_FILE}" IS_NEWER_THAN "${CMAKE_CURRENT_BINARY_DIR}/generated-timestamp")
set(REGENERATE ON)
break()
endif()
endforeach()
if(${REGENERATE})
execute_process(
COMMAND
python3 -m generate
"${LIBQALCULATE_RESOLVED_PATH}"
"${GENERATED_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/qalculate.pyi"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND_ERROR_IS_FATAL ANY
)
file(TOUCH "${CMAKE_CURRENT_BINARY_DIR}/generated-timestamp")
endif()
file(GLOB_RECURSE SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc" "${GENERATED_SOURCE_DIR}/*.cc")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
pybind11_add_module(
python-qalculate
${SOURCES}
)
target_compile_options(
python-qalculate
PRIVATE
-Wall -Wextra -pedantic
)
target_link_libraries(
python-qalculate
PRIVATE
libqalculate
)
target_include_directories(
python-qalculate
PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/src"
"${GENERATED_SOURCE_DIR}"
)
set_target_properties(
python-qalculate
PROPERTIES
OUTPUT_NAME qalculate
)
set(
USE_PYBIND11_STUBGEN FALSE
CACHE BOOL
"Whether to generate stubs using pybind11-stubgen or use custom autogenerated stubs (incomplete)"
)
if(USE_PYBIND11_STUBGEN)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/qalculate.pyi"
COMMAND
"${CMAKE_COMMAND}" -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}:$ENV{PYTHONPATH}"
pybind11-stubgen -o "${CMAKE_CURRENT_BINARY_DIR}" qalculate --enum-class-locations ".*:qalculate"
DEPENDS python-qalculate
COMMENT "Generating qalculate.pyi with pybind11-stubgen"
VERBATIM
)
add_custom_target(
"python-qalculate-stubs" ALL
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/qalculate.pyi"
)
endif()
build_binary_wheel(
TARGET python-qalculate
STUBS "${CMAKE_CURRENT_BINARY_DIR}/qalculate.pyi"
)