Skip to content

Commit

Permalink
Squashed 'cmake_modules/yacma/' changes from e50bcb9..9b55530
Browse files Browse the repository at this point in the history
9b55530 More YACMA bits.
8d4e291 yacma fix for recent CMake versions.
4942670 Merge commit '9dd6fbba6dc9283ac77899901e6c026d0b016e23' into pr/dates
a0fa858 Update copyright dates for 2020.
19ed5f9 Update yacma copyright date.
14b830d Tentative yacma fix.
ee88350 Include Python dirs as SYSTEM.
eac192c Merge pull request #1 from bluescarni/pr/py_fixes
d841133 Another simplification.
ba89892 Tentative Python libs linking fix.
ba6dd38 Avoid setting the Python module compilation flags for clang-cl.
4fc0633 Remove the hcc bits from yacma.

git-subtree-dir: cmake_modules/yacma
git-subtree-split: 9b5553088aba21f8deab536aae3551f09cce4e49
  • Loading branch information
bluescarni committed Mar 28, 2020
1 parent 1cc29f9 commit 2c857ac
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 40 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016-2019 Francesco Biscani
Copyright (c) 2016-2020 Francesco Biscani

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
48 changes: 28 additions & 20 deletions YACMACompilerLinkerSettings.cmake
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 All @@ -49,36 +44,32 @@ endfunction()

# Enable conditionally a CXX flag, if supported by the compiler.
# This is for flags intended to be enabled in all configurations.
# NOTE: we use macros and go through temporary private variables
# because it's apparently impossible to append to an internal
# NOTE: we use macros because it's apparently impossible to append to an internal
# CACHEd list.
macro(_YACMA_CHECK_ENABLE_CXX_FLAG flag)
set(CMAKE_REQUIRED_QUIET TRUE)
check_cxx_compiler_flag("${flag}" YACMA_CHECK_CXX_FLAG)
check_cxx_compiler_flag("${flag}" YACMA_CHECK_CXX_FLAG::${flag})
unset(CMAKE_REQUIRED_QUIET)
if(YACMA_CHECK_CXX_FLAG)
if(YACMA_CHECK_CXX_FLAG::${flag})
message(STATUS "'${flag}': flag is supported by the compiler, enabling.")
list(APPEND _YACMA_CXX_FLAGS "${flag}")
else()
message(STATUS "'${flag}': flag is not supported by the compiler.")
endif()
# NOTE: check_cxx_compiler stores variables in the cache.
unset(YACMA_CHECK_CXX_FLAG CACHE)
endmacro()

# Enable conditionally a debug CXX flag, is supported by the compiler.
# This is for flags intended to be enabled in debug mode.
macro(_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG flag)
set(CMAKE_REQUIRED_QUIET TRUE)
check_cxx_compiler_flag("${flag}" YACMA_CHECK_DEBUG_CXX_FLAG)
check_cxx_compiler_flag("${flag}" YACMA_CHECK_DEBUG_CXX_FLAG::${flag})
unset(CMAKE_REQUIRED_QUIET)
if(YACMA_CHECK_DEBUG_CXX_FLAG)
if(YACMA_CHECK_DEBUG_CXX_FLAG::${flag})
message(STATUS "'${flag}': debug flag is supported by the compiler, enabling.")
list(APPEND _YACMA_CXX_FLAGS_DEBUG "${flag}")
else()
message(STATUS "'${flag}': debug flag is not supported by the compiler.")
endif()
unset(YACMA_CHECK_DEBUG_CXX_FLAG CACHE)
endmacro()

# What we want to avoid is to re-run the expensive flag checks. We will set cache variables
Expand All @@ -91,6 +82,8 @@ if(NOT _YACMACompilerLinkerSettingsRun)
# Configuration bits specific for GCC.
if(YACMA_COMPILER_IS_GNUCXX)
_YACMA_CHECK_ENABLE_CXX_FLAG(-fdiagnostics-color=auto)
# New in GCC 9.
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Waddress-of-packed-member)
endif()

# Configuration bits specific for clang.
Expand All @@ -99,7 +92,26 @@ if(NOT _YACMACompilerLinkerSettingsRun)
# for the time being.
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wshadow)
# Clang is better at this flag than GCC.
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Werror)
# NOTE: enable unconditionally, as it seems like the CMake
# machinery for detecting this fails. Perhaps the source code
# used for checking the flag emits warnings?
list(APPEND _YACMA_CXX_FLAGS_DEBUG "-Werror")
# New warnings in clang 8.
# NOTE: a few issues with macros here, let's disable for now.
# _YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wextra-semi-stmt)
# New warnings in clang 10.
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wtautological-overlap-compare)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wtautological-compare)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wtautological-bitwise-compare)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wbitwise-conditional-parentheses)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wrange-loop-analysis)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wmisleading-indentation)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wc99-designator)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wreorder-init-list)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wsizeof-pointer-div)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wsizeof-array-div)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wxor-used-as-pow)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wfinal-dtor-non-final-class)
endif()

# Common configuration for GCC, clang and Intel.
Expand All @@ -122,11 +134,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 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

0 comments on commit 2c857ac

Please sign in to comment.