Skip to content

Commit

Permalink
Merge pull request #363 from bluescarni/pr/yacma_update
Browse files Browse the repository at this point in the history
yacma update
  • Loading branch information
bluescarni authored Dec 2, 2019
2 parents b70a160 + 50e4a25 commit c7d6e89
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ if(CMAKE_COMPILER_IS_GNUCXX)
set(YACMA_COMPILER_IS_GNUCXX TRUE)
endif()

# Detect the hcc compiler.
if(YACMA_COMPILER_IS_CLANGXX AND "${CMAKE_CXX_COMPILER}" MATCHES "hcc")
set(YACMA_COMPILER_IS_HCC TRUE)
endif()

# This is an OS X specific setting that is suggested to be enabled. See:
# https://blog.kitware.com/upcoming-in-cmake-2-8-12-osx-rpath-support/
# http://stackoverflow.com/questions/31561309/cmake-warnings-under-os-x-macosx-rpath-is-not-specified-for-the-following-targe
Expand Down Expand Up @@ -122,11 +117,7 @@ if(NOT _YACMACompilerLinkerSettingsRun)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wdisabled-optimization)
# This is useful when the compiler decides the template backtrace is too verbose.
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-ftemplate-backtrace-limit=0)
if(YACMA_COMPILER_IS_HCC)
message(STATUS "hcc compiler detected, the '-fstack-protector-all' flag will not be enabled.")
else()
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-fstack-protector-all)
endif()
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-fstack-protector-all)
# A few suggestion flags.
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wsuggest-attribute=pure)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wsuggest-attribute=const)
Expand Down
34 changes: 15 additions & 19 deletions ap_examples/uda_basic/cmake_modules/yacma/YACMAPythonSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ if(YACMAPythonSetupIncluded)
endif()

# NOTE: this is a heuristic to determine whether we need to link to the Python library.
# In theory, Python extensions don't need to, as they are dlopened() by the Python process
# and thus they don't need to be linked to the Python library at compile time. However,
# the dependency on Boost.Python muddies the waters, as BP itself does link to the Python
# library, at least on some platforms. The following configuration seems to be working fine
# on various CI setups.
# The linking seems to be necessary only on Windows.
if(WIN32)
message(STATUS "Python modules require linking to the Python library.")
set(_YACMA_PYTHON_MODULE_NEED_LINK TRUE)
Expand Down Expand Up @@ -40,23 +36,18 @@ else()
endif()
mark_as_advanced(YACMA_PYTHON_INCLUDE_DIR)

# Add an interface imported target for the
# Python include dir.
add_library(YACMA::PythonIncludeDir INTERFACE IMPORTED)
set_target_properties(YACMA::PythonIncludeDir PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${YACMA_PYTHON_INCLUDE_DIR})

message(STATUS "Python interpreter: ${PYTHON_EXECUTABLE}")
message(STATUS "Python interpreter version: ${PYTHON_VERSION_STRING}")
if(_YACMA_PYTHON_MODULE_NEED_LINK)
message(STATUS "Python libraries: ${PYTHON_LIBRARIES}")
endif()
message(STATUS "Python include dir: ${YACMA_PYTHON_INCLUDE_DIR}")

# An imported target to be used when building extension modules.
if(_YACMA_PYTHON_MODULE_NEED_LINK)
add_library(YACMA::PythonModule UNKNOWN IMPORTED)
set_target_properties(YACMA::PythonModule PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${YACMA_PYTHON_INCLUDE_DIR}"
IMPORTED_LOCATION "${PYTHON_LIBRARIES}" IMPORTED_LINK_INTERFACE_LANGUAGES "C")
else()
add_library(YACMA::PythonModule INTERFACE IMPORTED)
set_target_properties(YACMA::PythonModule PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${YACMA_PYTHON_INCLUDE_DIR}")
endif()

# This flag is used to signal the need to override the default extension of the Python modules
# depending on the architecture. Under Windows, for instance, CMake produces shared objects as
# .dll files, but Python from 2.5 onwards requires .pyd files (hence the need to override).
Expand Down Expand Up @@ -123,11 +114,9 @@ function(YACMA_PYTHON_MODULE name)
# with clang and gcc. See:
# https://bugs.python.org/issue11149
# http://www.python.org/dev/peps/pep-3123/
# NOTE: not sure here how we should set flags up for MSVC or clang on windows, need
# to check in the future.
# NOTE: do not use the yacma compiler linker settings bits, so this module
# can be used stand-alone.
if(CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
if(CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND NOT MSVC))
message(STATUS "Setting up extra compiler flag '-fwrapv' for the Python module '${name}'.")
target_compile_options(${name} PRIVATE "-fwrapv")
if(${PYTHON_VERSION_MAJOR} LESS 3)
Expand All @@ -143,7 +132,14 @@ function(YACMA_PYTHON_MODULE name)
# https://cmake.org/pipermail/cmake/2017-March/065115.html
set_target_properties(${name} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
endif()
target_link_libraries("${name}" PRIVATE YACMA::PythonModule)

# Add the Python include dirs.
target_include_directories("${name}" SYSTEM PRIVATE ${YACMA_PYTHON_INCLUDE_DIR})

# Link to the Python libs, if necessary.
if(_YACMA_PYTHON_MODULE_NEED_LINK)
target_link_libraries("${name}" PRIVATE ${PYTHON_LIBRARIES})
endif()
endfunction()

# Mark as included.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ if(CMAKE_COMPILER_IS_GNUCXX)
set(YACMA_COMPILER_IS_GNUCXX TRUE)
endif()

# Detect the hcc compiler.
if(YACMA_COMPILER_IS_CLANGXX AND "${CMAKE_CXX_COMPILER}" MATCHES "hcc")
set(YACMA_COMPILER_IS_HCC TRUE)
endif()

# This is an OS X specific setting that is suggested to be enabled. See:
# https://blog.kitware.com/upcoming-in-cmake-2-8-12-osx-rpath-support/
# http://stackoverflow.com/questions/31561309/cmake-warnings-under-os-x-macosx-rpath-is-not-specified-for-the-following-targe
Expand Down Expand Up @@ -122,11 +117,7 @@ if(NOT _YACMACompilerLinkerSettingsRun)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wdisabled-optimization)
# This is useful when the compiler decides the template backtrace is too verbose.
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-ftemplate-backtrace-limit=0)
if(YACMA_COMPILER_IS_HCC)
message(STATUS "hcc compiler detected, the '-fstack-protector-all' flag will not be enabled.")
else()
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-fstack-protector-all)
endif()
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-fstack-protector-all)
# A few suggestion flags.
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wsuggest-attribute=pure)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wsuggest-attribute=const)
Expand Down
34 changes: 15 additions & 19 deletions ap_examples/udp_basic/cmake_modules/yacma/YACMAPythonSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ if(YACMAPythonSetupIncluded)
endif()

# NOTE: this is a heuristic to determine whether we need to link to the Python library.
# In theory, Python extensions don't need to, as they are dlopened() by the Python process
# and thus they don't need to be linked to the Python library at compile time. However,
# the dependency on Boost.Python muddies the waters, as BP itself does link to the Python
# library, at least on some platforms. The following configuration seems to be working fine
# on various CI setups.
# The linking seems to be necessary only on Windows.
if(WIN32)
message(STATUS "Python modules require linking to the Python library.")
set(_YACMA_PYTHON_MODULE_NEED_LINK TRUE)
Expand Down Expand Up @@ -40,23 +36,18 @@ else()
endif()
mark_as_advanced(YACMA_PYTHON_INCLUDE_DIR)

# Add an interface imported target for the
# Python include dir.
add_library(YACMA::PythonIncludeDir INTERFACE IMPORTED)
set_target_properties(YACMA::PythonIncludeDir PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${YACMA_PYTHON_INCLUDE_DIR})

message(STATUS "Python interpreter: ${PYTHON_EXECUTABLE}")
message(STATUS "Python interpreter version: ${PYTHON_VERSION_STRING}")
if(_YACMA_PYTHON_MODULE_NEED_LINK)
message(STATUS "Python libraries: ${PYTHON_LIBRARIES}")
endif()
message(STATUS "Python include dir: ${YACMA_PYTHON_INCLUDE_DIR}")

# An imported target to be used when building extension modules.
if(_YACMA_PYTHON_MODULE_NEED_LINK)
add_library(YACMA::PythonModule UNKNOWN IMPORTED)
set_target_properties(YACMA::PythonModule PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${YACMA_PYTHON_INCLUDE_DIR}"
IMPORTED_LOCATION "${PYTHON_LIBRARIES}" IMPORTED_LINK_INTERFACE_LANGUAGES "C")
else()
add_library(YACMA::PythonModule INTERFACE IMPORTED)
set_target_properties(YACMA::PythonModule PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${YACMA_PYTHON_INCLUDE_DIR}")
endif()

# This flag is used to signal the need to override the default extension of the Python modules
# depending on the architecture. Under Windows, for instance, CMake produces shared objects as
# .dll files, but Python from 2.5 onwards requires .pyd files (hence the need to override).
Expand Down Expand Up @@ -123,11 +114,9 @@ function(YACMA_PYTHON_MODULE name)
# with clang and gcc. See:
# https://bugs.python.org/issue11149
# http://www.python.org/dev/peps/pep-3123/
# NOTE: not sure here how we should set flags up for MSVC or clang on windows, need
# to check in the future.
# NOTE: do not use the yacma compiler linker settings bits, so this module
# can be used stand-alone.
if(CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
if(CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND NOT MSVC))
message(STATUS "Setting up extra compiler flag '-fwrapv' for the Python module '${name}'.")
target_compile_options(${name} PRIVATE "-fwrapv")
if(${PYTHON_VERSION_MAJOR} LESS 3)
Expand All @@ -143,7 +132,14 @@ function(YACMA_PYTHON_MODULE name)
# https://cmake.org/pipermail/cmake/2017-March/065115.html
set_target_properties(${name} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
endif()
target_link_libraries("${name}" PRIVATE YACMA::PythonModule)

# Add the Python include dirs.
target_include_directories("${name}" SYSTEM PRIVATE ${YACMA_PYTHON_INCLUDE_DIR})

# Link to the Python libs, if necessary.
if(_YACMA_PYTHON_MODULE_NEED_LINK)
target_link_libraries("${name}" PRIVATE ${PYTHON_LIBRARIES})
endif()
endfunction()

# Mark as included.
Expand Down
30 changes: 14 additions & 16 deletions cmake_modules/yacma/YACMAPythonSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ if(YACMAPythonSetupIncluded)
endif()

# NOTE: this is a heuristic to determine whether we need to link to the Python library.
# In theory, Python extensions don't need to, as they are dlopened() by the Python process
# and thus they don't need to be linked to the Python library at compile time. However,
# the dependency on Boost.Python muddies the waters, as BP itself does link to the Python
# library, at least on some platforms. The following configuration seems to be working fine
# on various CI setups.
# The linking seems to be necessary only on Windows.
if(WIN32)
message(STATUS "Python modules require linking to the Python library.")
set(_YACMA_PYTHON_MODULE_NEED_LINK TRUE)
Expand Down Expand Up @@ -40,23 +36,18 @@ else()
endif()
mark_as_advanced(YACMA_PYTHON_INCLUDE_DIR)

# Add an interface imported target for the
# Python include dir.
add_library(YACMA::PythonIncludeDir INTERFACE IMPORTED)
set_target_properties(YACMA::PythonIncludeDir PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${YACMA_PYTHON_INCLUDE_DIR})

message(STATUS "Python interpreter: ${PYTHON_EXECUTABLE}")
message(STATUS "Python interpreter version: ${PYTHON_VERSION_STRING}")
if(_YACMA_PYTHON_MODULE_NEED_LINK)
message(STATUS "Python libraries: ${PYTHON_LIBRARIES}")
endif()
message(STATUS "Python include dir: ${YACMA_PYTHON_INCLUDE_DIR}")

# An imported target to be used when building extension modules.
if(_YACMA_PYTHON_MODULE_NEED_LINK)
add_library(YACMA::PythonModule UNKNOWN IMPORTED)
set_target_properties(YACMA::PythonModule PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${YACMA_PYTHON_INCLUDE_DIR}"
IMPORTED_LOCATION "${PYTHON_LIBRARIES}" IMPORTED_LINK_INTERFACE_LANGUAGES "C")
else()
add_library(YACMA::PythonModule INTERFACE IMPORTED)
set_target_properties(YACMA::PythonModule PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${YACMA_PYTHON_INCLUDE_DIR}")
endif()

# This flag is used to signal the need to override the default extension of the Python modules
# depending on the architecture. Under Windows, for instance, CMake produces shared objects as
# .dll files, but Python from 2.5 onwards requires .pyd files (hence the need to override).
Expand Down Expand Up @@ -141,7 +132,14 @@ function(YACMA_PYTHON_MODULE name)
# https://cmake.org/pipermail/cmake/2017-March/065115.html
set_target_properties(${name} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
endif()
target_link_libraries("${name}" PRIVATE YACMA::PythonModule)

# Add the Python include dirs.
target_include_directories("${name}" SYSTEM PRIVATE ${YACMA_PYTHON_INCLUDE_DIR})

# Link to the Python libs, if necessary.
if(_YACMA_PYTHON_MODULE_NEED_LINK)
target_link_libraries("${name}" PRIVATE ${PYTHON_LIBRARIES})
endif()
endfunction()

# Mark as included.
Expand Down
2 changes: 1 addition & 1 deletion pygmo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.hpp.in" "${CMAKE_CURRENT_BINA

# Setup of the header-only pygmo library.
add_library(pygmo INTERFACE)
target_link_libraries(pygmo INTERFACE Pagmo::pagmo ${PYGMO_BP_TARGET} Boost::disable_autolinking YACMA::PythonModule NumPy::numpy)
target_link_libraries(pygmo INTERFACE Pagmo::pagmo ${PYGMO_BP_TARGET} Boost::disable_autolinking YACMA::PythonIncludeDir NumPy::numpy)
target_include_directories(pygmo INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include/pygmo> $<INSTALL_INTERFACE:include>)
# Setup of the export.
Expand Down

0 comments on commit c7d6e89

Please sign in to comment.