Add 'projects/rocprofiler-systems/' from commit '92e1d84c72c9321d79a1866e0090fae0215e6557'
git-subtree-dir: projects/rocprofiler-systems git-subtree-mainline:ee9e74df21git-subtree-split:92e1d84c72
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
# Python configuration
|
||||
#
|
||||
|
||||
# include guard
|
||||
include_guard(DIRECTORY)
|
||||
|
||||
# Stops lookup as soon as a version satisfying version constraints is found.
|
||||
set(Python3_FIND_STRATEGY
|
||||
"LOCATION"
|
||||
CACHE STRING
|
||||
"Stops lookup as soon as a version satisfying version constraints is found"
|
||||
)
|
||||
|
||||
# virtual environment is used before any other standard paths to look-up for the
|
||||
# interpreter
|
||||
set(Python3_FIND_VIRTUALENV
|
||||
"FIRST"
|
||||
CACHE STRING
|
||||
"Virtual environment is used before any other standard paths"
|
||||
)
|
||||
set_property(CACHE Python3_FIND_VIRTUALENV PROPERTY STRINGS "FIRST;LAST;NEVER")
|
||||
|
||||
if(APPLE)
|
||||
set(Python3_FIND_FRAMEWORK
|
||||
"LAST"
|
||||
CACHE STRING
|
||||
"Order of preference between Apple-style and unix-style package components"
|
||||
)
|
||||
set_property(CACHE Python3_FIND_FRAMEWORK PROPERTY STRINGS "FIRST;LAST;NEVER")
|
||||
endif()
|
||||
|
||||
# PyPy does not support embedding the interpreter
|
||||
set(Python3_FIND_IMPLEMENTATIONS
|
||||
"CPython"
|
||||
CACHE STRING
|
||||
"Different implementations which will be searched."
|
||||
)
|
||||
set_property(
|
||||
CACHE Python3_FIND_IMPLEMENTATIONS
|
||||
PROPERTY STRINGS "CPython;IronPython;PyPy"
|
||||
)
|
||||
|
||||
# variable is a 3-tuple specifying, in order, pydebug (d), pymalloc (m) and unicode (u)
|
||||
# set(Python3_FIND_ABI "OFF" "OFF" "OFF" CACHE STRING "variable is a 3-tuple specifying
|
||||
# pydebug (d), pymalloc (m) and unicode (u)")
|
||||
|
||||
# Create CMake cache entries for the above artifact specification variables so that users
|
||||
# can edit them interactively. This disables support for multiple version/component
|
||||
# requirements.
|
||||
set(Python3_ARTIFACTS_INTERACTIVE
|
||||
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")
|
||||
# set_property(CACHE Python3_USE_STATIC_LIBS PROPERTY STRINGS "ON;OFF;ANY") else()
|
||||
# unset(Python3_USE_STATIC_LIBS) endif()
|
||||
|
||||
foreach(
|
||||
_VAR
|
||||
FIND_STRATEGY
|
||||
FIND_VIRTUALENV
|
||||
FIND_FRAMEWORK
|
||||
FIND_IMPLEMENTATIONS
|
||||
ARTIFACTS_INTERACTIVE
|
||||
)
|
||||
if(DEFINED Python3_${_VAR})
|
||||
set(Python_${_VAR}
|
||||
"${Python3_${_VAR}}"
|
||||
CACHE STRING
|
||||
"Set via Python3_${_VAR} setting (rocprofsys)"
|
||||
)
|
||||
mark_as_advanced(Python_${_VAR})
|
||||
mark_as_advanced(Python3_${_VAR})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# display version
|
||||
rocprofiler_systems_add_feature(ROCPROFSYS_PYTHON_VERSIONS
|
||||
"Python version for rocprofsys" DOC
|
||||
)
|
||||
|
||||
option(PYBIND11_INSTALL "Enable Pybind11 installation" OFF)
|
||||
|
||||
if(ROCPROFSYS_BUILD_PYTHON AND NOT TARGET pybind11)
|
||||
# checkout PyBind11 if not checked out
|
||||
rocprofiler_systems_checkout_git_submodule(
|
||||
RECURSIVE
|
||||
RELATIVE_PATH external/pybind11
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
REPO_URL https://github.com/jrmadsen/pybind11.git
|
||||
REPO_BRANCH omnitrace
|
||||
)
|
||||
|
||||
if(NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION)
|
||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)
|
||||
endif()
|
||||
set(PYBIND11_NOPYTHON ON)
|
||||
rocprofiler_systems_save_variables(IPO VARIABLES CMAKE_INTERPROCEDURAL_OPTIMIZATION)
|
||||
add_subdirectory(${PROJECT_SOURCE_DIR}/external/pybind11)
|
||||
rocprofiler_systems_restore_variables(IPO
|
||||
VARIABLES CMAKE_INTERPROCEDURAL_OPTIMIZATION
|
||||
)
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND
|
||||
${PYTHON_EXECUTABLE} -c
|
||||
"import time ; print('{} {}'.format(time.ctime(), time.tzname[0]))"
|
||||
OUTPUT_VARIABLE ROCPROFSYS_INSTALL_DATE
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET
|
||||
)
|
||||
|
||||
string(REPLACE " " " " ROCPROFSYS_INSTALL_DATE "${ROCPROFSYS_INSTALL_DATE}")
|
||||
@@ -0,0 +1,197 @@
|
||||
# * 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,321 @@
|
||||
#
|
||||
function(ROCPROFILER_SYSTEMS_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()
|
||||
rocprofiler_systems_message(WARNING "${_PYTHON_ERROR_VALUE}")
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
#
|
||||
# Internal: find the appropriate link time optimization flags for this compiler
|
||||
function(_ROCPROFSYS_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)
|
||||
rocprofiler_systems_message(STATUS "${target_name} :: LTO enabled")
|
||||
else()
|
||||
rocprofiler_systems_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(ROCPROFILER_SYSTEMS_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)
|
||||
rocprofiler_systems_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)
|
||||
_rocprofiler_systems_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()
|
||||
Fai riferimento in un nuovo problema
Block a user