Skip to content

Commit

Permalink
cmake compiler ifs
Browse files Browse the repository at this point in the history
  • Loading branch information
gabyx committed Jan 30, 2018
1 parent b9c8e92 commit a5044c3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
13 changes: 6 additions & 7 deletions cmake/SetTargetCompileOptions.cmake
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
macro(setTargetCompileOptions TARGETNAME)

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
list(APPEND CXX_WARNINGS "-Wall"
"-Wpedantic"
"-Wno-comment" )

list(APPEND CXX_FLAGS_DEBUG "-fsanitize=address"
"-fno-omit-frame-pointer")

elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang" )
elseif( CMAKE_CXX_COMPILER_ID MATCHES "Clang")

list(APPEND CXX_WARNINGS "-Wall"
"-Wpedantic"
"-Wno-comment")

list(APPEND CXX_FLAGS_DEBUG "-fno-omit-frame-pointer")

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
list(APPEND CXX_FLAGS_DEBUG "-fsanitize=leak"
"-fsanitize=address"
"-fno-omit-frame-pointer")
endif()

elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" )
elseif( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
message(WARNING "MSVC is partially supported (Visual Studio 2013 Update 5), trying to set compiler flags anyway!")
list(APPEND CXX_FLAGS "/arch:SSE2")
list(APPEND CXX_WARNINGS "/Wall")
Expand All @@ -41,8 +40,8 @@ macro(setTargetCompileOptions TARGETNAME)
target_compile_options(${TARGETNAME} PRIVATE ${CXX_FLAGS} ${CXX_WARNINGS} )
target_compile_options(${TARGETNAME} PRIVATE $<$<CONFIG:Debug>:${CXX_FLAGS_DEBUG}> )

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR
CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# with clang 5.0.1: -fsanitize=address produces weird output in lldb for std::string ...
set_property(TARGET ${TARGETNAME} PROPERTY LINK_FLAGS "-fsanitize=leak -fsanitize=address")
endif()
Expand Down
28 changes: 12 additions & 16 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ macro(add_approxmvbb_lib STATICorSHARED TARGETNAME EXPORTNAME DOINSTALL)
# set build flag, for import/export specifiers in platform.hpp
# Building a library means we only export the symbols which have APPROXMVBB_EXPORT set in the Platform.hpp file
# We define all other symbols to be hidden by default as suggested by https://gcc.gnu.org/wiki/Visibility
if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
if( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(${TARGETNAME} PRIVATE -DApproxMVBB_BUILD_LIBRARY -fvisibility=hidden)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(${TARGETNAME} PRIVATE /DApproxMVBB_BUILD_LIBRARY)
else()
message(FATAL_ERROR "Could not set compile options for compiler id: '${CMAKE_CXX_COMPILER_ID}'")
Expand All @@ -46,11 +45,10 @@ endif()
if(${ApproxMVBB_KDTREE_SUPPORT})
add_library(ApproxMVBB_KdTreeSupport INTERFACE)
add_library("ApproxMVBB::KdTreeSupport" ALIAS ApproxMVBB_KdTreeSupport)
if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
if( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set_target_properties(ApproxMVBB_KdTreeSupport PROPERTIES INTERFACE_COMPILE_OPTIONS "-DApproxMVBB_KDTREE_SUPPORT")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set_target_properties(ApproxMVBB_KdTreeSupport PROPERTIES INTERFACE_COMPILE_OPTIONS "/DApproxMVBB_KDTREE_SUPPORT")
else()
message(FATAL_ERROR "Could not set compile options for compiler id: '${CMAKE_CXX_COMPILER_ID}'")
Expand All @@ -66,11 +64,10 @@ endif()
if(${ApproxMVBB_XML_SUPPORT})
add_library(ApproxMVBB_XML_SUPPORT INTERFACE)
add_library("ApproxMVBB::XMLSupport" ALIAS ApproxMVBB_XML_SUPPORT)
if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
if( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set_target_properties(ApproxMVBB_XML_SUPPORT PROPERTIES INTERFACE_COMPILE_OPTIONS "-DApproxMVBB_XML_SUPPORT")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set_target_properties(ApproxMVBB_XML_SUPPORT PROPERTIES INTERFACE_COMPILE_OPTIONS "-DApproxMVBB_XML_SUPPORT")
else()
message(FATAL_ERROR "Could not set compile options for compiler id: '${CMAKE_CXX_COMPILER_ID}'")
Expand All @@ -91,11 +88,10 @@ if(ApproxMVBB_BUILD_TESTS)
# set build flag, for import/export specifiers in platform.hpp
# Building a library means we only export the symbols which have APPROXMVBB_EXPORT set in the Platform.hpp file
# We define all other symbols to be hidden by default as suggested by https://gcc.gnu.org/wiki/Visibility
if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
if( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(ApproxMVBBForTestsOnly PRIVATE -DApproxMVBB_BUILD_TESTS)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(ApproxMVBBForTestsOnly PRIVATE /DApproxMVBB_BUILD_TESTS)
else()
message(FATAL_ERROR "Could not set compile options for compiler id: '${CMAKE_CXX_COMPILER_ID}'")
Expand Down
7 changes: 3 additions & 4 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ macro(defineTarget TARGETNAME)

setTargetCompileOptions(${TARGETNAME})

if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
if( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(${TARGETNAME} PRIVATE -DApproxMVBB_BUILD_TESTS )
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(${TARGETNAME} PRIVATE /DApproxMVBB_BUILD_TESTS )
else()
message(FATAL_ERROR "Could not set compiler flags for compiler id: ${CMAKE_CXX_COMPILER_ID}")
Expand Down

0 comments on commit a5044c3

Please sign in to comment.