-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
58 lines (52 loc) · 2.42 KB
/
CMakeLists.txt
File metadata and controls
58 lines (52 loc) · 2.42 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
cmake_minimum_required(VERSION 3.10)
project(MultiNEAT)
# Set the C++ standard to 17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Include the project "src" directory for headers
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
# --- Build the executable target using main.cpp ---
# Get all .cpp files in src directory
file(GLOB EXE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
# Exclude any file containing "bindings" (so main.cpp and the rest are included)
list(FILTER EXE_SOURCES EXCLUDE REGEX "src/.*Bindings.*\\.cpp")
# Add executable target
add_executable(multineat_exe ${EXE_SOURCES})
target_include_directories(multineat_exe PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
add_definitions(-UNDEBUG)
find_package(Python3 REQUIRED COMPONENTS Interpreter Development Development.Module)
include_directories(
${Python3_INCLUDE_DIRS}
${pybind11_INCLUDE_DIRS}
)
# Find pybind11 through Python's site-packages
execute_process(
COMMAND ${Python3_EXECUTABLE} -c "import pybind11; print(pybind11.get_cmake_dir())"
OUTPUT_VARIABLE pybind11_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
find_package(pybind11 REQUIRED CONFIG)
message(STATUS "Found pybind11 v${pybind11_VERSION}")
include_directories(${pybind11_INCLUDE_DIRS})
# --- Build the Python module target (shared library) using pybind11 ---
# For the Python module we want everything except main.cpp.
# First, get all .cpp files in src (recursively if needed)
file(GLOB_RECURSE PY_ALL "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
# Exclude main.cpp from the Python module; we also exclude any extra binding files from this group (we add them separately)
list(FILTER PY_ALL EXCLUDE REGEX "src/.*Main\\.cpp")
list(FILTER PY_ALL EXCLUDE REGEX "src/.*Bindings.*\\.cpp")
# Now specify the bindings file (assumed to be src/bindings.cpp) and combine with the rest.
set(PY_MODULE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/Bindings.cpp" ${PY_ALL})
# Use pybind11 to create a MODULE target called pymultineat. (Python will load a shared-library named 'pymultineat')
pybind11_add_module(pymultineat MODULE ${PY_MODULE_SOURCES})
target_include_directories(pymultineat PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${Python3_INCLUDE_DIRS}
${pybind11_INCLUDE_DIRS}
)
target_link_libraries(pymultineat PRIVATE ${Python3_LIBRARIES})
set_target_properties(pymultineat PROPERTIES
INTERPROCEDURAL_OPTIMIZATION ON
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
)