Skip to content

Commit

Permalink
Squashed 'cmake/yacma/' changes from b2f0ede..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.
e50bcb9 Last minute tweaks.
89acd28 Remove the explicit setting of the '_MT' definition on MSVC, as this seems unnecessary.
89647b7 Merge commit 'b33ce5313e6b723090d3f057d7b2ff6f975f18b6'
bf087bc Another small yacma simplification.
b1f6b74 Merge commit '168443070fe46d395235eb0fe30ddb5214aadb83' into pr/circleci
d7e9df3 Some yacma simplifications.
a55db40 Merge commit 'e781b7c72abab2a4adc59eb6fde9f1f3d53a3b39' into pr/circleci
3936275 Second batch of copyright updates.
0311a6d Slight yacma tweak.
ceff571 Merge commit '5351f3f3128b4ac75eccfc4bad58d46a829209f9' into pr/real_iter
8707bb1 Internal docs and changelog update.
b11af0d Again. [skip appveyor]
4a3f2cb Derp. [skip appveyor]
cffc8aa Try the "-undefined dynamic_lookup" flag for Clang OSX.
e130517 Try to avoid linking to the Python library on OSX when building pygmo.
23ec264 Merge commit 'b5f0f92b47cc884ed18e53e7608cdbcfc3223710' [skip ci]
ac8cec0 A few new compiler flags in yacma.
5b34743 Merge commit '023ca6868644202d38fa70d89a570bb4eb53afbd' into pr/iter
51b588e Merge commit '0caaf93af2bb470b63a6c1e7140f01ec5770375d' into pr/yacma_update
bf63d41 Merge commit 'ab914a3611dc60b3d0e3e441e65095c197468380' into pr/integer_iterate
0916451 Merge commit 'f4147ad3acb77c56dd2cf78a1b87790c041ba896' into pr/s11n
1686d01 YACMA copyright date update.
167b40c Merge commit '246f92d131f58efef03b6591814bee25e0fb2b85' into pr/pybind11_utils
c159972 Fix yacma debug flag.
ff24b2a Merge branch 'master' into pr/mp_real
c6ea431 A yacma update to enable more warnings.

git-subtree-dir: cmake/yacma
git-subtree-split: 9b5553088aba21f8deab536aae3551f09cce4e49
  • Loading branch information
bluescarni committed Apr 3, 2020
1 parent 2567ec5 commit 528c681
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 52 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-2018 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
56 changes: 33 additions & 23 deletions YACMACompilerLinkerSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@ 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
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
if(APPLE)
message(STATUS "OSX detected, setting the 'CMAKE_MACOSX_RPATH' option to TRUE.")
set(CMAKE_MACOSX_RPATH TRUE)
endif()

Expand All @@ -48,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 @@ -90,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 @@ -98,15 +92,35 @@ 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.
if(YACMA_COMPILER_IS_CLANGXX OR YACMA_COMPILER_IS_INTELXX OR YACMA_COMPILER_IS_GNUCXX)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wall)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wextra)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wnon-virtual-dtor)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wnoexcept)
# NOTE: this flag is a bit too chatty, let's disable it for the moment.
#_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wnoexcept)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wlogical-op)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wconversion)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wdeprecated)
Expand All @@ -120,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 Expand Up @@ -166,7 +176,7 @@ if(NOT _YACMACompilerLinkerSettingsRun)
endif()

# MSVC setup.
if(YACMA_COMPILER_IS_MSVC)
if(YACMA_COMPILER_IS_MSVC AND NOT YACMA_COMPILER_IS_CLANGXX)
# Enable higher warning level than usual.
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(/W4)
# Treat warnings as errors.
Expand Down
48 changes: 25 additions & 23 deletions YACMAPythonSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ 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.
# NOTE: apparently homebrew requires NOT to link to the Python library. We might want
# to add a config option to accommodate that eventually.
if(WIN32 OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# 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)
else()
Expand Down Expand Up @@ -42,31 +36,26 @@ 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).
set(_YACMA_PY_MODULE_EXTENSION "")

# Platform-specific setup.
if(UNIX)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
if(APPLE)
message(STATUS "OS X platform detected.")
# Apparently on OS X Python expects the .so extension for compiled modules.
message(STATUS "Output extension for compiled modules will be '.so'.")
Expand Down Expand Up @@ -125,19 +114,32 @@ 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)
message(STATUS "Python < 3 detected, setting up extra compiler flag '-fno-strict-aliasing' for the Python module '${name}'.")
target_compile_options(${name} PRIVATE "-fno-strict-aliasing")
endif()
endif()
target_link_libraries("${name}" PRIVATE YACMA::PythonModule)
if(APPLE AND ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
# On OSX + Clang this link flag is apparently necessary in order to avoid
# undefined references to symbols defined in the Python library. See also:
# https://github.com/potassco/clingo/issues/79
# https://stackoverflow.com/questions/25421479/clang-and-undefined-symbols-when-building-a-library
# https://cmake.org/pipermail/cmake/2017-March/065115.html
set_target_properties(${name} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
endif()

# 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
5 changes: 0 additions & 5 deletions YACMAThreadingSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ if(MINGW)
list(APPEND YACMA_THREADING_CXX_FLAGS "-mthreads")
endif()

if(YACMA_COMPILER_IS_MSVC)
message(STATUS "Enabling the '_MT' definition for MSVC.")
list(APPEND YACMA_THREADING_CXX_FLAGS "/D_MT")
endif()

# Check if we have thread_local.
# NOTE: we need to double check what happens with OSX's clang here.
list(FIND CMAKE_CXX_COMPILE_FEATURES "cxx_thread_local" YACMA_HAVE_THREAD_LOCAL)
Expand Down

0 comments on commit 528c681

Please sign in to comment.