-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
57 lines (48 loc) · 1.82 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
cmake_minimum_required(VERSION 3.17)
project(
mini
VERSION 1.3.0
LANGUAGES C CXX)
option(MINI_BUILD_TESTS "Build tests" OFF)
option(MINI_DEV_PYTHON_BUILD "Build nanobind in dev mode" OFF)
add_library(mini STATIC ${PROJECT_SOURCE_DIR}/src/mini.cc)
target_include_directories(
mini PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>)
target_compile_features(mini PRIVATE cxx_std_17)
set_target_properties(mini PROPERTIES POSITION_INDEPENDENT_CODE ON)
if(MINI_BUILD_TESTS)
include(${CMAKE_CURRENT_LIST_DIR}/test/Test.cmake)
endif()
if(MINI_DEV_PYTHON_BUILD OR SKBUILD)
if(SKBUILD)
message(STATUS "Python_VERSION ${PYTHON_VERSION_STRING}")
message(STATUS "Python_EXECUTABLE ${PYTHON_EXECUTABLE}")
message(STATUS "Python_INCLUDE_DIR ${PYTHON_INCLUDE_DIR}")
message(STATUS "Python_LIBRARIES ${PYTHON_LIBRARY}")
set(Python_VERSION "${PYTHON_VERSION_STRING}")
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
set(Python_INCLUDE_DIR "${PYTHON_INCLUDE_DIR}")
set(Python_LIBRARIES "${PYTHON_LIBRARY}")
endif()
find_package(Python COMPONENTS Interpreter Development)
if(MINI_DEV_PYTHON_BUILD)
include(FetchContent)
FetchContent_Declare(
nanobind
GIT_REPOSITORY https://github.com/wjakob/nanobind.git
GIT_TAG master)
FetchContent_MakeAvailable(nanobind)
else()
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c
"import nanobind; print(nanobind.cmake_dir())"
OUTPUT_VARIABLE _tmp_dir
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO STDOUT)
list(APPEND CMAKE_PREFIX_PATH "${_tmp_dir}")
# Now import nanobind from CMake
find_package(nanobind CONFIG REQUIRED)
endif()
nanobind_add_module(minipy_ext NB_STATIC src/bind.cc)
target_link_libraries(minipy_ext PRIVATE mini)
install(TARGETS minipy_ext LIBRARY DESTINATION .)
endif()