diff --git a/CMakeLists.txt b/CMakeLists.txt index 573defb7b3..91767f2481 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,7 @@ if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 4) endif() # Define minimum cmake version -cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) +cmake_minimum_required(VERSION 3.12 FATAL_ERROR) # Define minimum compiler versions @@ -124,51 +124,32 @@ SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # Check if pybind11 is to be ditched string(REGEX MATCH ";pybind;|;pybind11;|;Pybind;|;Pybind11;" DITCH_PYBIND ";${itch};") -# Check for Python interpreter. -# We also need to search for PythonLibs before letting pybind11 look for them, -# otherwise it seems to get it wrong. Also, we need to add versions of python -# greater than 3.3 manually, for compatibility with CMake 2.8.12. -# If pybind11 is ditched, do not worry about PythonLibs -set(Python_ADDITIONAL_VERSIONS 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13) -find_package(PythonInterp 3) # We require Python 3. -if(PYTHONINTERP_FOUND) - if(NOT DITCH_PYBIND) - find_package(PythonLibs 3) # We require Python 3. - endif() +# Check for Python 3 interpreter and (optionally) development libraries. +# If pybind11 is ditched, do not worry about Python Development libraries. +if(DITCH_PYBIND) + find_package(Python3 REQUIRED COMPONENTS Interpreter) else() + find_package(Python3 COMPONENTS Interpreter Development) +endif() +if(NOT Python3_Interpreter_FOUND) message(FATAL_ERROR "\nPython 3 was not found, but it is required by GAMBIT. \nIf you need to set the path to the Python interpreter manually, " - "please use -D PYTHON_EXECUTABLE=path/to/preferred/python.") -endif() -message("${BoldYellow} Using Python interpreter version ${PYTHON_VERSION_STRING} for build.${ColourReset}") - -if(PYTHONLIBS_FOUND) - message("${BoldYellow} Using Python libraries version ${PYTHONLIBS_VERSION_STRING} for Python backend support.${ColourReset}") - # Remove trailing non-numeric characters from version - string(REGEX REPLACE "[a-zA-Z]" "" PYTHONLIBS_VERSION_STRING_CLEAN ${PYTHONLIBS_VERSION_STRING}) - if (NOT "${PYTHON_VERSION_STRING}" STREQUAL "${PYTHONLIBS_VERSION_STRING_CLEAN}") - message("${BoldRed} NOTE: You are using different Python versions for the interpreter and the libraries!${ColourReset}\n" - " In principle this should be fine, as the interpreter is only used for building GAMBIT, and the\n" - " libraries are only used for providing support for Python backends at runtime. However, if you\n" - " have matching versions installed, you can make this message go away by manually setting the \n" - " following variables when you invoke cmake:\n" - " PYTHON_LIBRARY\n" - " PYTHON_INCLUDE_DIR\n" - " PYTHON_EXECUTABLE\n" - " Make sure to clean out your build dir before reconfiguring with these variables set.") - endif() + "please use -DPython3_EXECUTABLE=path/to/preferred/python.") +endif() +message("${BoldYellow} Using Python interpreter version ${Python3_VERSION} for build.${ColourReset}") + +if(Python3_Development_FOUND) + message("${BoldYellow} Using Python libraries version ${Python3_VERSION} for Python backend support.${ColourReset}") endif() -# Check for pybind11 if PythonLibs were found and not ditched -if(NOT PYTHONLIBS_FOUND AND NOT NO_PYTHON_LIBS) +# Check for pybind11 if Python Development libraries were found and not ditched +if(NOT Python3_Development_FOUND AND NOT NO_PYTHON_LIBS) if(DITCH_PYBIND) message("${BoldCyan} X Excluding pybind11 from GAMBIT configuration. Ditching support for Python backends.${ColourReset}") else() - message("${BoldRed} PythonLibs NOT found, so pybind11 cannot be used. Ditching support for Python backends.${ColourReset}\n" - " If you *do* have the Python libraries installed, you can manually set the following\n" - " variables when invoking cmake (also making sure to clean out your build dir):\n" - " PYTHON_LIBRARY\n" - " PYTHON_INCLUDE_DIR\n" - " PYTHON_EXECUTABLE") + message("${BoldRed} Python3 Development libraries NOT found, so pybind11 cannot be used. Ditching support for Python backends.${ColourReset}\n" + " If you *do* have the Python libraries installed, you can manually set\n" + " -DPython3_ROOT_DIR=path/to/python or -DPython3_EXECUTABLE=path/to/python\n" + " when invoking cmake (also making sure to clean out your build dir).") set(itch "${itch};pybind11") endif() @@ -176,7 +157,7 @@ else() set(MIN_pybind11_VERSION "2.13.6") set(PREFERRED_pybind11_VERSION "2.13.6") set(pybind11_CONTRIB_DIR "${PROJECT_SOURCE_DIR}/contrib/pybind11") - include_directories("${PYTHON_INCLUDE_DIRS}") + include_directories("${Python3_INCLUDE_DIRS}") unset(PYBIND11_CPP_STANDARD CACHE) find_package(pybind11 QUIET) if(pybind11_FOUND) @@ -599,7 +580,7 @@ endif() if(EXISTS "${PROJECT_SOURCE_DIR}/ScannerBit/") message("${Yellow}-- Updating GAMBIT scanner cmake and related files${ColourReset}") set(scanner_harvester ${PROJECT_SOURCE_DIR}/ScannerBit/scripts/scanner+_harvester.py ${PROJECT_BINARY_DIR} -x __not_a_real_name__,${itch_with_commas}) - execute_process(RESULT_VARIABLE result COMMAND ${PYTHON_EXECUTABLE} ${scanner_harvester} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) + execute_process(RESULT_VARIABLE result COMMAND ${Python3_EXECUTABLE} ${scanner_harvester} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) check_result(${result} ${scanner_harvester}) message("${Yellow}-- Updating GAMBIT scanner cmake and related files - done.${ColourReset}") endif() @@ -610,7 +591,7 @@ include(cmake/preprocessor.cmake) # Generate particle_database.cpp from particle_database.yaml. if(EXISTS "${PROJECT_SOURCE_DIR}/Models/") set(particle_harvester ${PROJECT_SOURCE_DIR}/Models/scripts/particle_harvester.py ${PROJECT_BINARY_DIR} -x __not_a_real_name__,${itch_with_commas}) - execute_process(COMMAND ${PYTHON_EXECUTABLE} ${particle_harvester} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) + execute_process(COMMAND ${Python3_EXECUTABLE} ${particle_harvester} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) message("${Yellow}-- Generated particle_database.cpp from particle_database.yaml.${ColourReset}") endif() @@ -672,7 +653,7 @@ endif() # Generate the CMakeLists.txt files for GAMBIT modules, Backends, Models and Printers) message("${Yellow}-- Updating GAMBIT module, model, backend, and printer CMake files.${ColourReset}") set(update_cmakelists ${PROJECT_SOURCE_DIR}/cmake/scripts/update_cmakelists.py -x __not_a_real_name__,${itch_with_commas}) -execute_process(RESULT_VARIABLE result COMMAND ${PYTHON_EXECUTABLE} ${update_cmakelists} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) +execute_process(RESULT_VARIABLE result COMMAND ${Python3_EXECUTABLE} ${update_cmakelists} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) check_result(${result} ${update_cmakelists}) message("${Yellow}-- Updating GAMBIT module, backend, and printer CMake files - done.${ColourReset}") diff --git a/ScannerBit/python/CMakeLists.txt b/ScannerBit/python/CMakeLists.txt index 0c07cf57ee..fd7839e1f7 100644 --- a/ScannerBit/python/CMakeLists.txt +++ b/ScannerBit/python/CMakeLists.txt @@ -4,13 +4,13 @@ include(cmake/scannerbit_python_interface_utils.cmake) include(cmake/boost_python.cmake) #include(cmake/yaml.cmake) -if(PYTHONINTERP_FOUND) +if(Python3_Interpreter_FOUND) if(VERBOSE_SCANNERBIT_PYTHON_INTERFACE) message("${BoldYellow}Python extensive module Python deps:${ColourReset}") - message("-- Python version string: ${PYTHON_VERSION_STRING}") - message("-- Python include dirs: ${PYTHON_INCLUDE_DIRS}") - message("-- Python executable: ${PYTHON_EXECUTABLE}") + message("-- Python version string: ${Python3_VERSION}") + message("-- Python include dirs: ${Python3_INCLUDE_DIRS}") + message("-- Python executable: ${Python3_EXECUTABLE}") endif(VERBOSE_SCANNERBIT_PYTHON_INTERFACE) if(HDF5_FOUND) @@ -36,7 +36,7 @@ if(PYTHONINTERP_FOUND) ${HDF5_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/contrib/pybind11/include ${yaml_INCLUDE_DIR} - ${PYTHON_INCLUDE_DIRS} + ${Python3_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/ScannerBit/include ${CMAKE_CURRENT_SOURCE_DIR}/include ) @@ -95,6 +95,6 @@ if(PYTHONINTERP_FOUND) else() message("${BoldRed}-- The ScannerBit python interface requires Python. ${ColourReset}") - message("${Red}-- PYTHONINTERP_FOUND=${PYTHONINTERP_FOUND} ${ColourReset}") + message("${Red}-- Python3_Interpreter_FOUND=${Python3_Interpreter_FOUND} ${ColourReset}") endif() diff --git a/ScannerBit/python/cmake/boost_python.cmake b/ScannerBit/python/cmake/boost_python.cmake index be20271d02..c593814474 100644 --- a/ScannerBit/python/cmake/boost_python.cmake +++ b/ScannerBit/python/cmake/boost_python.cmake @@ -6,7 +6,7 @@ ExternalProject_Add(boost_python BINARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/contrib/boost_python/build" SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/contrib/boost_python" PATCH_COMMAND cp ../../cmake/boost_python_install.cmake CMakeLists.txt - CONFIGURE_COMMAND ${CMAKE_COMMAND} -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} -DBoost_INCLUDE_DIRS=${Boost_INCLUDE_DIRS} -DPYTHON_INCLUDE_DIRS=${PYTHON_INCLUDE_DIRS} -DPYTHON_LIBRARIES=${PYTHON_LIBRARIES} -DPYTHON_VERSION_STRING=${PYTHON_VERSION_STRING} -DNUMPY_INCLUDE_DIRS=${NUMPY_INCLUDE_DIRS} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} .. + CONFIGURE_COMMAND ${CMAKE_COMMAND} -DPython3_EXECUTABLE=${Python3_EXECUTABLE} -DBoost_INCLUDE_DIRS=${Boost_INCLUDE_DIRS} -DPython3_INCLUDE_DIRS=${Python3_INCLUDE_DIRS} -DPython3_LIBRARIES=${Python3_LIBRARIES} -DPython3_VERSION=${Python3_VERSION} -DNUMPY_INCLUDE_DIRS=${NUMPY_INCLUDE_DIRS} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} .. BUILD_COMMAND make boost_python INSTALL_COMMAND "" ) diff --git a/ScannerBit/python/cmake/boost_python_install.cmake b/ScannerBit/python/cmake/boost_python_install.cmake index b6e110ba11..cb5a69ce95 100644 --- a/ScannerBit/python/cmake/boost_python_install.cmake +++ b/ScannerBit/python/cmake/boost_python_install.cmake @@ -1,7 +1,6 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8.10 FATAL_ERROR) - -FIND_PACKAGE(PythonInterp REQUIRED) -FIND_PACKAGE(PythonLibs) +CMAKE_MINIMUM_REQUIRED(VERSION 3.12 FATAL_ERROR) + +find_package(Python3 REQUIRED COMPONENTS Interpreter Development) FIND_PACKAGE(NumPy) FIND_PACKAGE(Boost 1.41) @@ -52,19 +51,19 @@ SET(BOOST_PYTHON_FLAGS SET(BOOST_PYTHON_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include ${Boost_INCLUDE_DIRS} - ${PYTHON_INCLUDE_DIRS} + ${Python3_INCLUDE_DIRS} ) SET(BOOST_NUMPY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include ${Boost_INCLUDE_DIRS} - ${PYTHON_INCLUDE_DIRS} + ${Python3_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIRS} ) ADD_LIBRARY(boost_python SHARED ${BOOST_PYTHON_SRCS}) -TARGET_LINK_LIBRARIES(boost_python pthread ${PYTHON_LIBRARIES}) +TARGET_LINK_LIBRARIES(boost_python pthread ${Python3_LIBRARIES}) SET_TARGET_PROPERTIES( boost_python PROPERTIES @@ -72,12 +71,12 @@ SET_TARGET_PROPERTIES( boost_python INCLUDE_DIRECTORIES "${BOOST_PYTHON_INCLUDE_DIRS}" ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib" - LIBRARY_OUTPUT_NAME "boost_python${PYTHON_VERSION_STRING}" + LIBRARY_OUTPUT_NAME "boost_python${Python3_VERSION}" SUFFIX .so) ADD_LIBRARY(boost_numpy SHARED ${BOOST_NUMPY_SRCS}) -TARGET_LINK_LIBRARIES(boost_numpy pthread ${PYTHON_LIBRARIES}) +TARGET_LINK_LIBRARIES(boost_numpy pthread ${Python3_LIBRARIES}) SET_TARGET_PROPERTIES( boost_numpy PROPERTIES @@ -85,6 +84,6 @@ SET_TARGET_PROPERTIES( boost_numpy INCLUDE_DIRECTORIES "${BOOST_NUMPY_INCLUDE_DIRS}" ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib" - LIBRARY_OUTPUT_NAME "boost_numpy${PYTHON_VERSION_STRING}" + LIBRARY_OUTPUT_NAME "boost_numpy${Python3_VERSION}" SUFFIX .so) diff --git a/cmake/FindCython.cmake b/cmake/FindCython.cmake index 2ec34d16e0..04cf33e092 100644 --- a/cmake/FindCython.cmake +++ b/cmake/FindCython.cmake @@ -36,9 +36,9 @@ # Use the Cython executable that lives next to the Python executable # if it is a local installation. -find_package(PythonInterp) -if(PYTHONINTERP_FOUND) - get_filename_component(_python_path ${PYTHON_EXECUTABLE} PATH) +find_package(Python3 QUIET COMPONENTS Interpreter) +if(Python3_Interpreter_FOUND) + get_filename_component(_python_path ${Python3_EXECUTABLE} PATH) find_program(CYTHON_EXECUTABLE NAMES cython cython.bat cython3 HINTS ${_python_path} @@ -58,8 +58,8 @@ if(CYTHON_EXECUTABLE) # RESULT_VARIABLE CYTHON_version_result # OUTPUT_STRIP_TRAILING_WHITESPACE) -# message("${PYTHON_EXECUTABLE} -m cython --version") - execute_process(COMMAND ${PYTHON_EXECUTABLE} -m cython --version +# message("${Python3_EXECUTABLE} -m cython --version") + execute_process(COMMAND ${Python3_EXECUTABLE} -m cython --version RESULT_VARIABLE cython_result ERROR_VARIABLE cython_output) @@ -67,7 +67,7 @@ if(CYTHON_EXECUTABLE) string(REGEX REPLACE "^Cython version ([0-9]+\\.[0-9]+).*" "\\1" CYTHON_VERSION "${cython_output}") else() string(REGEX REPLACE "\n" "" cython_output "${cython_output}") - message(" Did not find cython${PYTHON_VERSION}: ${cython_output}") + message(" Did not find cython${Python3_VERSION}: ${cython_output}") endif() # if(NOT ${CYTHON_version_result} EQUAL 0) @@ -84,6 +84,6 @@ endif() include(FindPackageHandleStandardArgs) # FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cython REQUIRED_VARS CYTHON_EXECUTABLE) -find_package_handle_standard_args(Cython${PYTHON_VERSION} DEFAULT_MSG CYTHON_VERSION) +find_package_handle_standard_args(Cython${Python3_VERSION} DEFAULT_MSG CYTHON_VERSION) mark_as_advanced(CYTHON_EXECUTABLE) diff --git a/cmake/utilities.cmake b/cmake/utilities.cmake index 7760a703c7..b02f22719a 100644 --- a/cmake/utilities.cmake +++ b/cmake/utilities.cmake @@ -159,7 +159,7 @@ macro(add_external_clean package dir dl target) set(reset_file "${CMAKE_BINARY_DIR}/BOSS_reset_info/reset_info.${safe_package}.boss") add_custom_target(clean-${package} COMMAND ${CMAKE_COMMAND} -E remove -f ${rmstring1}-BOSS ${rmstring1}-configure ${rmstring1}-build ${rmstring1}-install ${rmstring1}-done COMMAND [ -e ${dir} ] && cd ${dir} && ([ -e makefile ] || [ -e Makefile ] && (${target})) || true - COMMAND [ -e ${reset_file} ] && ${PYTHON_EXECUTABLE} ${BOSS_dir}/boss.py -r ${reset_file} || true) + COMMAND [ -e ${reset_file} ] && ${Python3_EXECUTABLE} ${BOSS_dir}/boss.py -r ${reset_file} || true) add_custom_target(nuke-${package} DEPENDS clean-${package} COMMAND ${CMAKE_COMMAND} -E remove -f ${rmstring1}-download ${rmstring1}-download-failed ${rmstring1}-mkdir ${rmstring1}-patch ${rmstring1}-update ${rmstring1}-gitclone-lastrun.txt ${dl} || true COMMAND ${CMAKE_COMMAND} -E remove_directory ${dir} || true @@ -272,7 +272,7 @@ macro(add_gambit_custom target filename HARVESTER DEPS) set(ditch_string "-x __not_a_real_name__,${ARGN}") endif() add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${filename} - COMMAND ${PYTHON_EXECUTABLE} ${${HARVESTER}} ${ditch_string} + COMMAND ${Python3_EXECUTABLE} ${${HARVESTER}} ${ditch_string} COMMAND touch ${CMAKE_BINARY_DIR}/${filename} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} DEPENDS ${${HARVESTER}} @@ -371,7 +371,7 @@ function(add_gambit_executable executablename LIBRARIES) set(LIBRARIES ${LIBRARIES} ${Mathematica_WSTP_LIBRARIES}) endif() if(pybind11_FOUND) - set(LIBRARIES ${LIBRARIES} ${PYTHON_LIBRARIES}) + set(LIBRARIES ${LIBRARIES} ${Python3_LIBRARIES}) endif() if(SQLite3_FOUND) set(LIBRARIES ${LIBRARIES} ${SQLite3_LIBRARIES}) @@ -451,7 +451,7 @@ function(add_standalone executablename) # Set up the target to call the facilitator script to make the functors source file for this standalone. add_custom_command(OUTPUT ${STANDALONE_FUNCTORS} - COMMAND ${PYTHON_EXECUTABLE} ${STANDALONE_FACILITATOR} ${executablename} -m __not_a_real_name__,${COMMA_SEPARATED_MODULES} + COMMAND ${Python3_EXECUTABLE} ${STANDALONE_FACILITATOR} ${executablename} -m __not_a_real_name__,${COMMA_SEPARATED_MODULES} COMMAND touch ${STANDALONE_FUNCTORS} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} DEPENDS modules_harvested @@ -727,7 +727,7 @@ macro(BOSS_backend_full name backend_version ${ARGN}) add_dependencies(${name}_${ver} castxml) ExternalProject_Add_Step(${name}_${ver} BOSS # Run BOSS - COMMAND ${PYTHON_EXECUTABLE} ${BOSS_dir}/boss.py --no-instructions ${BOSS_castxml_cc} ${BOSS_command_line_options} ${BOSS_includes_Boost} ${BOSS_includes_Eigen3} ${BOSS_includes_GSL} ${name}_${backend_version_safe} + COMMAND ${Python3_EXECUTABLE} ${BOSS_dir}/boss.py --no-instructions ${BOSS_castxml_cc} ${BOSS_command_line_options} ${BOSS_includes_Boost} ${BOSS_includes_Eigen3} ${BOSS_includes_GSL} ${name}_${backend_version_safe} # Copy BOSS-generated files to correct folders within Backends/include COMMAND ${CMAKE_COMMAND} -E remove_directory ${PROJECT_SOURCE_DIR}/Backends/include/gambit/Backends/backend_types/${name_in_frontend}_${backend_version_safe} || true COMMAND cp -r BOSS_output/${name_in_frontend}_${backend_version_safe}/for_gambit/backend_types/${name_in_frontend}_${backend_version_safe} ${PROJECT_SOURCE_DIR}/Backends/include/gambit/Backends/backend_types/ diff --git a/gum/CMakeLists.txt b/gum/CMakeLists.txt index 1d1ce37b49..79e8c82850 100644 --- a/gum/CMakeLists.txt +++ b/gum/CMakeLists.txt @@ -20,7 +20,7 @@ # # ************************************** -cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) +cmake_minimum_required(VERSION 3.12 FATAL_ERROR) project(GUM) message(" Building GUM in ${CMAKE_CURRENT_SOURCE_DIR}") include(ExternalProject) @@ -74,43 +74,28 @@ endif() # Contrib packages include(cmake/contrib.cmake) -# Check for Python interpreter -# Also, we need to add versions of python greater than 3.3 manually, -# for compatibility with CMake 2.8.12. -set(Python_ADDITIONAL_VERSIONS 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11) -find_package(PythonInterp 3) # We require Python 3. -if(PYTHONINTERP_FOUND) - if(NOT DITCH_PYBIND) - find_package(PythonLibs 3) # We require Python 3. - endif() -else() +# Check for Python 3 interpreter and development libraries +find_package(Python3 REQUIRED COMPONENTS Interpreter Development) +if(NOT Python3_Interpreter_FOUND) message(FATAL_ERROR "\nPython 3 was not found, but it is required by GUM. \nIf you need to set the path to the Python interpreter manually, " - "please use -D PYTHON_EXECUTABLE=path/to/preferred/python.") + "please use -DPython3_EXECUTABLE=path/to/preferred/python.") endif() -include_directories(${PYTHON_INCLUDE_DIRS}) -message(" Using Python interpreter version ${PYTHON_VERSION_STRING} for build.") - -if(PYTHONLIBS_FOUND) - message(" Using Python libraries version ${PYTHONLIBS_VERSION_STRING}.") - # Remove trailing non-numeric characters from version - string(REGEX REPLACE "[a-zA-Z]" "" PYTHONLIBS_VERSION_STRING_CLEAN ${PYTHONLIBS_VERSION_STRING}) - if (NOT "${PYTHON_VERSION_STRING}" STREQUAL "${PYTHONLIBS_VERSION_STRING_CLEAN}") - message(" You are using different Python versions for the interpreter and the libraries! GUM might not work, please make sure to have matching versions installed.") - endif() +include_directories(${Python3_INCLUDE_DIRS}) +message(" Using Python interpreter version ${Python3_VERSION} for build.") + +if(Python3_Development_FOUND) + message(" Using Python libraries version ${Python3_VERSION}.") else() - message(FATAL_ERROR " PythonLibs for Python version ${PYTHON_VERSION_STRING} NOT found! Plase make sure to install them to work with GUM.\n" - " If you *do* have the Python libraries installed, you can try manually setting the \n" - " following variables when you invoke cmake:\n" - " PYTHON_LIBRARY\n" - " PYTHON_INCLUDE_DIR\n" - " PYTHON_EXECUTABLE\n" - " Make sure to clean out your build dir before reconfiguring with these variables set.") + message(FATAL_ERROR " Python3 Development libraries NOT found! Please make sure to install them to work with GUM.\n" + " If you *do* have the Python libraries installed, you can try manually setting\n" + " -DPython3_ROOT_DIR=path/to/python or -DPython3_EXECUTABLE=path/to/python\n" + " when invoking cmake (also making sure to clean out your build dir).") endif() # Simple function to find specific Python modules macro(find_python_module module) - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import ${module}" RESULT_VARIABLE return_value ERROR_QUIET) + execute_process(COMMAND ${Python3_EXECUTABLE} -c "import ${module}" RESULT_VARIABLE return_value ERROR_QUIET) if (NOT return_value) message(STATUS "Found Python module ${module}.") set(PY_${module}_FOUND TRUE) @@ -159,14 +144,12 @@ endif() set(Boost_NO_BOOST_CMAKE ON) find_package(Boost 1.41.0 QUIET) if(Boost_FOUND) - if(PYTHON_VERSION_MAJOR EQUAL 2) - set(python_component python) - elseif(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND Boost_VERSION LESS 105800) + if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND Boost_VERSION LESS 105800) set(python_component python3) elseif(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND Boost_VERSION LESS 106700) - set(python_component python-py${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}) + set(python_component python-py${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}) else() - set(python_component python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR} ) + set(python_component python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR} ) endif() if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,dynamic_lookup") @@ -177,9 +160,9 @@ if(Boost_FOUND) find_package(Boost 1.41.0 REQUIRED COMPONENTS ${python_component} filesystem system) include_directories("${Boost_INCLUDE_DIR}") add_library(fr SHARED src/feynrules.cpp src/math_package.cpp) - target_link_libraries(fr ${LIBRARIES} ${PYTHON_LIBRARIES} ${Boost_LIBRARIES}) + target_link_libraries(fr ${LIBRARIES} ${Python3_LIBRARIES} ${Boost_LIBRARIES}) add_library(sarah SHARED src/sarah.cpp src/math_package.cpp) - target_link_libraries(sarah ${LIBRARIES} ${PYTHON_LIBRARIES} ${Boost_LIBRARIES}) + target_link_libraries(sarah ${LIBRARIES} ${Python3_LIBRARIES} ${Boost_LIBRARIES}) else() message(FATAL_ERROR "\nGUM requires Boost v1.41 or greater, including the compiled libraries Boost.Python, Boost.System and Boost.Filesystem.\nPlease install suitable Boost components and rerun cmake.") endif() @@ -205,7 +188,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") add_executable(mathematica ${SRC_GUM} ${HEADER_FILES}) -TARGET_LINK_LIBRARIES(mathematica ${LIBRARIES} ${PYTHON_LIBRARIES} ${Boost_LIBRARIES} ${GUM_LIBS}) +TARGET_LINK_LIBRARIES(mathematica ${LIBRARIES} ${Python3_LIBRARIES} ${Boost_LIBRARIES} ${GUM_LIBS}) if (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") OR