Skip to content

Commit

Permalink
Update of YACMA to fix osx linking problem
Browse files Browse the repository at this point in the history
  • Loading branch information
darioizzo committed Jan 7, 2019
1 parent 11e43cd commit 6ccc09c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
39 changes: 31 additions & 8 deletions cmake_modules/yacma/YACMACompilerLinkerSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +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
Expand Down Expand Up @@ -82,16 +87,13 @@ if(NOT _YACMACompilerLinkerSettingsRun)
set(_YACMA_CXX_FLAGS "")
set(_YACMA_CXX_FLAGS_DEBUG "")

# NOTE: all these flags are with a Unix-like syntax. We will need to change them
# for MSVC and clang on windows possibly.

# Configuration bits specific for GCC.
if(YACMA_COMPILER_IS_GNUCXX)
_YACMA_CHECK_ENABLE_CXX_FLAG(-fdiagnostics-color=auto)
endif()

# Configuration bits specific for clang.
if(YACMA_COMPILER_IS_CLANGXX AND NOT YACMA_COMPILER_IS_MSVC)
if(YACMA_COMPILER_IS_CLANGXX)
# For now it seems like -Wshadow from clang behaves better than GCC's, just enable it here
# for the time being.
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wshadow)
Expand All @@ -100,7 +102,7 @@ if(NOT _YACMACompilerLinkerSettingsRun)
endif()

# Common configuration for GCC, clang and Intel.
if((YACMA_COMPILER_IS_CLANGXX AND NOT YACMA_COMPILER_IS_MSVC) OR YACMA_COMPILER_IS_INTELXX OR YACMA_COMPILER_IS_GNUCXX)
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)
Expand All @@ -120,20 +122,35 @@ if(NOT _YACMACompilerLinkerSettingsRun)
_YACMA_CHECK_ENABLE_CXX_FLAG(-fvisibility=hidden)
# This is useful when the compiler decides the template backtrace is too verbose.
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-ftemplate-backtrace-limit=0)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-fstack-protector-all)
# These became available in GCC from version 5.
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()
# A few suggestion flags.
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wsuggest-attribute=pure)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wsuggest-attribute=const)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wsuggest-attribute=noreturn)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wsuggest-attribute=format)
# From GCC 5.
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wodr)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wsuggest-final-types)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wsuggest-final-methods)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wsuggest-override)
# From GCC 6.
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wshift-negative-value)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wshift-overflow=2)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wduplicated-cond)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wnull-dereference)
# From GCC 7.
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wduplicated-branches)
#_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wduplicated-branches)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wrestrict)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Waligned-new)
# From GCC 8.
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wcast-align=strict)
# This is supposed to produce a nice graphical visualization
# of mismatching template errors.
_YACMA_CHECK_ENABLE_CXX_FLAG(-fdiagnostics-show-template-tree)
if(YACMA_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "5.999")
# NOTE: GCC >= 6 seems to be wrongly warning about visibility attributes
# in some situations:
Expand All @@ -142,6 +159,12 @@ if(NOT _YACMACompilerLinkerSettingsRun)
message(STATUS "Activating the '-Wno-attributes' workaround for GCC >= 6.")
_YACMA_CHECK_ENABLE_CXX_FLAG(-Wno-attributes)
endif()
if(YACMA_COMPILER_IS_GNUCXX)
# The -Wmaybe-uninitialized flag is enabled by -Wall, but it is known
# to emit a lot of possibly spurious warnings. Let's just disable it.
message(STATUS "Activating the '-Wno-maybe-uninitialized' workaround for GCC.")
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wno-maybe-uninitialized)
endif()
endif()

# MSVC setup.
Expand Down
12 changes: 9 additions & 3 deletions cmake_modules/yacma/YACMAPythonSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ endif()
# 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")
if(WIN32)
message(STATUS "Python modules require linking to the Python library.")
set(_YACMA_PYTHON_MODULE_NEED_LINK TRUE)
else()
Expand Down Expand Up @@ -137,6 +135,14 @@ function(YACMA_PYTHON_MODULE name)
target_compile_options(${name} PRIVATE "-fno-strict-aliasing")
endif()
endif()
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# 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()
target_link_libraries("${name}" PRIVATE YACMA::PythonModule)
endfunction()

Expand Down

0 comments on commit 6ccc09c

Please sign in to comment.