-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
89 lines (75 loc) · 3.41 KB
/
CMakeLists.txt
File metadata and controls
89 lines (75 loc) · 3.41 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
cmake_minimum_required(VERSION 3.14)
project(Chess)
cmake_policy(SET CMP0135 NEW)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# ==========================================
# RÉCUPÉRATION DE ONNX RUNTIME (C++)
# ==========================================
set(ONNXRUNTIME_VERSION "1.24.3")
set(ONNXRUNTIME_URL "https://github.com/microsoft/onnxruntime/releases/download/v${ONNXRUNTIME_VERSION}/onnxruntime-win-x64-${ONNXRUNTIME_VERSION}.zip")
include(FetchContent)
FetchContent_Declare(
onnxruntime
URL ${ONNXRUNTIME_URL}
)
FetchContent_MakeAvailable(onnxruntime)
# Extraction des chemins vers les dossiers de l'archive téléchargée
FetchContent_GetProperties(onnxruntime SOURCE_DIR onnxruntime_src)
set(ONNXRUNTIME_INCLUDE_DIR "${onnxruntime_src}/include")
set(ONNXRUNTIME_LIB "${onnxruntime_src}/lib/onnxruntime.lib")
set(ONNXRUNTIME_DLL "${onnxruntime_src}/lib/onnxruntime.dll")
# ==========================================
# 1. Création de la librairie core
# ==========================================
add_library(chess_core STATIC
src/chessboard.cpp
src/square.cpp
src/piece.cpp
src/move.cpp
src/pgn_parser.cpp
src/mcts.cpp
src/zobrist.cpp)
# On indique au compilateur où chercher les headers locaux ET ceux de ONNX Runtime
target_include_directories(chess_core PUBLIC src ${ONNXRUNTIME_INCLUDE_DIR})
# On lie la librairie ONNX Runtime
target_link_libraries(chess_core PUBLIC ${ONNXRUNTIME_LIB})
# ==========================================
# 2. Exécutable de test (C++ pur)
# ==========================================
add_executable(chess_tests src/main.cpp)
target_link_libraries(chess_tests PRIVATE chess_core)
# ==========================================
# 3. Configuration Python & Pybind11
# ==========================================
find_package(Python3 3.11 COMPONENTS Interpreter Development REQUIRED)
# Transmet dynamiquement la version trouvée à Pybind11
set(PYBIND11_PYTHON_VERSION ${Python3_VERSION} CACHE STRING "Version Python pour pybind11" FORCE)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v2.11.1
)
FetchContent_MakeAvailable(pybind11)
# ==========================================
# 4. Création du module Python
# ==========================================
pybind11_add_module(chess_engine src/bindings.cpp)
target_link_libraries(chess_engine PRIVATE chess_core)
# Génération des stubs ET copie de la DLL ONNX
add_custom_command(TARGET chess_engine POST_BUILD
# Copie de la DLL nécessaire à l'exécution
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${ONNXRUNTIME_DLL}
${CMAKE_SOURCE_DIR}/python_src/onnxruntime.dll
# Génération des stubs (.pyi) en utilisant l'exécutable Python trouvé dynamiquement
COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_SOURCE_DIR}/python_src"
${Python3_EXECUTABLE} -m pybind11_stubgen chess_engine
--enum-class-locations "PieceType:chess_engine"
--output-dir "${CMAKE_SOURCE_DIR}/python_src"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/python_src"
COMMENT "Copie de onnxruntime.dll et génération des stubs..."
)
# Force CMake à exporter le module compilé dans le dossier python_src/
set_target_properties(chess_engine PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/python_src)
set_target_properties(chess_engine PROPERTIES LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_SOURCE_DIR}/python_src)