Skip to content

Commit

Permalink
cmake: find python using FindPython3
Browse files Browse the repository at this point in the history
  • Loading branch information
s95rob committed Oct 20, 2023
1 parent 73c2026 commit a991e50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
32 changes: 9 additions & 23 deletions CMake/Python.cmake
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
# Check if Python vars have been set in CLI

message(STATUS "Checking if Python paths have been set...")

if (NOT DEFINED PYTHON_INCLUDE_DIR)
message(FATAL_ERROR "Please provide Python include directory as CMake argument! Usage: -DPYTHON_INCLUDE_DIR=/path/to/python/include")
else()
message(STATUS "PYTHON_INCLUDE_DIR=${PYTHON_INCLUDE_DIR}")
endif()

if (NOT DEFINED PYTHON_LIB_DIR)
message(FATAL_ERROR "Please provide Python lib directory as CMake argument! Usage: -DPYTHON_LIB_DIR=/path/to/python/lib")
else()
message(STATUS "PYTHON_LIB_DIR=${PYTHON_LIB_DIR}")
endif()

if (NOT DEFINED PYTHON_LIB)
message(FATAL_ERROR "Please provide Python library as CMake argument! Usage -DPYTHON_LIB=python3.11")
else()
message(STATUS "PYTHON_LIB=${PYTHON_LIB}")
endif()

message(STATUS "Python OK!")
# Check if Python environment variables have been set

find_package(Python3 COMPONENTS Interpreter Development)

if (NOT DEFINED Python3_Development_FOUND)
message(FATAL_ERROR "Please make sure Python3 (including development artifacts) installed correctly on your system!")
else()
message(STATUS "Linking Python ${Python3_VERSION}")
endif()
9 changes: 3 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ set(BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(EXTERN_DIR ${ROOT_DIR}/Extern)
set(SCRIPTS_DIR ${ROOT_DIR}/CMake)
set(SAMPLE_PLUGINS_DIR ${ROOT_DIR}/Samples)
include("${SCRIPTS_DIR}/Python.cmake")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED true)

project(Source2Py LANGUAGES CXX)

include("${SCRIPTS_DIR}/Python.cmake")
include("${SCRIPTS_DIR}/Source2SDK.cmake")
include("${SCRIPTS_DIR}/Metamod.cmake")

Expand All @@ -25,15 +25,12 @@ target_include_directories(Source2Py PRIVATE
${SOURCE2SDK_INCLUDE_DIRS}
${METAMOD_INCLUDE_DIRS}
${EXTERN_DIR}/pybind11/include
${PYTHON_INCLUDE_DIR}
)
target_link_directories(Source2Py PRIVATE
${PYTHON_LIB_DIR}
${Python3_INCLUDE_DIRS}
)
target_link_libraries(Source2Py PRIVATE
Source2SDK
Metamod
${PYTHON_LIB}
${Python3_LIBRARIES}
)
set_target_properties(Source2Py PROPERTIES
OUTPUT_NAME "Source2Py"
Expand Down

0 comments on commit a991e50

Please sign in to comment.