Multiple python versions (#42)
* Support multiple Python versions in single build * RPATH + Split up config into config and runtime * pybind11 submodule * Docker build updates
Bu işleme şunda yer alıyor:
işlemeyi yapan:
GitHub
ebeveyn
d98e60a17f
işleme
4db6ba3d28
@@ -12,31 +12,23 @@ set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME python)
|
||||
|
||||
# ########################################################################################
|
||||
|
||||
function(OMNITRACE_CONFIGURE_PYTARGET _TARGET)
|
||||
function(OMNITRACE_CONFIGURE_PYTARGET _TARGET _VERSION)
|
||||
|
||||
add_library(omnitrace::${_TARGET} ALIAS ${_TARGET})
|
||||
target_link_libraries(${_TARGET} PRIVATE libpyomnitrace-interface)
|
||||
|
||||
set(_SUBDIR ${ARGN})
|
||||
if(_SUBDIR)
|
||||
set(_SUBDIR "/${_SUBDIR}")
|
||||
endif()
|
||||
|
||||
set_target_properties(
|
||||
${_TARGET}
|
||||
PROPERTIES PREFIX ""
|
||||
SUFFIX "${PYTHON_MODULE_EXTENSION}"
|
||||
LIBRARY_OUTPUT_DIRECTORY
|
||||
${PROJECT_BINARY_DIR}/python/omnitrace${_SUBDIR}
|
||||
ARCHIVE_OUTPUT_DIRECTORY
|
||||
${PROJECT_BINARY_DIR}/python/omnitrace${_SUBDIR}
|
||||
RUNTIME_OUTPUT_DIRECTORY
|
||||
${PROJECT_BINARY_DIR}/python/omnitrace${_SUBDIR}
|
||||
PDB_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/python/omnitrace${_SUBDIR}
|
||||
OUTPUT_NAME libpyomnitrace
|
||||
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/python/omnitrace
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/python/omnitrace
|
||||
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/python/omnitrace
|
||||
PDB_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/python/omnitrace
|
||||
INSTALL_RPATH_USE_LINK_PATH ON
|
||||
${EXTRA_PROPERTIES})
|
||||
|
||||
set(_PYLIB ${CMAKE_INSTALL_PYTHONDIR}/omnitrace${_SUBDIR})
|
||||
set(_PYLIB ${CMAKE_INSTALL_PYTHONDIR}/omnitrace)
|
||||
if(NOT IS_ABSOLUTE "${_PYLIB}")
|
||||
set(_PYLIB ${CMAKE_INSTALL_PREFIX}/${_PYLIB})
|
||||
endif()
|
||||
@@ -57,12 +49,8 @@ function(OMNITRACE_CONFIGURE_PYTARGET _TARGET)
|
||||
|
||||
install(
|
||||
TARGETS ${_TARGET}
|
||||
DESTINATION ${CMAKE_INSTALL_PYTHONDIR}/omnitrace${_SUBDIR}
|
||||
DESTINATION ${CMAKE_INSTALL_PYTHONDIR}/omnitrace
|
||||
OPTIONAL)
|
||||
|
||||
if(NOT "${_TARGET}" STREQUAL "libpyomnitrace")
|
||||
add_dependencies(libpyomnitrace ${_TARGET})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# ########################################################################################
|
||||
@@ -96,12 +84,160 @@ target_link_libraries(
|
||||
|
||||
target_compile_definitions(libpyomnitrace-interface INTERFACE OMNITRACE_PYBIND11_SOURCE)
|
||||
|
||||
add_library(libpyomnitrace MODULE ${pysources} ${pyheaders})
|
||||
omnitrace_configure_pytarget(libpyomnitrace)
|
||||
# ----------------------------------------------------------------------------
|
||||
# Console scripts
|
||||
#
|
||||
function(OMNITRACE_PYTHON_CONSOLE_SCRIPT SCRIPT_NAME SCRIPT_SUBMODULE)
|
||||
set(options)
|
||||
set(args VERSION ROOT_DIR)
|
||||
set(kwargs)
|
||||
cmake_parse_arguments(ARG "${options}" "${args}" "${kwargs}" ${ARGN})
|
||||
|
||||
add_subdirectory(omnitrace)
|
||||
if(ARG_VERSION AND ARG_ROOT_DIR)
|
||||
set(Python3_ROOT_DIR "${ARG_ROOT_DIR}")
|
||||
find_package(Python3 ${ARG_VERSION} EXACT QUIET MODULE COMPONENTS Interpreter)
|
||||
set(PYTHON_EXECUTABLE "${Python3_EXECUTABLE}")
|
||||
configure_file(${PROJECT_SOURCE_DIR}/cmake/Templates/console-script.in
|
||||
${PROJECT_BINARY_DIR}/bin/${SCRIPT_NAME}-${ARG_VERSION} @ONLY)
|
||||
|
||||
if(PYTHON_EXECUTABLE)
|
||||
if(CMAKE_INSTALL_PYTHONDIR)
|
||||
install(
|
||||
PROGRAMS ${PROJECT_BINARY_DIR}/bin/${SCRIPT_NAME}-${ARG_VERSION}
|
||||
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
OPTIONAL)
|
||||
endif()
|
||||
|
||||
if(OMNITRACE_BUILD_TESTING OR OMNITRACE_BUILD_PYTHON)
|
||||
add_test(
|
||||
NAME ${SCRIPT_NAME}-console-script-test-${ARG_VERSION}
|
||||
COMMAND ${PROJECT_BINARY_DIR}/bin/${SCRIPT_NAME}-${ARG_VERSION} --help
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
|
||||
set_tests_properties(
|
||||
${SCRIPT_NAME}-console-script-test-${ARG_VERSION}
|
||||
PROPERTIES LABELS "python;python-${ARG_VERSION};console-script")
|
||||
add_test(
|
||||
NAME ${SCRIPT_NAME}-generic-console-script-test-${ARG_VERSION}
|
||||
COMMAND ${PROJECT_BINARY_DIR}/bin/${SCRIPT_NAME} --help
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
|
||||
set_tests_properties(
|
||||
${SCRIPT_NAME}-generic-console-script-test-${ARG_VERSION}
|
||||
PROPERTIES ENVIRONMENT "PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}" LABELS
|
||||
"python;python-${ARG_VERSION};console-script")
|
||||
endif()
|
||||
else()
|
||||
set(PYTHON_EXECUTABLE "python3")
|
||||
|
||||
configure_file(${PROJECT_SOURCE_DIR}/cmake/Templates/console-script.in
|
||||
${PROJECT_BINARY_DIR}/bin/${SCRIPT_NAME} @ONLY)
|
||||
|
||||
if(CMAKE_INSTALL_PYTHONDIR)
|
||||
install(
|
||||
PROGRAMS ${PROJECT_BINARY_DIR}/bin/${SCRIPT_NAME}
|
||||
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
OPTIONAL)
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
include(PyBind11Tools)
|
||||
|
||||
# OMNITRACE_PYTHON_ROOT_DIRS=/opt/conda/envs/py36;/opt/conda/envs/py37;/opt/conda/envs/py38;/opt/conda/envs/py39
|
||||
# OMNITRACE_PYTHON_VERSIONS=3.6;3.7;3.8;3.9
|
||||
|
||||
if(NOT OMNITRACE_PYTHON_VERSIONS AND OMNITRACE_PYTHON_VERSION)
|
||||
set(OMNITRACE_PYTHON_VERSIONS "${OMNITRACE_PYTHON_VERSION}")
|
||||
if(NOT OMNITRACE_PYTHON_ROOT_DIRS)
|
||||
omnitrace_find_python(_PY VERSION ${OMNITRACE_PYTHON_VERSION})
|
||||
set(OMNITRACE_PYTHON_ROOT_DIRS
|
||||
"${_PY_ROOT_DIR}"
|
||||
CACHE INTERNAL "" FORCE)
|
||||
endif()
|
||||
elseif(
|
||||
NOT OMNITRACE_PYTHON_VERSIONS
|
||||
AND NOT OMNITRACE_PYTHON_VERSION
|
||||
AND OMNITRACE_PYTHON_ROOT_DIRS)
|
||||
set(_PY_VERSIONS)
|
||||
foreach(_DIR ${OMNITRACE_PYTHON_ROOT_DIRS})
|
||||
omnitrace_find_python(_PY ROOT_DIR ${_DIR})
|
||||
if(NOT _PY_FOUND)
|
||||
continue()
|
||||
endif()
|
||||
if(NOT "${_PY_VERSION}" IN_LIST _PY_VERSIONS)
|
||||
list(APPEND _PY_VERSIONS "${_PY_VERSION}")
|
||||
endif()
|
||||
endforeach()
|
||||
set(OMNITRACE_PYTHON_VERSIONS
|
||||
"${_PY_VERSIONS}"
|
||||
CACHE INTERNAL "" FORCE)
|
||||
elseif(
|
||||
NOT OMNITRACE_PYTHON_VERSIONS
|
||||
AND NOT OMNITRACE_PYTHON_VERSION
|
||||
AND NOT OMNITRACE_PYTHON_ROOT_DIRS)
|
||||
omnitrace_find_python(_PY REQUIRED)
|
||||
set(OMNITRACE_PYTHON_ROOT_DIRS
|
||||
"${_PY_ROOT_DIR}"
|
||||
CACHE INTERNAL "" FORCE)
|
||||
set(OMNITRACE_PYTHON_VERSIONS
|
||||
"${_PY_VERSION}"
|
||||
CACHE INTERNAL "" FORCE)
|
||||
endif()
|
||||
|
||||
list(LENGTH OMNITRACE_PYTHON_VERSIONS _NUM_PYTHON_VERSIONS)
|
||||
list(LENGTH OMNITRACE_PYTHON_ROOT_DIRS _NUM_PYTHON_ROOT_DIRS)
|
||||
|
||||
if(NOT _NUM_PYTHON_VERSIONS EQUAL _NUM_PYTHON_ROOT_DIRS)
|
||||
omnitrace_message(
|
||||
WARNING
|
||||
"Error! Number of python versions : ${_NUM_PYTHON_VERSIONS}. VERSIONS :: ${OMNITRACE_PYTHON_VERSIONS}"
|
||||
)
|
||||
omnitrace_message(
|
||||
WARNING
|
||||
"Error! Number of python root directories : ${_NUM_PYTHON_ROOT_DIRS}. ROOT DIRS :: ${OMNITRACE_PYTHON_ROOT_DIRS}"
|
||||
)
|
||||
omnitrace_message(
|
||||
FATAL_ERROR
|
||||
"Error! Number of python versions != number of python root directories")
|
||||
endif()
|
||||
|
||||
file(GLOB_RECURSE PYTHON_FILES ${CMAKE_CURRENT_SOURCE_DIR}/omnitrace/*.py)
|
||||
foreach(_IN ${PYTHON_FILES})
|
||||
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/omnitrace"
|
||||
"${PROJECT_BINARY_DIR}/python/omnitrace" _OUT "${_IN}")
|
||||
configure_file(${_IN} ${_OUT} @ONLY)
|
||||
install(
|
||||
FILES ${_OUT}
|
||||
DESTINATION ${CMAKE_INSTALL_PYTHONDIR}/omnitrace
|
||||
OPTIONAL)
|
||||
endforeach()
|
||||
|
||||
omnitrace_python_console_script("omnitrace-python" "omnitrace")
|
||||
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_INSTALL_LIBDIR}/python
|
||||
COMMAND ${CMAKE_COMMAND} -E create_symlink ../../python
|
||||
${CMAKE_INSTALL_LIBDIR}/python/site-packages
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
|
||||
set(_INDEX 0)
|
||||
foreach(_VERSION ${OMNITRACE_PYTHON_VERSIONS})
|
||||
# add_library(libpyomnitrace MODULE ${pysources} ${pyheaders})
|
||||
list(GET OMNITRACE_PYTHON_ROOT_DIRS ${_INDEX} Python3_ROOT_DIR)
|
||||
omnitrace_pybind11_add_module(
|
||||
libpyomnitrace-${_VERSION} MODULE
|
||||
PYTHON_VERSION ${_VERSION}
|
||||
VISIBILITY "hidden" ${pysources} ${pyheaders})
|
||||
omnitrace_configure_pytarget(libpyomnitrace-${_VERSION} ${_VERSION})
|
||||
|
||||
if(OMNITRACE_USE_PYTHON)
|
||||
omnitrace_python_console_script(
|
||||
"omnitrace-python" "omnitrace"
|
||||
VERSION ${_VERSION}
|
||||
ROOT_DIR "${Python3_ROOT_DIR}")
|
||||
endif()
|
||||
math(EXPR _INDEX "${_INDEX} + 1")
|
||||
endforeach()
|
||||
|
||||
if(PYTHON_EXECUTABLE AND OFF)
|
||||
configure_file(${CMAKE_CURRENT_LIST_DIR}/setup.py.in
|
||||
${PROJECT_BINARY_DIR}/python/setup.py @ONLY)
|
||||
configure_file(${CMAKE_CURRENT_LIST_DIR}/setup.cfg.in
|
||||
|
||||
@@ -40,8 +40,9 @@ set_property(CACHE Python3_FIND_IMPLEMENTATIONS PROPERTY STRINGS
|
||||
# can edit them interactively. This disables support for multiple version/component
|
||||
# requirements.
|
||||
set(Python3_ARTIFACTS_INTERACTIVE
|
||||
ON
|
||||
CACHE BOOL "Create CMake cache entries so that users can edit them interactively")
|
||||
OFF
|
||||
CACHE BOOL "Create CMake cache entries so that users can edit them interactively"
|
||||
FORCE)
|
||||
|
||||
# if("${Python3_USE_STATIC_LIBS}" STREQUAL "ANY") set(Python3_USE_STATIC_LIBS "OFF" CACHE
|
||||
# STRING "If ON, only static libs; if OFF, only shared libs; if ANY, shared then static")
|
||||
@@ -60,158 +61,7 @@ foreach(_VAR FIND_STRATEGY FIND_VIRTUALENV FIND_FRAMEWORK FIND_IMPLEMENTATIONS
|
||||
endforeach()
|
||||
|
||||
# display version
|
||||
omnitrace_add_feature(OMNITRACE_PYTHON_VERSION "Python version for omnitrace" DOC)
|
||||
|
||||
# search hint
|
||||
if(PYTHON_ROOT_DIR AND NOT Python3_ROOT_DIR)
|
||||
set(Python3_ROOT_DIR ${PYTHON_ROOT_DIR})
|
||||
endif()
|
||||
|
||||
# legacy specification of interpreter
|
||||
if(PYTHON_EXECUTABLE AND NOT Python3_EXECUTABLE)
|
||||
set(Python3_EXECUTABLE
|
||||
"${PYTHON_EXECUTABLE}"
|
||||
CACHE FILEPATH "Path to Python3 interpreter")
|
||||
endif()
|
||||
|
||||
# default python types to search for
|
||||
set(Python_ADDITIONAL_VERSIONS
|
||||
"3.9;3.8;3.7;3.6"
|
||||
CACHE STRING "Python versions supported by omnitrace")
|
||||
|
||||
# override types to search for
|
||||
if(OMNITRACE_PYTHON_VERSION)
|
||||
set(Python_ADDITIONAL_VERSIONS
|
||||
${OMNITRACE_PYTHON_VERSION}
|
||||
CACHE STRING "Python versions supported by omnitrace" FORCE)
|
||||
elseif(PYBIND11_PYTHON_VERSION)
|
||||
set(Python_ADDITIONAL_VERSIONS
|
||||
${PYBIND11_PYTHON_VERSION}
|
||||
CACHE STRING "Python versions supported by omnitrace")
|
||||
endif()
|
||||
|
||||
# unset the version strings
|
||||
if(_PYVERSION_LAST AND (OMNITRACE_PYTHON_VERSION VERSION_LESS _PYVERSION_LAST
|
||||
OR OMNITRACE_PYTHON_VERSION VERSION_GREATER _PYVERSION_LAST))
|
||||
unset(OMNITRACE_PYTHON_VERSION CACHE)
|
||||
unset(PYBIND11_PYTHON_VERSION CACHE)
|
||||
unset(CMAKE_INSTALL_PYTHONDIR CACHE)
|
||||
endif()
|
||||
|
||||
# if OMNITRACE_PYTHON_VERSION specified, set to desired python version
|
||||
set(_PYVERSION ${OMNITRACE_PYTHON_VERSION})
|
||||
|
||||
# if OMNITRACE_PYTHON_VERSION is not set but PYBIND11_PYTHON_VERSION is
|
||||
if("${_PYVERSION}" STREQUAL "" AND PYBIND11_PYTHON_VERSION)
|
||||
set(_PYVERSION ${PYBIND11_PYTHON_VERSION})
|
||||
endif()
|
||||
|
||||
# basically just used to get Python3_SITEARCH for installation
|
||||
find_package(Python3 ${_PYVERSION} MODULE ${OMNITRACE_FIND_REQUIREMENT}
|
||||
COMPONENTS Interpreter Development)
|
||||
|
||||
# executable
|
||||
set(PYTHON_EXECUTABLE
|
||||
"${Python3_EXECUTABLE}"
|
||||
CACHE FILEPATH "Set via Python3_EXECUTABLE (omnitrace)" FORCE)
|
||||
# includes
|
||||
if(Python3_INCLUDE_DIR AND NOT Python3_INCLUDE_DIRS)
|
||||
set(Python3_INCLUDE_DIRS ${Python3_INCLUDE_DIR})
|
||||
endif()
|
||||
if(Python3_INCLUDE_DIRS)
|
||||
set(PYTHON_INCLUDE_DIR
|
||||
"${Python3_INCLUDE_DIRS}"
|
||||
CACHE PATH "Set via Python3_INCLUDE_DIR (omnitrace)" FORCE)
|
||||
set(PYTHON_INCLUDE_DIRS
|
||||
"${Python3_INCLUDE_DIRS}"
|
||||
CACHE PATH "Set via Python3_INCLUDE_DIRS (omnitrace)" FORCE)
|
||||
endif()
|
||||
# libraries
|
||||
set(PYTHON_LIBRARY_DEBUG
|
||||
"${Python3_LIBRARY_DEBUG}"
|
||||
CACHE FILEPATH "Set via Python3_LIBRARY_DEBUG (omnitrace)" FORCE)
|
||||
set(PYTHON_LIBRARY_RELEASE
|
||||
"${Python3_LIBRARY_RELEASE}"
|
||||
CACHE FILEPATH "Set via Python3_LIBRARY_DEBUG (omnitrace)" FORCE)
|
||||
if(Python3_LIBRARY_RELEASE)
|
||||
set(PYTHON_LIBRARY
|
||||
"${Python3_LIBRARY_RELEASE}"
|
||||
CACHE FILEPATH "Set via Python3_LIBRARY (omnitrace)" FORCE)
|
||||
set(PYTHON_LIBRARIES
|
||||
"${Python3_LIBRARY_RELEASE}"
|
||||
CACHE FILEPATH "Set via Python3_LIBRARIES (omnitrace)" FORCE)
|
||||
else(Python3_LIBRARY_DEBUG)
|
||||
set(PYTHON_LIBRARY
|
||||
"${Python3_LIBRARY_DEBUG}"
|
||||
CACHE FILEPATH "Set via Python3_LIBRARY (omnitrace)" FORCE)
|
||||
set(PYTHON_LIBRARIES
|
||||
"${Python3_LIBRARY_DEBUG}"
|
||||
CACHE FILEPATH "Set via Python3_LIBRARIES (omnitrace)" FORCE)
|
||||
endif()
|
||||
set(PYTHON_LIBRARY_DIRS
|
||||
"${Python3_LIBRARY_DIRS}"
|
||||
CACHE PATH "Set via Python3_LIBRARY_DIRS (omnitrace)" FORCE)
|
||||
set(PYTHON_LINK_OPTIONS
|
||||
"${Python3_LINK_OPTIONS}"
|
||||
CACHE STRING "Set via Python3_LINK_OPTIONS (omnitrace)" FORCE)
|
||||
|
||||
# module
|
||||
set(PYTHON_MODULE_EXTENSION
|
||||
"${Python3_MODULE_EXTENSION}"
|
||||
CACHE STRING "Set via Python3_MODULE_EXTENSION (omnitrace)" FORCE)
|
||||
set(PYTHON_MODULE_PREFIX
|
||||
"${Python3_MODULE_PREFIX}"
|
||||
CACHE STRING "Set via Python3_MODULE_PREFIX (omnitrace)" FORCE)
|
||||
|
||||
# version
|
||||
set(PYTHON_VERSION
|
||||
"${Python3_VERSION}"
|
||||
CACHE STRING "Set via Python3_VERSION (omnitrace)" FORCE)
|
||||
set(PYTHON_VERSION_MAJOR
|
||||
"${Python3_VERSION_MAJOR}"
|
||||
CACHE STRING "Set via Python3_VERSION_MAJOR (omnitrace)" FORCE)
|
||||
set(PYTHON_VERSION_MINOR
|
||||
"${Python3_VERSION_MINOR}"
|
||||
CACHE STRING "Set via Python3_VERSION_MINOR (omnitrace)" FORCE)
|
||||
|
||||
# find_package
|
||||
set(PythonInterp_FOUND ${Python3_Interpreter_FOUND})
|
||||
set(PythonLibs_FOUND ${Python3_Development_FOUND})
|
||||
|
||||
# set OMNITRACE_PYTHON_VERSION if we have the python version
|
||||
if(PYTHON_VERSION_STRING)
|
||||
set(OMNITRACE_PYTHON_VERSION
|
||||
"${PYTHON_VERSION_STRING}"
|
||||
CACHE STRING "Python version for omnitrace")
|
||||
endif()
|
||||
|
||||
# if either not found, disable
|
||||
if(NOT Python3_FOUND)
|
||||
set(OMNITRACE_USE_PYTHON OFF)
|
||||
set(OMNITRACE_BUILD_PYTHON OFF)
|
||||
omnitrace_inform_empty_interface(omnitrace-python "Python embedded interpreter")
|
||||
omnitrace_inform_empty_interface(omnitrace-plotting "Python plotting from C++")
|
||||
else()
|
||||
set(OMNITRACE_PYTHON_VERSION
|
||||
"${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}"
|
||||
CACHE STRING "Python version for omnitrace")
|
||||
omnitrace_add_feature(PYTHON_EXECUTABLE "Python executable")
|
||||
endif()
|
||||
|
||||
# C++ standard
|
||||
if(NOT MSVC)
|
||||
if(NOT "${PYBIND11_CPP_STANDARD}" STREQUAL "-std=c++${CMAKE_CXX_STANDARD}")
|
||||
set(PYBIND11_CPP_STANDARD
|
||||
-std=c++${CMAKE_CXX_STANDARD}
|
||||
CACHE STRING "PyBind11 CXX standard" FORCE)
|
||||
endif()
|
||||
else()
|
||||
if(NOT "${PYBIND11_CPP_STANDARD}" STREQUAL "/std:c++${CMAKE_CXX_STANDARD}")
|
||||
set(PYBIND11_CPP_STANDARD
|
||||
/std:c++${CMAKE_CXX_STANDARD}
|
||||
CACHE STRING "PyBind11 CXX standard" FORCE)
|
||||
endif()
|
||||
endif()
|
||||
omnitrace_add_feature(OMNITRACE_PYTHON_VERSIONS "Python version for omnitrace" DOC)
|
||||
|
||||
option(PYBIND11_INSTALL "Enable Pybind11 installation" OFF)
|
||||
|
||||
@@ -220,38 +70,17 @@ if(OMNITRACE_BUILD_PYTHON AND NOT TARGET pybind11)
|
||||
omnitrace_checkout_git_submodule(
|
||||
RECURSIVE
|
||||
RELATIVE_PATH external/pybind11
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/external/timemory
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
REPO_URL https://github.com/jrmadsen/pybind11.git
|
||||
REPO_BRANCH master)
|
||||
REPO_BRANCH omnitrace)
|
||||
|
||||
# add PyBind11 to project omnitrace_save_variables(IPO VARIABLES
|
||||
# CMAKE_INTERPROCEDURAL_OPTIMIZATION)
|
||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)
|
||||
add_subdirectory(${PROJECT_SOURCE_DIR}/external/timemory/external/pybind11)
|
||||
# omnitrace_restore_variables(IPO VARIABLES CMAKE_INTERPROCEDURAL_OPTIMIZATION)
|
||||
endif()
|
||||
|
||||
if(NOT PYBIND11_PYTHON_VERSION)
|
||||
unset(PYBIND11_PYTHON_VERSION CACHE)
|
||||
execute_process(
|
||||
COMMAND
|
||||
${PYTHON_EXECUTABLE} -c
|
||||
"import sys; print('{}.{}'.format(sys.version_info[0], sys.version_info[1]))"
|
||||
OUTPUT_VARIABLE PYTHON_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
|
||||
set(PYBIND11_PYTHON_VERSION
|
||||
"${PYTHON_VERSION}"
|
||||
CACHE STRING "Python version")
|
||||
endif()
|
||||
|
||||
omnitrace_add_feature(PYBIND11_CPP_STANDARD "PyBind11 C++ standard")
|
||||
omnitrace_add_feature(PYBIND11_PYTHON_VERSION "PyBind11 Python version")
|
||||
|
||||
if(NOT "${OMNITRACE_PYTHON_VERSION}" MATCHES "${PYBIND11_PYTHON_VERSION}*")
|
||||
message(STATUS "OMNITRACE_PYTHON_VERSION is set to ${OMNITRACE_PYTHON_VERSION}")
|
||||
message(STATUS "PYBIND11_PYTHON_VERSION is set to ${PYBIND11_PYTHON_VERSION}")
|
||||
message(
|
||||
FATAL_ERROR "Mismatched 'OMNITRACE_PYTHON_VERSION' and 'PYBIND11_PYTHON_VERSION'")
|
||||
if(NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION)
|
||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)
|
||||
endif()
|
||||
set(PYBIND11_NOPYTHON ON)
|
||||
omnitrace_save_variables(IPO VARIABLES CMAKE_INTERPROCEDURAL_OPTIMIZATION)
|
||||
add_subdirectory(${PROJECT_SOURCE_DIR}/external/pybind11)
|
||||
omnitrace_restore_variables(IPO VARIABLES CMAKE_INTERPROCEDURAL_OPTIMIZATION)
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
@@ -261,189 +90,3 @@ execute_process(
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
|
||||
|
||||
string(REPLACE " " " " OMNITRACE_INSTALL_DATE "${OMNITRACE_INSTALL_DATE}")
|
||||
|
||||
if(SKBUILD)
|
||||
set(OMNITRACE_INSTALL_PYTHON
|
||||
"prefix"
|
||||
CACHE STRING "SKBUILD forced python install type" FORCE)
|
||||
else()
|
||||
set(OMNITRACE_INSTALL_PYTHON
|
||||
"lib"
|
||||
CACHE STRING "Installation type for python (prefix, lib, or global)")
|
||||
endif()
|
||||
|
||||
omnitrace_add_feature(OMNITRACE_INSTALL_PYTHON
|
||||
"Installation type for python (prefix, lib, or global)")
|
||||
|
||||
if(SKBUILD OR "${OMNITRACE_INSTALL_PYTHON}" STREQUAL "prefix")
|
||||
set(CMAKE_INSTALL_PYTHONDIR
|
||||
${CMAKE_INSTALL_PREFIX}
|
||||
CACHE PATH "Installation directory for python")
|
||||
elseif(SPACK_BUILD OR "${OMNITRACE_INSTALL_PYTHON}" STREQUAL "lib")
|
||||
set(CMAKE_INSTALL_PYTHONDIR
|
||||
lib/python${PYBIND11_PYTHON_VERSION}/site-packages
|
||||
CACHE PATH "Installation directory for python")
|
||||
else()
|
||||
string(REPLACE "\\" "/" Python3_SITEARCH "${Python3_SITEARCH}")
|
||||
set(CMAKE_INSTALL_PYTHONDIR ${Python3_SITEARCH})
|
||||
omnitrace_add_feature(Python3_SITEARCH
|
||||
"site-packages directory of python installation")
|
||||
set(_REMOVE OFF)
|
||||
# make the directory if it doesn't exist
|
||||
if(NOT EXISTS ${Python3_SITEARCH}/omnitrace)
|
||||
set(_REMOVE ON)
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${Python3_SITEARCH}/omnitrace
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
ERROR_QUIET)
|
||||
endif()
|
||||
# figure out if we can install to Python3_SITEARCH
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -E touch ${Python3_SITEARCH}/omnitrace/__init__.py
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
ERROR_VARIABLE ERR_MSG
|
||||
RESULT_VARIABLE ERR_CODE)
|
||||
# remove the directory if we created it
|
||||
if(_REMOVE)
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -E remove_directory ${Python3_SITEARCH}/omnitrace
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
ERROR_QUIET)
|
||||
endif()
|
||||
# check the error code of the touch command
|
||||
if(ERR_CODE)
|
||||
if("${OMNITRACE_INSTALL_PYTHON}" STREQUAL "global")
|
||||
message(
|
||||
FATAL_ERROR
|
||||
"omnitrace could not install python files to ${Python3_SITEARCH} (not writable):\n${ERR_MSG}"
|
||||
)
|
||||
endif()
|
||||
# get the python directory name, e.g. 'python3.6' from
|
||||
# '/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6'
|
||||
get_filename_component(PYDIR "${Python3_STDLIB}" NAME)
|
||||
omnitrace_add_feature(Python3_STDLIB
|
||||
"standard-library directory of python installation")
|
||||
# Should not be CMAKE_INSTALL_LIBDIR! Python won't look in a lib64 folder
|
||||
set(CMAKE_INSTALL_PYTHONDIR lib/${PYDIR}/site-packages)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(OMNITRACE_BUILD_PYTHON OR pybind11_FOUND)
|
||||
set(_PYBIND11_INCLUDE_DIRS)
|
||||
foreach(_TARG pybind11 pybind11::pybind11 pybind11::module)
|
||||
if(TARGET ${_TARG})
|
||||
get_target_property(_INCLUDE_DIR ${_TARG} INTERFACE_INCLUDE_DIRECTORIES)
|
||||
if(_INCLUDE_DIR)
|
||||
list(APPEND _PYBIND11_INCLUDE_DIRS ${_INCLUDE_DIR})
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
if(_PYBIND11_INCLUDE_DIRS)
|
||||
list(REMOVE_DUPLICATES _PYBIND11_INCLUDE_DIRS)
|
||||
endif()
|
||||
omnitrace_target_compile_definitions(omnitrace-python INTERFACE OMNITRACE_USE_PYTHON)
|
||||
if(NOT APPLE)
|
||||
target_link_libraries(omnitrace-python INTERFACE ${PYTHON_LIBRARIES})
|
||||
endif()
|
||||
if(PYTHON_INCLUDE_DIRS)
|
||||
target_include_directories(omnitrace-python SYSTEM
|
||||
INTERFACE ${PYTHON_INCLUDE_DIRS})
|
||||
endif()
|
||||
if(PYBIND11_INCLUDE_DIRS)
|
||||
target_include_directories(omnitrace-python SYSTEM
|
||||
INTERFACE ${PYBIND11_INCLUDE_DIRS})
|
||||
endif()
|
||||
if(PYBIND11_INCLUDE_DIR)
|
||||
target_include_directories(omnitrace-python SYSTEM
|
||||
INTERFACE $<BUILD_INTERFACE:${PYBIND11_INCLUDE_DIR}>)
|
||||
endif()
|
||||
if(_PYBIND11_INCLUDE_DIRS)
|
||||
target_include_directories(omnitrace-python SYSTEM
|
||||
INTERFACE $<BUILD_INTERFACE:${_PYBIND11_INCLUDE_DIRS}>)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.18)
|
||||
target_link_libraries(omnitrace-python INTERFACE "-undefined dynamic_lookup")
|
||||
else()
|
||||
target_link_libraries(
|
||||
omnitrace-python
|
||||
INTERFACE "$<$<LINK_LANGUAGE:CXX>:-undefined dynamic_lookup>")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
# Windows produces:
|
||||
#
|
||||
# CMake Warning (dev) at tests/test-python-install-import.cmake:3 (SET): Syntax error
|
||||
# in cmake code at
|
||||
# C:/projects/omnitrace/build-omnitrace/tests/test-python-install-import.cmake:3 when
|
||||
# parsing string C:\Python36-x64\Lib\site-packages Invalid escape sequence \P
|
||||
string(REPLACE "\\" "/" INSTALL_PYTHONDIR "${CMAKE_INSTALL_PYTHONDIR}")
|
||||
else()
|
||||
set(INSTALL_PYTHONDIR "${CMAKE_INSTALL_PYTHONDIR}")
|
||||
endif()
|
||||
|
||||
configure_file(
|
||||
${PROJECT_SOURCE_DIR}/external/timemory/cmake/Templates/test-python-install-import.cmake.in
|
||||
${PROJECT_BINARY_DIR}/tests/test-python-install-import.cmake
|
||||
@ONLY)
|
||||
unset(INSTALL_PYTHONDIR)
|
||||
|
||||
omnitrace_add_feature(CMAKE_INSTALL_PYTHONDIR
|
||||
"Installation prefix of the python bindings")
|
||||
|
||||
set(_PYVERSION_LAST
|
||||
"${OMNITRACE_PYTHON_VERSION}"
|
||||
CACHE INTERNAL "Last version" FORCE)
|
||||
|
||||
find_package(PythonInterp ${OMNITRACE_PYTHON_VERSION} EXACT REQUIRED)
|
||||
find_package(PythonLibs ${OMNITRACE_PYTHON_VERSION} EXACT REQUIRED)
|
||||
# find_package(PythonExtensions REQUIRED)
|
||||
|
||||
if("${PYTHON_MODULE_EXTENSION}" STREQUAL "")
|
||||
execute_process(
|
||||
COMMAND
|
||||
"${Python3_EXECUTABLE}" "-c" "
|
||||
from distutils import sysconfig as s;import sys;import struct;
|
||||
print('.'.join(str(v) for v in sys.version_info));
|
||||
print(sys.prefix);
|
||||
print(s.get_python_inc(plat_specific=True));
|
||||
print(s.get_python_lib(plat_specific=True));
|
||||
print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'));
|
||||
print(hasattr(sys, 'gettotalrefcount')+0);
|
||||
print(struct.calcsize('@P'));
|
||||
print(s.get_config_var('LDVERSION') or s.get_config_var('VERSION'));
|
||||
print(s.get_config_var('LIBDIR') or '');
|
||||
print(s.get_config_var('MULTIARCH') or '');
|
||||
"
|
||||
RESULT_VARIABLE _PYTHON_SUCCESS
|
||||
OUTPUT_VARIABLE _PYTHON_VALUES
|
||||
ERROR_VARIABLE _PYTHON_ERROR_VALUE)
|
||||
|
||||
if(_PYTHON_SUCCESS MATCHES 0)
|
||||
# Convert the process output into a list
|
||||
if(WIN32)
|
||||
string(REGEX REPLACE "\\\\" "/" _PYTHON_VALUES ${_PYTHON_VALUES})
|
||||
endif()
|
||||
string(REGEX REPLACE ";" "\\\\;" _PYTHON_VALUES ${_PYTHON_VALUES})
|
||||
string(REGEX REPLACE "\n" ";" _PYTHON_VALUES ${_PYTHON_VALUES})
|
||||
list(GET _PYTHON_VALUES 0 _PYTHON_VERSION_LIST)
|
||||
list(GET _PYTHON_VALUES 1 PYTHON_PREFIX)
|
||||
list(GET _PYTHON_VALUES 2 PYTHON_INCLUDE_DIR)
|
||||
list(GET _PYTHON_VALUES 3 PYTHON_SITE_PACKAGES)
|
||||
list(GET _PYTHON_VALUES 4 PYTHON_MODULE_EXTENSION)
|
||||
list(GET _PYTHON_VALUES 5 PYTHON_IS_DEBUG)
|
||||
list(GET _PYTHON_VALUES 6 PYTHON_SIZEOF_VOID_P)
|
||||
list(GET _PYTHON_VALUES 7 PYTHON_LIBRARY_SUFFIX)
|
||||
list(GET _PYTHON_VALUES 8 PYTHON_LIBDIR)
|
||||
list(GET _PYTHON_VALUES 9 PYTHON_MULTIARCH)
|
||||
else()
|
||||
message(WARNING "${_PYTHON_ERROR_VALUE}")
|
||||
endif()
|
||||
|
||||
if("${PYTHON_MODULE_EXTENSION}" STREQUAL "")
|
||||
message(WARNING "Python module extension is empty!")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
# * Find python libraries This module finds the libraries corresponding to the Python
|
||||
# interpreter FindPythonInterp provides. This code sets the following variables:
|
||||
#
|
||||
# PYTHONLIBS_FOUND - have the Python libs been found PYTHON_PREFIX - path to the
|
||||
# Python installation PYTHON_LIBRARIES - path to the python library
|
||||
# PYTHON_INCLUDE_DIRS - path to where Python.h is found PYTHON_MODULE_EXTENSION -
|
||||
# lib extension, e.g. '.so' or '.pyd' PYTHON_MODULE_PREFIX - lib name prefix: usually an
|
||||
# empty string PYTHON_SITE_PACKAGES - path to installation site-packages
|
||||
# PYTHON_IS_DEBUG - whether the Python interpreter is a debug build
|
||||
#
|
||||
# Thanks to talljimbo for the patch adding the 'LDVERSION' config variable usage.
|
||||
|
||||
# =============================================================================
|
||||
# Copyright 2001-2009 Kitware, Inc. Copyright 2012 Continuum Analytics, Inc.
|
||||
#
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification, are
|
||||
# permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright notice, this list of
|
||||
# conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# * Neither the names of Kitware, Inc., the Insight Software Consortium, nor the names of
|
||||
# their contributors may be used to endorse or promote products derived from this
|
||||
# software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
# =============================================================================
|
||||
|
||||
# Checking for the extension makes sure that `LibsNew` was found and not just `Libs`.
|
||||
|
||||
set(_find_quiet)
|
||||
set(_find_required)
|
||||
set(_find_exact)
|
||||
|
||||
if(PyBind11Python_FIND_QUIETLY)
|
||||
set(_find_quiet QUIET)
|
||||
endif()
|
||||
|
||||
if(PyBind11Python_FIND_REQUIRED)
|
||||
set(_find_required REQUIRED)
|
||||
endif()
|
||||
|
||||
if(PyBind11Python_FIND_VERSION)
|
||||
set(_find_exact EXACT)
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED PyBind11Python_PYTHON)
|
||||
set(PyBind11Python_PYTHON Python3)
|
||||
if(PyBind11Python_FIND_VERSION AND "${PyBind11Python_FIND_VERSION}" VERSION_LESS 3.0)
|
||||
set(PyBind11Python_PYTHON Python2)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT PyBind11Python_COMPONENTS)
|
||||
set(PyBind11Python_COMPONENTS Interpreter Development)
|
||||
endif()
|
||||
|
||||
# Use the Python interpreter to find the libs.
|
||||
find_package(${PyBind11Python_PYTHON} ${PyBind11Python_FIND_VERSION} ${_find_exact} MODULE
|
||||
${_find_required} ${_find_quiet} COMPONENTS ${PyBind11Python_COMPONENTS})
|
||||
|
||||
# According to
|
||||
# https://stackoverflow.com/questions/646518/python-how-to-detect-debug-interpreter
|
||||
# testing whether sys has the gettotalrefcount function is a reliable, cross-platform way
|
||||
# to detect a CPython debug interpreter.
|
||||
#
|
||||
# The library suffix is from the config var LDVERSION sometimes, otherwise VERSION.
|
||||
# VERSION will typically be like "2.7" on unix, and "27" on windows.
|
||||
execute_process(
|
||||
COMMAND
|
||||
"${${PyBind11Python_PYTHON}_EXECUTABLE}" "-c"
|
||||
"
|
||||
import sys;import struct;
|
||||
import sysconfig as s
|
||||
USE_SYSCONFIG = sys.version_info >= (3, 10)
|
||||
if not USE_SYSCONFIG:
|
||||
from distutils import sysconfig as ds
|
||||
print('.'.join(str(v) for v in sys.version_info));
|
||||
print(sys.prefix);
|
||||
if USE_SYSCONFIG:
|
||||
scheme = s.get_default_scheme()
|
||||
if scheme == 'posix_local':
|
||||
# Debian's default scheme installs to /usr/local/ but we want to find headers in /usr/
|
||||
scheme = 'posix_prefix'
|
||||
print(s.get_path('platinclude', scheme))
|
||||
print(s.get_path('platlib'))
|
||||
else:
|
||||
print(ds.get_python_inc(plat_specific=True));
|
||||
print(ds.get_python_lib(plat_specific=True));
|
||||
print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'));
|
||||
print(hasattr(sys, 'gettotalrefcount')+0);
|
||||
print(struct.calcsize('@P'));
|
||||
print(s.get_config_var('LDVERSION') or s.get_config_var('VERSION'));
|
||||
print(s.get_config_var('LIBDIR') or '');
|
||||
print(s.get_config_var('MULTIARCH') or '');
|
||||
"
|
||||
RESULT_VARIABLE _PYTHON_SUCCESS
|
||||
OUTPUT_VARIABLE _PYTHON_VALUES
|
||||
ERROR_VARIABLE _PYTHON_ERROR_VALUE)
|
||||
|
||||
if(NOT _PYTHON_SUCCESS MATCHES 0)
|
||||
if(PyBind11Python_FIND_REQUIRED)
|
||||
message(FATAL_ERROR "Python config failure:\n${_PYTHON_ERROR_VALUE}")
|
||||
endif()
|
||||
set(PyBind11Python_FOUND FALSE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Convert the process output into a list
|
||||
if(WIN32)
|
||||
string(REGEX REPLACE "\\\\" "/" _PYTHON_VALUES ${_PYTHON_VALUES})
|
||||
endif()
|
||||
string(REGEX REPLACE ";" "\\\\;" _PYTHON_VALUES ${_PYTHON_VALUES})
|
||||
string(REGEX REPLACE "\n" ";" _PYTHON_VALUES ${_PYTHON_VALUES})
|
||||
list(GET _PYTHON_VALUES 0 _PYTHON_VERSION_LIST)
|
||||
list(GET _PYTHON_VALUES 1 PYTHON_PREFIX)
|
||||
list(GET _PYTHON_VALUES 2 PYTHON_INCLUDE_DIR)
|
||||
list(GET _PYTHON_VALUES 3 PYTHON_SITE_PACKAGES)
|
||||
list(GET _PYTHON_VALUES 4 PYTHON_MODULE_EXTENSION)
|
||||
list(GET _PYTHON_VALUES 5 PYTHON_IS_DEBUG)
|
||||
list(GET _PYTHON_VALUES 6 PYTHON_SIZEOF_VOID_P)
|
||||
list(GET _PYTHON_VALUES 7 PYTHON_LIBRARY_SUFFIX)
|
||||
list(GET _PYTHON_VALUES 8 PYTHON_LIBDIR)
|
||||
list(GET _PYTHON_VALUES 9 PYTHON_MULTIARCH)
|
||||
|
||||
# Make sure the Python has the same pointer-size as the chosen compiler Skip if
|
||||
# CMAKE_SIZEOF_VOID_P is not defined
|
||||
if(CMAKE_SIZEOF_VOID_P AND (NOT "${PYTHON_SIZEOF_VOID_P}" STREQUAL
|
||||
"${CMAKE_SIZEOF_VOID_P}"))
|
||||
if(PyBind11Python_FIND_REQUIRED)
|
||||
math(EXPR _PYTHON_BITS "${PYTHON_SIZEOF_VOID_P} * 8")
|
||||
math(EXPR _CMAKE_BITS "${CMAKE_SIZEOF_VOID_P} * 8")
|
||||
message(FATAL_ERROR "Python config failure: Python is ${_PYTHON_BITS}-bit, "
|
||||
"chosen compiler is ${_CMAKE_BITS}-bit")
|
||||
endif()
|
||||
set(PyBind11Python_FOUND FALSE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# The built-in FindPython didn't always give the version numbers
|
||||
string(REGEX REPLACE "\\." ";" _PYTHON_VERSION_LIST ${_PYTHON_VERSION_LIST})
|
||||
list(GET _PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
|
||||
list(GET _PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
|
||||
list(GET _PYTHON_VERSION_LIST 2 PYTHON_VERSION_PATCH)
|
||||
set(PYTHON_VERSION
|
||||
"${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.${PYTHON_VERSION_PATCH}")
|
||||
|
||||
# Make sure all directory separators are '/'
|
||||
string(REGEX REPLACE "\\\\" "/" PYTHON_PREFIX "${PYTHON_PREFIX}")
|
||||
string(REGEX REPLACE "\\\\" "/" PYTHON_INCLUDE_DIR "${PYTHON_INCLUDE_DIR}")
|
||||
string(REGEX REPLACE "\\\\" "/" PYTHON_SITE_PACKAGES "${PYTHON_SITE_PACKAGES}")
|
||||
|
||||
# We use PYTHON_INCLUDE_DIR, PYTHON_LIBRARY and PYTHON_DEBUG_LIBRARY for the cache entries
|
||||
# because they are meant to specify the location of a single library. We now set the
|
||||
# variables listed by the documentation for this module.
|
||||
set(PYTHON_EXECUTABLE "${${PyBind11Python_PYTHON}_EXECUTABLE}")
|
||||
set(PYTHON_INCLUDE_DIRS "${${PyBind11Python_PYTHON}_INCLUDE_DIRS}")
|
||||
set(PYTHON_LIBRARIES "${${PyBind11Python_PYTHON}_LIBRARIES}")
|
||||
if(NOT PYTHON_DEBUG_LIBRARY)
|
||||
set(PYTHON_DEBUG_LIBRARY "")
|
||||
endif()
|
||||
set(PYTHON_DEBUG_LIBRARIES "${PYTHON_DEBUG_LIBRARY}")
|
||||
|
||||
# find_package_message(PyBind11Python "Found PyBind11Python: ${PYTHON_LIBRARIES}"
|
||||
# "${PYTHON_EXECUTABLE}${PYTHON_VERSION_STRING}")
|
||||
|
||||
if(NOT PYTHON_MODULE_PREFIX)
|
||||
set(PYTHON_MODULE_PREFIX "")
|
||||
endif()
|
||||
@@ -0,0 +1,301 @@
|
||||
#
|
||||
function(OMNITRACE_FIND_PYTHON _VAR)
|
||||
set(options REQUIRED QUIET)
|
||||
set(args VERSION ROOT_DIR)
|
||||
set(kwargs COMPONENTS)
|
||||
cmake_parse_arguments(ARG "${options}" "${args}" "${kwargs}" ${ARGN})
|
||||
|
||||
if(ARG_QUIET)
|
||||
set(_QUIET "QUIET")
|
||||
endif()
|
||||
|
||||
if(ARG_VERSION)
|
||||
set(_EXACT "EXACT")
|
||||
endif()
|
||||
|
||||
if(ARG_REQUIRED)
|
||||
set(_FIND_REQUIREMENT "REQUIRED")
|
||||
endif()
|
||||
|
||||
if(NOT ARG_COMPONENTS)
|
||||
set(ARG_COMPONENTS Interpreter Development)
|
||||
endif()
|
||||
|
||||
set(Python3_ROOT_DIR "${ARG_ROOT_DIR}")
|
||||
set(Python3_FIND_STRATEGY "LOCATION")
|
||||
set(Python3_FIND_VIRTUALENV "FIRST")
|
||||
set(Python3_ARTIFACTS_INTERACTIVE OFF)
|
||||
|
||||
find_package(Python3 ${ARG_VERSION} ${_EXACT} ${_QUIET} MODULE ${_FIND_REQUIREMENT}
|
||||
COMPONENTS ${ARG_COMPONENTS})
|
||||
|
||||
set(${_VAR}_FOUND
|
||||
"${Python3_FOUND}"
|
||||
PARENT_SCOPE)
|
||||
if(NOT Python3_FOUND)
|
||||
set(${_VAR}_EXECUTABLE
|
||||
""
|
||||
PARENT_SCOPE)
|
||||
set(${_VAR}_ROOT_DIR
|
||||
""
|
||||
PARENT_SCOPE)
|
||||
set(${_VAR}_VERSION
|
||||
""
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
else()
|
||||
set(${_VAR}_EXECUTABLE
|
||||
"${Python3_EXECUTABLE}"
|
||||
PARENT_SCOPE)
|
||||
execute_process(
|
||||
COMMAND
|
||||
"${Python3_EXECUTABLE}" "-c"
|
||||
"import sys; print('.'.join(str(v) for v in [sys.version_info[0], sys.version_info[1]])); print(sys.prefix);"
|
||||
RESULT_VARIABLE _PYTHON_SUCCESS
|
||||
OUTPUT_VARIABLE _PYTHON_VALUES
|
||||
ERROR_VARIABLE _PYTHON_ERROR_VALUE)
|
||||
|
||||
if(_PYTHON_SUCCESS MATCHES 0)
|
||||
# Convert the process output into a list
|
||||
string(REGEX REPLACE ";" "\\\\;" _PYTHON_VALUES ${_PYTHON_VALUES})
|
||||
string(REGEX REPLACE "\n" ";" _PYTHON_VALUES ${_PYTHON_VALUES})
|
||||
list(GET _PYTHON_VALUES 0 _PYTHON_VERSION_LIST)
|
||||
list(GET _PYTHON_VALUES 1 _PYTHON_PREFIX)
|
||||
set(${_VAR}_ROOT_DIR
|
||||
"${_PYTHON_PREFIX}"
|
||||
PARENT_SCOPE)
|
||||
set(${_VAR}_VERSION
|
||||
"${_PYTHON_VERSION_LIST}"
|
||||
PARENT_SCOPE)
|
||||
else()
|
||||
omnitrace_message(WARNING "${_PYTHON_ERROR_VALUE}")
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
#
|
||||
# Internal: find the appropriate link time optimization flags for this compiler
|
||||
function(_OMNITRACE_PYBIND11_ADD_LTO_FLAGS target_name prefer_thin_lto)
|
||||
# Checks whether the given CXX/linker flags can compile and link a cxx file. cxxflags
|
||||
# and linkerflags are lists of flags to use. The result variable is a unique variable
|
||||
# name for each set of flags: the compilation result will be cached base on the result
|
||||
# variable. If the flags work, sets them in cxxflags_out/linkerflags_out internal
|
||||
# cache variables (in addition to ${result}).
|
||||
function(_PYBIND11_RETURN_IF_CXX_AND_LINKER_FLAGS_WORK result cxxflags linkerflags
|
||||
cxxflags_out linkerflags_out)
|
||||
include(CheckCXXCompilerFlag)
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${linkerflags})
|
||||
check_cxx_compiler_flag("${cxxflags}" ${result})
|
||||
if(${result})
|
||||
set(${cxxflags_out}
|
||||
"${cxxflags}"
|
||||
CACHE INTERNAL "" FORCE)
|
||||
set(${linkerflags_out}
|
||||
"${linkerflags}"
|
||||
CACHE INTERNAL "" FORCE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
if(NOT DEFINED PYBIND11_LTO_CXX_FLAGS)
|
||||
set(PYBIND11_LTO_CXX_FLAGS
|
||||
""
|
||||
CACHE INTERNAL "")
|
||||
set(PYBIND11_LTO_LINKER_FLAGS
|
||||
""
|
||||
CACHE INTERNAL "")
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
set(cxx_append "")
|
||||
set(linker_append "")
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT APPLE)
|
||||
# Clang Gold plugin does not support -Os; append -O3 to MinSizeRel builds
|
||||
# to override it
|
||||
set(linker_append ";$<$<CONFIG:MinSizeRel>:-O3>")
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
set(cxx_append ";-fno-fat-lto-objects")
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND prefer_thin_lto)
|
||||
_pybind11_return_if_cxx_and_linker_flags_work(
|
||||
HAS_FLTO_THIN "-flto=thin${cxx_append}" "-flto=thin${linker_append}"
|
||||
PYBIND11_LTO_CXX_FLAGS PYBIND11_LTO_LINKER_FLAGS)
|
||||
endif()
|
||||
|
||||
if(NOT HAS_FLTO_THIN)
|
||||
_pybind11_return_if_cxx_and_linker_flags_work(
|
||||
HAS_FLTO "-flto${cxx_append}" "-flto${linker_append}"
|
||||
PYBIND11_LTO_CXX_FLAGS PYBIND11_LTO_LINKER_FLAGS)
|
||||
endif()
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
|
||||
# Intel equivalent to LTO is called IPO
|
||||
_pybind11_return_if_cxx_and_linker_flags_work(
|
||||
HAS_INTEL_IPO "-ipo" "-ipo" PYBIND11_LTO_CXX_FLAGS
|
||||
PYBIND11_LTO_LINKER_FLAGS)
|
||||
elseif(MSVC)
|
||||
# cmake only interprets libraries as linker flags when they start with a -
|
||||
# (otherwise it converts /LTCG to \LTCG as if it was a Windows path). Luckily
|
||||
# MSVC supports passing flags with - instead of /, even if it is a bit
|
||||
# non-standard:
|
||||
_pybind11_return_if_cxx_and_linker_flags_work(
|
||||
HAS_MSVC_GL_LTCG "/GL" "-LTCG" PYBIND11_LTO_CXX_FLAGS
|
||||
PYBIND11_LTO_LINKER_FLAGS)
|
||||
endif()
|
||||
|
||||
if(PYBIND11_LTO_CXX_FLAGS)
|
||||
omnitrace_message(STATUS "${target_name} :: LTO enabled")
|
||||
else()
|
||||
omnitrace_message(
|
||||
STATUS
|
||||
"${target_name} :: LTO disabled (not supported by the compiler and/or linker)"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Enable LTO flags if found, except for Debug builds
|
||||
if(PYBIND11_LTO_CXX_FLAGS)
|
||||
target_compile_options(
|
||||
${target_name} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:${PYBIND11_LTO_CXX_FLAGS}>")
|
||||
endif()
|
||||
if(PYBIND11_LTO_LINKER_FLAGS)
|
||||
target_link_libraries(
|
||||
${target_name}
|
||||
PRIVATE "$<$<NOT:$<CONFIG:Debug>>:${PYBIND11_LTO_LINKER_FLAGS}>")
|
||||
endif()
|
||||
endfunction()
|
||||
#
|
||||
function(OMNITRACE_PYBIND11_ADD_MODULE target_name)
|
||||
set(options MODULE SHARED EXCLUDE_FROM_ALL NO_EXTRAS SYSTEM THIN_LTO LTO)
|
||||
set(args PYTHON_VERSION VISIBILITY CXX_STANDARD)
|
||||
set(kwargs)
|
||||
cmake_parse_arguments(ARG "${options}" "${args}" "${kwargs}" ${ARGN})
|
||||
|
||||
if(ARG_MODULE AND ARG_SHARED)
|
||||
omnitrace_message(FATAL_ERROR "Can't be both MODULE and SHARED")
|
||||
elseif(ARG_SHARED)
|
||||
set(lib_type SHARED)
|
||||
else()
|
||||
set(lib_type MODULE)
|
||||
endif()
|
||||
if(NOT ARG_VISIBILITY)
|
||||
set(ARG_VISIBILITY "hidden")
|
||||
endif()
|
||||
if(ARG_PYTHON_VERSION)
|
||||
set(PythonLibsNew_FIND_REQUIRED ON)
|
||||
endif()
|
||||
if(NOT ARG_CXX_STANDARD AND CMAKE_CXX_STANDARD)
|
||||
set(ARG_CXX_STANDARD ${CMAKE_CXX_STANDARD})
|
||||
elseif(NOT ARG_CXX_STANDARD)
|
||||
set(ARG_CXX_STANDARD 11)
|
||||
endif()
|
||||
if(ARG_EXCLUDE_FROM_ALL)
|
||||
set(exclude_from_all EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
|
||||
add_library(${target_name} ${lib_type} ${exclude_from_all} ${ARG_UNPARSED_ARGUMENTS})
|
||||
|
||||
target_link_libraries(${target_name} PRIVATE pybind11::module)
|
||||
|
||||
if(ARG_SYSTEM)
|
||||
set(inc_isystem SYSTEM)
|
||||
endif()
|
||||
|
||||
list(INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/source/python/cmake/Modules")
|
||||
find_package(PyBind11Python ${ARG_PYTHON_VERSION})
|
||||
|
||||
target_include_directories(
|
||||
${target_name} ${inc_isystem}
|
||||
PRIVATE ${PYBIND11_INCLUDE_DIR} # from project CMakeLists.txt
|
||||
PRIVATE ${pybind11_INCLUDE_DIR} # from pybind11Config
|
||||
PRIVATE ${Python3_INCLUDE_DIRS})
|
||||
|
||||
# Python debug libraries expose slightly different objects
|
||||
# https://docs.python.org/3.6/c-api/intro.html#debugging-builds
|
||||
# https://stackoverflow.com/questions/39161202/how-to-work-around-missing-pymodule-create2-in-amd64-win-python35-d-lib
|
||||
if(PYTHON_IS_DEBUG)
|
||||
target_compile_definitions(${target_name} PRIVATE Py_DEBUG)
|
||||
endif()
|
||||
|
||||
# The prefix and extension are provided by FindPythonLibsNew.cmake
|
||||
set_target_properties(${target_name} PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}")
|
||||
set_target_properties(${target_name} PROPERTIES SUFFIX "${PYTHON_MODULE_EXTENSION}")
|
||||
|
||||
# -fvisibility=hidden is required to allow multiple modules compiled against different
|
||||
# pybind versions to work properly, and for some features (e.g. py::module_local). We
|
||||
# force it on everything inside the `pybind11` namespace; also turning it on for a
|
||||
# pybind module compilation here avoids potential warnings or issues from having mixed
|
||||
# hidden/non-hidden types.
|
||||
set_target_properties(${target_name} PROPERTIES CXX_VISIBILITY_PRESET
|
||||
"${ARG_VISIBILITY}")
|
||||
set_target_properties(${target_name} PROPERTIES CUDA_VISIBILITY_PRESET
|
||||
"${ARG_VISIBILITY}")
|
||||
|
||||
if(WIN32 OR CYGWIN)
|
||||
# Link against the Python shared library on Windows
|
||||
target_link_libraries(${target_name} PRIVATE ${Python3_LIBRARIES})
|
||||
elseif(APPLE)
|
||||
# It's quite common to have multiple copies of the same Python version installed
|
||||
# on one's system. E.g.: one copy from the OS and another copy that's statically
|
||||
# linked into an application like Blender or Maya. If we link our plugin library
|
||||
# against the OS Python here and import it into Blender or Maya later on, this
|
||||
# will cause segfaults when multiple conflicting Python instances are active at
|
||||
# the same time (even when they are of the same version).
|
||||
|
||||
# Windows is not affected by this issue since it handles DLL imports differently.
|
||||
# The solution for Linux and Mac OS is simple: we just don't link against the
|
||||
# Python library. The resulting shared library will have missing symbols, but
|
||||
# that's perfectly fine -- they will be resolved at import time.
|
||||
|
||||
target_link_libraries(${target_name} PRIVATE "-undefined dynamic_lookup")
|
||||
|
||||
if(ARG_SHARED)
|
||||
# Suppress CMake >= 3.0 warning for shared libraries
|
||||
set_target_properties(${target_name} PROPERTIES MACOSX_RPATH ON)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Make sure C++11/14 are enabled
|
||||
set_target_properties(${target_name} PROPERTIES CXX_STANDARD ${ARG_CXX_STANDARD}
|
||||
CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
if(ARG_NO_EXTRAS)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(ARG_LTO OR ARG_THIN_LTO)
|
||||
_omnitrace_pybind11_add_lto_flags(${target_name} ${ARG_THIN_LTO})
|
||||
endif()
|
||||
|
||||
if(NOT MSVC AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo)
|
||||
# Strip unnecessary sections of the binary on Linux/Mac OS
|
||||
if(CMAKE_STRIP)
|
||||
if(APPLE)
|
||||
add_custom_command(
|
||||
TARGET ${target_name}
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_STRIP} -x $<TARGET_FILE:${target_name}>)
|
||||
else()
|
||||
add_custom_command(
|
||||
TARGET ${target_name}
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_STRIP} $<TARGET_FILE:${target_name}>)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
# /MP enables multithreaded builds (relevant when there are many files), /bigobj
|
||||
# is needed for bigger binding projects due to the limit to 64k addressable
|
||||
# sections
|
||||
target_compile_options(${target_name} PRIVATE /bigobj)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.11)
|
||||
target_compile_options(${target_name} PRIVATE $<$<NOT:$<CONFIG:Debug>>:/MP>)
|
||||
else()
|
||||
# Only set these options for C++ files. This is important so that, for
|
||||
# instance, projects that include other types of source files like CUDA .cu
|
||||
# files don't get these options propagated to nvcc since that would cause the
|
||||
# build to fail.
|
||||
target_compile_options(
|
||||
${target_name}
|
||||
PRIVATE $<$<NOT:$<CONFIG:Debug>>:$<$<COMPILE_LANGUAGE:CXX>:/MP>>)
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
@@ -1,51 +0,0 @@
|
||||
# ########################################################################################
|
||||
#
|
||||
# omnitrace (Python)
|
||||
#
|
||||
# ########################################################################################
|
||||
|
||||
file(GLOB_RECURSE PYTHON_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.py)
|
||||
foreach(_IN ${PYTHON_FILES})
|
||||
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}/python/omnitrace"
|
||||
_OUT "${_IN}")
|
||||
configure_file(${_IN} ${_OUT} @ONLY)
|
||||
install(
|
||||
FILES ${_OUT}
|
||||
DESTINATION ${CMAKE_INSTALL_PYTHONDIR}/omnitrace
|
||||
OPTIONAL)
|
||||
endforeach()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Console scripts
|
||||
#
|
||||
function(OMNITRACE_PYTHON_CONSOLE_SCRIPT SCRIPT_NAME SCRIPT_SUBMODULE)
|
||||
|
||||
configure_file(${PROJECT_SOURCE_DIR}/cmake/Templates/console-script.in
|
||||
${PROJECT_BINARY_DIR}/bin/${SCRIPT_NAME} @ONLY)
|
||||
|
||||
if(CMAKE_INSTALL_PYTHONDIR)
|
||||
install(
|
||||
PROGRAMS ${PROJECT_BINARY_DIR}/bin/${SCRIPT_NAME}
|
||||
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
OPTIONAL)
|
||||
endif()
|
||||
|
||||
if(OMNITRACE_BUILD_TESTING OR OMNITRACE_BUILD_PYTHON)
|
||||
add_test(
|
||||
NAME ${SCRIPT_NAME}-console-script-test
|
||||
COMMAND ${PROJECT_BINARY_DIR}/bin/${SCRIPT_NAME} --help
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
|
||||
set_tests_properties(
|
||||
${SCRIPT_NAME}-console-script-test
|
||||
PROPERTIES ENVIRONMENT
|
||||
"PYTHONPATH=${PROJECT_BINARY_DIR}/python:$ENV{PYTHONPATH}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
if(NOT PYTHON_EXECUTABLE)
|
||||
set(PYTHON_EXECUTABLE "python${OMNITRACE_PYTHON_VERSION}")
|
||||
endif()
|
||||
|
||||
if(OMNITRACE_USE_PYTHON)
|
||||
omnitrace_python_console_script("omnitrace-python" "omnitrace")
|
||||
endif()
|
||||
@@ -1,4 +1,4 @@
|
||||
#!@PYTHON_EXECUTABLE@
|
||||
#!/usr/bin/env python@_VERSION@
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2022 Advanced Micro Devices, Inc. All Rights Reserved.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!@PYTHON_EXECUTABLE@
|
||||
#!/usr/bin/env python@_VERSION@
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2022 Advanced Micro Devices, Inc. All Rights Reserved.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!@PYTHON_EXECUTABLE@
|
||||
#!/usr/bin/env python@_VERSION@
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2022 Advanced Micro Devices, Inc. All Rights Reserved.
|
||||
|
||||
Yeni konuda referans
Bir kullanıcı engelle