-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
93 lines (75 loc) · 3.35 KB
/
CMakeLists.txt
File metadata and controls
93 lines (75 loc) · 3.35 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
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
# Copyright (C) 2022 Alexander Wentz
cmake_minimum_required(VERSION 3.4...3.18)
project(interface_cpp)
find_package(Python3 COMPONENTS Interpreter Development)
set(VENV ${CMAKE_CURRENT_LIST_DIR}/venv)
set(BIN_DIR ${VENV}/bin)
set(PYTHON ${BIN_DIR}/python)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
execute_process (COMMAND "${Python3_EXECUTABLE}" -m venv "${VENV}")
# Trick to use python from the new venv
## update the environment with VIRTUAL_ENV variable (mimic the activate script)
set (ENV{VIRTUAL_ENV} "${VENV}")
## change the context of the search
set (Python3_FIND_VIRTUALENV FIRST)
## unset Python3_EXECUTABLE because it is also an input variable (see documentation, Artifacts Specification section)
unset (Python3_EXECUTABLE)
## Launch a new search
find_package(Python3 COMPONENTS Interpreter Development)
# TODO maybe: pip install --upgrade pip
execute_process (COMMAND "${Python3_EXECUTABLE}" -m pip install -r "${CMAKE_CURRENT_LIST_DIR}/requirements.txt")
# build and install the python abstract interface
execute_process(
COMMAND "${Python3_EXECUTABLE}" -m build "${CMAKE_CURRENT_LIST_DIR}/pyinterface"
--wheel --no-isolation -o "${CMAKE_BINARY_DIR}/dist"
)
execute_process (COMMAND "${Python3_EXECUTABLE}" -m pip install "${CMAKE_BINARY_DIR}/dist/pyinterface-0.1.0-py3-none-any.whl" --force-reinstall)
# build and install the first python example
execute_process(
COMMAND "${Python3_EXECUTABLE}" -m build "${CMAKE_CURRENT_LIST_DIR}/pyderived"
--wheel --no-isolation -o "${CMAKE_BINARY_DIR}/dist"
)
execute_process (COMMAND "${Python3_EXECUTABLE}" -m pip install "${CMAKE_BINARY_DIR}/dist/pyderived-0.1.0-py3-none-any.whl" --force-reinstall)
# add_custom_command(
# OUTPUT ${VENV}
# COMMAND ${Python3_EXECUTABLE} -m venv ${VENV}
# COMMAND ${BIN_DIR}/pip install -r ${REQUIREMENTS}
# COMMAND ${BIN_DIR}/pip freeze > ${VENV}/environment.txt
# DEPENDS ${REQUIREMENTS}
# )
#
# add_custom_target(venv DEPENDS ${PYTHON})
find_package(pybind11 CONFIG)
# Create an shared lib to link against other executables / libs
add_library(interfaceCPPcpp SHARED src/base.cpp src/base.h src/interface.cpp)
target_link_libraries(interfaceCPPcpp PUBLIC pybind11::module)
target_compile_definitions(
interfaceCPPcpp
PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO}
)
# create an target for python
pybind11_add_module(interfaceCPP src/base.cpp src/base.h src/interface.cpp)
set_target_properties( interfaceCPP
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${VENV}/lib/python3.10/site-packages/interfaceCPP"
)
target_compile_definitions(
interfaceCPP
PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO}
)
#add the example library
pybind11_add_module(derivedExample STATIC src/derived.cpp src/derived.h)
target_link_libraries(derivedExample PUBLIC interfaceCPPcpp)
# define (VERSION_INFO) here.
target_compile_definitions(
derivedExample
PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO}
)
add_executable(myexe src/myexec.cpp)
target_link_libraries(myexe derivedExample)
#TODO create an executable and to use the example library
# Make substitution based on "@" marked strings
# set(INTERFACE_INSTALL_PATH ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
# install(FILES interfaceCPP DESTINATION ${INTERFACE_INSTALL_PATH})
# Configure 'sys.path' in pybase.py, so it may find interfaceCPP.
# configure_file("scripts/pyinterface/pybase.py" "scripts/pyinterface/pybase.py" @ONLY)