Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 24 additions & 43 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -124,59 +124,40 @@ 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()

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)
Expand Down Expand Up @@ -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()
Expand All @@ -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()

Expand Down Expand Up @@ -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}")

Expand Down
12 changes: 6 additions & 6 deletions ScannerBit/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
)
Expand Down Expand Up @@ -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()
2 changes: 1 addition & 1 deletion ScannerBit/python/cmake/boost_python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
)
Expand Down
19 changes: 9 additions & 10 deletions ScannerBit/python/cmake/boost_python_install.cmake
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -52,39 +51,39 @@ 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
COMPILE_FLAGS "${BOOST_PYTHON_FLAGS}"
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
COMPILE_FLAGS "${BOOST_PYTHON_FLAGS}"
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)

14 changes: 7 additions & 7 deletions cmake/FindCython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -58,16 +58,16 @@ 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)

if(cython_result EQUAL 0)
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)
Expand All @@ -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)
10 changes: 5 additions & 5 deletions cmake/utilities.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}}
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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/
Expand Down
Loading
Loading