Skip to content

Commit

Permalink
Use FindPython from CMake 3.12.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoikas committed Jun 15, 2020
1 parent c8d23e7 commit 188d3f5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 61 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/linux-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ jobs:
python_ver: [2.7, 3.6]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python_ver }}

- name: Find Python Artifacts
id: python_artifacts
shell: python
run: |
from distutils.sysconfig import get_config_var
import sys
print("::set-env name:PYTHON_EXECUTABLE::{}".format(sys.executable))
print("::set-env name=PYTHON_LIB::{}/{}".format(get_config_var("LIBPL"), get_config_var("LIBRARY")))
print("::set-env name=PYTHON_INCLUDE::{}".format(get_config_var("INCLUDEPY")))
- name: Build string_theory
run: |
mkdir -p build_deps && cd build_deps
Expand All @@ -21,6 +35,6 @@ jobs:
run: |
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH="${GITHUB_WORKSPACE}/build_deps/prefix" \
-DPython_ADDITIONAL_VERSIONS=${{ matrix.python_ver }} -DENABLE_PYTHON=ON \
-DPython_EXECUTABLE=$PYTHON_EXECUTABLE -DPython_LIBRARY=$PYTHON_LIB -DPython_INCLUDE_DIR=$PYTHON_INCLUDE -DENABLE_PYTHON=ON \
-DENABLE_TOOLS=ON -DENABLE_NET=ON -DENABLE_PHYSX=OFF ..
make -j2
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.12)
project(libhsplasma)

set(CMAKE_CXX_STANDARD 14)
Expand Down
83 changes: 33 additions & 50 deletions Python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
find_package(PythonLibs REQUIRED)
# Use only the major.minor version -- no patch, no +, etc
STRING(REGEX REPLACE "([0-9]\\.[0-9])[0-9.+]*" "\\1" PYTHONLIBS_VERSION_STRING_FILTERED "${PYTHONLIBS_VERSION_STRING}")
find_package(PythonInterp "${PYTHONLIBS_VERSION_STRING_FILTERED}" REQUIRED)
# make sure the versions match
STRING(REGEX REPLACE "([0-9]\\.[0-9])[0-9.+]*" "\\1" PYTHON_VERSION_STRING_FILTERED "${PYTHON_VERSION_STRING}")
if (NOT "${PYTHONLIBS_VERSION_STRING_FILTERED}" STREQUAL "${PYTHON_VERSION_STRING_FILTERED}")
message(FATAL_ERROR "Versions of Python libraries (${PYTHONLIBS_VERSION_STRING_FILTERED}) and Python interpreter (${PYTHON_VERSION_STRING_FILTERED}) do not match. Please configure the paths manually.")
endif()
find_package(Python REQUIRED COMPONENTS Interpreter Development)

if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)
set(CMAKE_CXX_FLAGS "-fno-strict-aliasing ${CMAKE_CXX_FLAGS}")
Expand All @@ -23,7 +15,6 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
endif()

include_directories(${PROJECT_SOURCE_DIR}/core)
include_directories(${PYTHON_INCLUDE_DIRS})
include_directories(./)

set(DEBUG_SOURCES
Expand Down Expand Up @@ -719,55 +710,47 @@ set(PYTHON_HEADERS
PyPlasma.h
)

add_library(PyHSPlasma SHARED
${DEBUG_SOURCES} ${DEBUG_HEADERS}
${MATH_SOURCES} ${MATH_HEADERS}
${PRP_ANIM_SOURCES} ${PRP_ANIM_HEADERS}
${PRP_AUDIO_SOURCES} ${PRP_AUDIO_HEADERS}
${PRP_AVATAR_SOURCES} ${PRP_AVATAR_HEADERS}
${PRP_CAMERA_SOURCES} ${PRP_CAMERA_HEADERS}
${PRP_COND_SOURCES} ${PRP_COND_HEADERS}
${PRP_GEOM_SOURCES} ${PRP_GEOM_HEADERS}
${PRP_GUI_SOURCES} ${PRP_GUI_HEADERS}
${PRP_KEYOBJ_SOURCES} ${PRP_KEYOBJ_HEADERS}
${PRP_LIGHT_SOURCES} ${PRP_LIGHT_HEADERS}
${PRP_MSG_SOURCES} ${PRP_MSG_HEADERS}
${PRP_MISC_SOURCES} ${PRP_MISC_HEADERS}
${PRP_MOD_SOURCES} ${PRP_MOD_HEADERS}
${PRP_OBJ_SOURCES} ${PRP_OBJ_HEADERS}
${PRP_PARTICLE_SOURCES} ${PRP_PARTICLE_HEADERS}
${PRP_PHYS_SOURCES} ${PRP_PHYS_HEADERS}
${PRP_REGION_SOURCES} ${PRP_REGION_HEADERS}
${PRP_SURFACE_SOURCES} ${PRP_SURFACE_HEADERS}
${PRP_SOURCES} ${PRP_HEADERS}
${RESMGR_SOURCES} ${RESMGR_HEADERS}
${SDL_SOURCES} ${SDL_HEADERS}
${STREAM_SOURCES} ${STREAM_HEADERS}
${SYS_SOURCES} ${SYS_HEADERS}
${UTIL_SOURCES} ${UTIL_HEADERS}
${VAULT_SOURCES} ${VAULT_HEADERS}
${PYTHON_SOURCES} ${PYTHON_HEADERS}
)

target_link_libraries(PyHSPlasma HSPlasma ${PYTHON_LIBRARIES})
Python_add_library(PyHSPlasma MODULE
${DEBUG_SOURCES} ${DEBUG_HEADERS}
${MATH_SOURCES} ${MATH_HEADERS}
${PRP_ANIM_SOURCES} ${PRP_ANIM_HEADERS}
${PRP_AUDIO_SOURCES} ${PRP_AUDIO_HEADERS}
${PRP_AVATAR_SOURCES} ${PRP_AVATAR_HEADERS}
${PRP_CAMERA_SOURCES} ${PRP_CAMERA_HEADERS}
${PRP_COND_SOURCES} ${PRP_COND_HEADERS}
${PRP_GEOM_SOURCES} ${PRP_GEOM_HEADERS}
${PRP_GUI_SOURCES} ${PRP_GUI_HEADERS}
${PRP_KEYOBJ_SOURCES} ${PRP_KEYOBJ_HEADERS}
${PRP_LIGHT_SOURCES} ${PRP_LIGHT_HEADERS}
${PRP_MSG_SOURCES} ${PRP_MSG_HEADERS}
${PRP_MISC_SOURCES} ${PRP_MISC_HEADERS}
${PRP_MOD_SOURCES} ${PRP_MOD_HEADERS}
${PRP_OBJ_SOURCES} ${PRP_OBJ_HEADERS}
${PRP_PARTICLE_SOURCES} ${PRP_PARTICLE_HEADERS}
${PRP_PHYS_SOURCES} ${PRP_PHYS_HEADERS}
${PRP_REGION_SOURCES} ${PRP_REGION_HEADERS}
${PRP_SURFACE_SOURCES} ${PRP_SURFACE_HEADERS}
${PRP_SOURCES} ${PRP_HEADERS}
${RESMGR_SOURCES} ${RESMGR_HEADERS}
${SDL_SOURCES} ${SDL_HEADERS}
${STREAM_SOURCES} ${STREAM_HEADERS}
${SYS_SOURCES} ${SYS_HEADERS}
${UTIL_SOURCES} ${UTIL_HEADERS}
${VAULT_SOURCES} ${VAULT_HEADERS}
${PYTHON_SOURCES} ${PYTHON_HEADERS}
)

target_link_libraries(PyHSPlasma PUBLIC HSPlasma)
set_target_properties(PyHSPlasma PROPERTIES PREFIX "")

if(NOT WIN32)
set_target_properties(PyHSPlasma PROPERTIES
SUFFIX ".so"
)

execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import sys, distutils.sysconfig; sys.stdout.write(distutils.sysconfig.get_python_lib(prefix='${CMAKE_INSTALL_PREFIX}'))"
execute_process(COMMAND ${Python_EXECUTABLE} -c "import sys, distutils.sysconfig; sys.stdout.write(distutils.sysconfig.get_python_lib(prefix='${CMAKE_INSTALL_PREFIX}'))"
OUTPUT_VARIABLE _PYTHON_LIB_DIR
)
install(TARGETS PyHSPlasma
DESTINATION ${_PYTHON_LIB_DIR}
)
else()
set_target_properties(PyHSPlasma PROPERTIES
SUFFIX ".pyd"
)

install(TARGETS PyHSPlasma
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
Expand Down
18 changes: 9 additions & 9 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ environment:
VisualStudioVersion: 12.0
CMAKE_GENERATOR: Visual Studio 12 2013
PYTHON_PREFIX: C:\Python27
CMAKE_PARAMS: -DPYTHON_INCLUDE_DIR=C:/Python27/include
-DPYTHON_LIBRARY=C:/Python27/libs/python27.lib
-DPYTHON_EXECUTABLE=C:/Python27/python.exe
CMAKE_PARAMS: -DPython_EXECUTABLE=C:/Python27/python.exe
-DPython_INCLUDE_DIR=C:/Python27/include
-DPython_LIBRARY=C:/Python27/libs/python27.lib
PREFIX_TARGET: vc2013-x86-static
DIST_SUFFIX: '%PREFIX_TARGET%-py27'

- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
VisualStudioVersion: 14.0
CMAKE_GENERATOR: Visual Studio 14 2015
PYTHON_PREFIX: C:\Python36
CMAKE_PARAMS: -DPYTHON_INCLUDE_DIR=C:/Python36/include
-DPYTHON_LIBRARY=C:/Python36/libs/python36.lib
-DPYTHON_EXECUTABLE=C:/Python36/python.exe
CMAKE_PARAMS: -DPython_EXECUTABLE=C:/Python36/python.exe
-DPython_INCLUDE_DIR=C:/Python36/include
-DPython_LIBRARY=C:/Python36/libs/python36.lib
PREFIX_TARGET: vc2015-x86-static
DIST_SUFFIX: '%PREFIX_TARGET%-py36'

- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
VisualStudioVersion: 15.0
CMAKE_GENERATOR: Visual Studio 15 2017 Win64
PYTHON_PREFIX: C:\Python36-x64
CMAKE_PARAMS: -DPYTHON_INCLUDE_DIR=C:/Python36-x64/include
-DPYTHON_LIBRARY=C:/Python36-x64/libs/python36.lib
-DPYTHON_EXECUTABLE=C:/Python36-x64/python.exe
CMAKE_PARAMS: -DPython_EXECUTABLE=C:/Python36-x64/python.exe
-DPython_INCLUDE_DIR=C:/Python36-x64/include
-DPython_LIBRARY=C:/Python36-x64/libs/python36.lib
PREFIX_TARGET: vc2017-x64-static
DIST_SUFFIX: '%PREFIX_TARGET%-py36'

Expand Down

0 comments on commit 188d3f5

Please sign in to comment.