CMakeLists.txt (1336B)
1 2 cmake_minimum_required(VERSION 3.10) 3 4 # Set project name 5 project(DecisionTreeClassifier) 6 7 # Set C++ standard 8 set(CMAKE_CXX_STANDARD 17) 9 10 # Find Python and Pybind11 11 find_package(Python3 REQUIRED COMPONENTS Interpreter Development) 12 find_package(pybind11 REQUIRED) 13 14 # Ensure optimization flag is applied for Release builds (you could also manually override Debug builds) 15 if(CMAKE_BUILD_TYPE STREQUAL "Release") 16 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -Wall -fPIC") 17 else() 18 # Optionally you can set optimizations differently for Debug builds 19 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O3 -Wall -fPIC") 20 endif() 21 22 # Add source files 23 set(SOURCES 24 cpp/DecisionTreeClassifier.cpp 25 cpp/TreeNode.cpp 26 cpp/Criterion.cpp 27 cpp/bindings.cpp 28 ) 29 30 # Create the shared library 31 add_library(decision_tree MODULE ${SOURCES}) 32 33 # Link with Python and Pybind11 34 target_include_directories(decision_tree PRIVATE ${Python3_INCLUDE_DIRS}) 35 target_link_libraries(decision_tree PRIVATE ${Python3_LIBRARIES} pybind11::module) 36 37 # Set output name based on Python extension suffix 38 set_target_properties(decision_tree PROPERTIES 39 PREFIX "" 40 SUFFIX ".so" 41 ) 42 43 # Rename the custom clean target to avoid conflict 44 add_custom_target(clean_build 45 COMMAND rm -f ${CMAKE_BINARY_DIR}/*.o 46 COMMENT "Clean build files" 47 ) 48