@@ -11,9 +11,9 @@ if(WIN32)
1111 endif ()
1212
1313 if (${CMAKE_GENERATOR_PLATFORM } STREQUAL Win32 )
14- set (VCPKG_TARGET_TRIPLET x86-windows)
14+ set (VCPKG_TARGET_TRIPLET " x86-windows" )
1515 elseif (${CMAKE_GENERATOR_PLATFORM } STREQUAL x64)
16- set (VCPKG_TARGET_TRIPLET x64-windows)
16+ set (VCPKG_TARGET_TRIPLET " x64-windows" )
1717 else ()
1818 message (FATAL_ERROR "Unsupported Generator Platform, only Win32 or x64 are supported" )
1919 endif ()
@@ -33,14 +33,15 @@ set (CMAKE_CXX_STANDARD 14)
3333if (UNIX )
3434 SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS } ${GCC_COVERAGE_COMPILE_FLAGS} -fPIC -g -O3" )
3535 SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS } -fPIC -O3 -g" )
36+ set (OpenGL_GL_PREFERENCE GLVND)
3637endif (UNIX )
3738
38- # Find needed libraries
39+ # Find required libraries
3940FIND_PACKAGE (OpenGL REQUIRED )
4041include_directories (${OPENGL_INCLUDE_DIR} )
4142
4243FIND_PACKAGE (SDL2 REQUIRED )
43- include_directories (${SDL2_INCLUDE_DIR } )
44+ include_directories (${SDL2_INCLUDE_DIRS } )
4445
4546if (UNIX AND NOT APPLE )
4647 FIND_PACKAGE (EGL REQUIRED )
@@ -62,35 +63,44 @@ include_directories(${SDL2_TTF_DIRS})
6263include_directories (${SDL2_GFX_DIRS} )
6364
6465if (UNIX )
65- find_package (PythonLibs 3 REQUIRED )
66- else ()
67- set (PYTHONLIBS_VERSION_STRING $ENV{PY_VERSION} )
68- endif ()
69-
70- message ("Using Python: ${PYTHONLIBS_VERSION_STRING} " )
71- string (REPLACE "." ";" VERSION_LIST ${PYTHONLIBS_VERSION_STRING} )
72- list (GET VERSION_LIST 0 PYTHON_MAJOR)
73- list (GET VERSION_LIST 1 PYTHON_MINOR)
74-
75- if (WIN32 )
66+ if (${CMAKE_VERSION } VERSION_GREATER_EQUAL "3.12" )
67+ find_package (Python COMPONENTS Development REQUIRED )
68+ else ()
69+ # Starting from CMake 3.12 FindPythonLibs was deprecated in favour of FindPython.
70+ # But Ubuntu 18.04 and other older distributions have CMake version less than 3.12,
71+ # so we have to support the old behaviour for some time.
72+ find_package (PythonLibs 3 REQUIRED )
73+ string (REPLACE "." ";" VERSION_LIST ${PYTHONLIBS_VERSION_STRING} )
74+ list (GET VERSION_LIST 0 Python_VERSION_MAJOR)
75+ list (GET VERSION_LIST 1 Python_VERSION_MINOR)
76+ set (Python_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS} )
77+ set (Python_LIBRARIES ${PYTHON_LIBRARIES} )
78+ endif ()
79+ elseif (WIN32 )
7680 # find_package (Python COMPONENTS Development)
7781 # FindPython package searches for system-wide python installations first.
7882 # It was improved only recently (Jan 2021), so we can't use it for earlier py versions:
7983 # (see https://github.com/microsoft/vcpkg/pull/15221 )
8084 # To avoid version mismatch we point to vcpkg's libs directly
81- set (PYTHON_LIBRARIES "${CMAKE_BINARY_DIR } /vcpkg_installed/${VCPKG_TARGET_TRIPLET} /lib/python${PYTHON_MAJOR}${PYTHON_MINOR} .lib" )
82- set (PYTHON_INCLUDE_DIR "${CMAKE_BINARY_DIR } /vcpkg_installed/${VCPKG_TARGET_TRIPLET} /include/python${PYTHON_MAJOR} .${PYTHON_MINOR} " )
85+ string (REPLACE "." ";" VERSION_LIST $ENV{PY_VERSION} )
86+ list (GET VERSION_LIST 0 Python_VERSION_MAJOR)
87+ list (GET VERSION_LIST 1 Python_VERSION_MINOR)
88+ set (Python_INCLUDE_DIRS "${CMAKE_BINARY_DIR } /vcpkg_installed/${VCPKG_TARGET_TRIPLET} /include/python${Python_VERSION_MAJOR} .${Python_VERSION_MINOR} " )
89+ set (Python_LIBRARIES "${CMAKE_BINARY_DIR } /vcpkg_installed/${VCPKG_TARGET_TRIPLET} /lib/python${Python_VERSION_MAJOR}${Python_VERSION_MINOR} .lib" )
8390endif ()
8491
92+ message ("Using Python: ${Python_VERSION_MAJOR} .${Python_VERSION_MINOR} " )
93+ include_directories (${Python_INCLUDE_DIRS} )
94+
8595# Include Boost Python.
8696if (WIN32 OR APPLE )
87- set (BOOST_PYTHON_VERSION python${PYTHON_MAJOR }${PYTHON_MINOR } )
97+ set (BOOST_PYTHON_VERSION python${Python_VERSION_MAJOR }${Python_VERSION_MINOR } )
8898else ()
8999 # Unfortunately different linux distributions are using different naming for boost-python
90- # list of prefixes: Ubuntu, Debian, Some other distributions
91- set (BOOST_PYTHON_PREFIXES python3-py python-py python )
100+ # list of prefixes: newer Ubuntu and other distributions, older Ubuntu, Debian
101+ set (BOOST_PYTHON_PREFIXES python python3-py python-py)
92102 foreach (BP_PREFIX ${BOOST_PYTHON_PREFIXES} )
93- set (BOOST_PYTHON_NAME ${BP_PREFIX}${PYTHON_MAJOR }${PYTHON_MINOR } )
103+ set (BOOST_PYTHON_NAME ${BP_PREFIX}${Python_VERSION_MAJOR }${Python_VERSION_MINOR } )
94104 string (TOUPPER ${BOOST_PYTHON_NAME} BOOST_PYTHON_NAME_UPPER)
95105 FIND_PACKAGE (Boost COMPONENTS ${BOOST_PYTHON_NAME} )
96106 if (Boost_${BOOST_PYTHON_NAME_UPPER} _FOUND)
@@ -103,12 +113,10 @@ else()
103113 message (FATAL_ERROR "Boost Python not found" )
104114 endif ()
105115endif ()
106- message ("Using python_boost : ${BOOST_PYTHON_VERSION} " )
116+ message ("Using Boost.Python : ${BOOST_PYTHON_VERSION} " )
107117
108118FIND_PACKAGE (Boost REQUIRED COMPONENTS thread system filesystem ${BOOST_PYTHON_VERSION} )
109- include_directories (${Boost_INCLUDE_DIR} )
110-
111- include_directories (${PYTHON_INCLUDE_DIR} )
119+ include_directories (${Boost_INCLUDE_DIRS} )
112120
113121include_directories (${PROJECT_SOURCE_DIR } /src )
114122include_directories (${PROJECT_SOURCE_DIR } /src/cmake )
@@ -151,7 +159,7 @@ endif()
151159
152160set (LIBRARIES gamelib menulib datalib blunted2
153161 Boost::filesystem Boost::system Boost::thread Boost::${BOOST_PYTHON_VERSION}
154- ${PYTHON_LIBRARIES } ${SDL2_LIBS_ALL} ${EGL_LIBRARIES} ${OPENGL_LIBRARY } )
162+ ${Python_LIBRARIES } ${SDL2_LIBS_ALL} ${EGL_LIBRARIES} ${OPENGL_LIBRARIES } )
155163
156164if (UNIX )
157165 set (LIB_NAME game)
0 commit comments