diff --git a/ap_examples/uda_basic/cmake_modules/yacma/YACMACompilerLinkerSettings.cmake b/ap_examples/uda_basic/cmake_modules/yacma/YACMACompilerLinkerSettings.cmake index a8d73e05f..d8c387594 100644 --- a/ap_examples/uda_basic/cmake_modules/yacma/YACMACompilerLinkerSettings.cmake +++ b/ap_examples/uda_basic/cmake_modules/yacma/YACMACompilerLinkerSettings.cmake @@ -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 @@ -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) diff --git a/ap_examples/uda_basic/cmake_modules/yacma/YACMAPythonSetup.cmake b/ap_examples/uda_basic/cmake_modules/yacma/YACMAPythonSetup.cmake index 199964324..2d31cebb3 100644 --- a/ap_examples/uda_basic/cmake_modules/yacma/YACMAPythonSetup.cmake +++ b/ap_examples/uda_basic/cmake_modules/yacma/YACMAPythonSetup.cmake @@ -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) @@ -40,6 +36,11 @@ 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) @@ -47,16 +48,6 @@ if(_YACMA_PYTHON_MODULE_NEED_LINK) 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). @@ -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) @@ -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. diff --git a/ap_examples/udp_basic/cmake_modules/yacma/YACMACompilerLinkerSettings.cmake b/ap_examples/udp_basic/cmake_modules/yacma/YACMACompilerLinkerSettings.cmake index a8d73e05f..d8c387594 100644 --- a/ap_examples/udp_basic/cmake_modules/yacma/YACMACompilerLinkerSettings.cmake +++ b/ap_examples/udp_basic/cmake_modules/yacma/YACMACompilerLinkerSettings.cmake @@ -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 @@ -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) diff --git a/ap_examples/udp_basic/cmake_modules/yacma/YACMAPythonSetup.cmake b/ap_examples/udp_basic/cmake_modules/yacma/YACMAPythonSetup.cmake index 199964324..2d31cebb3 100644 --- a/ap_examples/udp_basic/cmake_modules/yacma/YACMAPythonSetup.cmake +++ b/ap_examples/udp_basic/cmake_modules/yacma/YACMAPythonSetup.cmake @@ -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) @@ -40,6 +36,11 @@ 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) @@ -47,16 +48,6 @@ if(_YACMA_PYTHON_MODULE_NEED_LINK) 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). @@ -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) @@ -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. diff --git a/cmake_modules/yacma/YACMAPythonSetup.cmake b/cmake_modules/yacma/YACMAPythonSetup.cmake index 697200c1b..2d31cebb3 100644 --- a/cmake_modules/yacma/YACMAPythonSetup.cmake +++ b/cmake_modules/yacma/YACMAPythonSetup.cmake @@ -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) @@ -40,6 +36,11 @@ 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) @@ -47,16 +48,6 @@ if(_YACMA_PYTHON_MODULE_NEED_LINK) 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). @@ -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. diff --git a/pygmo/CMakeLists.txt b/pygmo/CMakeLists.txt index 63f97f1ce..6515d3f0f 100644 --- a/pygmo/CMakeLists.txt +++ b/pygmo/CMakeLists.txt @@ -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 $ $ $) # Setup of the export.