-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
66 lines (57 loc) · 1.74 KB
/
CMakeLists.txt
File metadata and controls
66 lines (57 loc) · 1.74 KB
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
cmake_minimum_required(VERSION 3.16)
if (NOT BUILD_SHARED_LIBS)
message(FATAL_ERROR "Cannot build Python bindings with a static lib build: "
"set BUILD_SHARED_LIBS to ON.")
endif()
# Since the Python libs and standalone Flashlight Text libs are built/installed
# to the same directory, set rpaths on the Python targets to be the current dir
if(APPLE)
# macOS
set(CMAKE_MACOSX_RPATH ON)
set(_portable_rpath_origin "@loader_path")
else()
# Linux
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
set(_portable_rpath_origin $ORIGIN)
endif(APPLE)
find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module)
find_package(pybind11 CONFIG)
if (NOT pybind11_FOUND)
message(STATUS "Could not find pybind11 -- downloading from source.")
include(${PROJECT_SOURCE_DIR}/cmake/Buildpybind11.cmake)
endif()
function (add_pybind11_extension ext_name)
string(REPLACE "_" ";" modlist ${ext_name})
list(GET modlist -1 modname)
list(REMOVE_AT modlist -1)
if(modlist)
string(REPLACE ";" "/" relpath "${modlist}")
else()
set(relpath "")
endif()
pybind11_add_module(
${ext_name}
${CMAKE_CURRENT_LIST_DIR}/${relpath}/_${modname}.cpp
)
target_link_libraries(
${ext_name}
PUBLIC
flashlight-sequence
)
target_include_directories(
${ext_name}
PRIVATE
${PROJECT_SOURCE_DIR}
)
if (FL_SEQUENCE_BUILD_PYTHON_PACKAGE)
set_target_properties(${ext_name} PROPERTIES
OUTPUT_NAME ${ext_name}
BUILD_RPATH ${_portable_rpath_origin})
else()
if (CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set_target_properties(${ext_name} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${relpath})
endif()
endif()
endfunction ()
add_pybind11_extension(flashlight_lib_sequence_criterion)