-
Notifications
You must be signed in to change notification settings - Fork 0
/
ngsolve_addon.cmake
62 lines (52 loc) · 2.79 KB
/
ngsolve_addon.cmake
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
###############################################################################
# This file was taken from https://github.com/NGSolve/ngsolve-addon-template
# Make sure to check for updates regularly.
# Don't change anything here (unless you know what you are doing!)
###############################################################################
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Find NGSolve and Netgen using python
if(CMAKE_VERSION VERSION_LESS "3.18")
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
else()
find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module)
endif()
set(Netgen_DIR "" CACHE PATH "Path to directory containing NetgenConfig.cmake")
set(NGSolve_DIR "" CACHE PATH "Path to directory containing NGSolveConfig.cmake")
execute_process(COMMAND ${Python3_EXECUTABLE} -m netgen.config OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE Netgen_DIR)
execute_process(COMMAND ${Python3_EXECUTABLE} -m ngsolve.config OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE NGSolve_DIR)
find_package(NGSolve CONFIG REQUIRED)
macro(add_ngsolve_addon module_name)
# Create the module
add_library(${module_name} SHARED ${ARGN})
target_link_libraries(${module_name} PUBLIC ngsolve Python3::Module)
set_target_properties(${module_name} PROPERTIES PREFIX "" CXX_STANDARD 17)
# Python does not recognize .dll (Windows) and .dylib (MacOS) file endings as modules
if(WIN32)
set_target_properties(${module_name} PROPERTIES SUFFIX ".pyd" )
else(WIN32)
set_target_properties(${module_name} PROPERTIES SUFFIX ".so")
endif(WIN32)
endmacro()
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
# Set install prefix to user-site if a user site is available, platlib otherwise
execute_process(COMMAND ${Python3_EXECUTABLE} -m site --user-site
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE user_site RESULT_VARIABLE ret
)
if (ret EQUAL 0)
set(CMAKE_INSTALL_PREFIX ${user_site} CACHE PATH "Install dir" FORCE)
else()
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_path('platlib'))"
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE install_prefix
)
set(CMAKE_INSTALL_PREFIX ${install_prefix} CACHE PATH "Install dir" FORCE)
endif()
set(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OFF)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
if(SKBUILD_PLATLIB_DIR)
set(stubgen_working_dir ${SKBUILD_PLATLIB_DIR})
else()
set(stubgen_working_dir ${CMAKE_INSTALL_PREFIX})
endif()
set(stubgen_generation_code "execute_process(WORKING_DIRECTORY ${stubgen_working_dir} COMMAND ${Python3_EXECUTABLE} -m pybind11_stubgen --ignore-all-errors -o ${CMAKE_CURRENT_BINARY_DIR}/stubs ${addon_name})")
set(stubgen_directory "${CMAKE_CURRENT_BINARY_DIR}/stubs/${addon_name}/")
message(STATUS "Install dir: ${CMAKE_INSTALL_PREFIX}")