From: maier Date: Fri, 15 Mar 2013 00:04:58 +0000 (+0000) Subject: CMake: Improve compile flag macros, replace "-O0" with "-O1" on Cygwin targets X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de2b7c0a44ca3d7ffede422c73a035224497abe4;p=dealii-svn.git CMake: Improve compile flag macros, replace "-O0" with "-O1" on Cygwin targets git-svn-id: https://svn.dealii.org/trunk@28906 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/cmake/checks/check_01_system_features.cmake b/deal.II/cmake/checks/check_01_system_features.cmake index f5ac8662e7..a85e40fecc 100644 --- a/deal.II/cmake/checks/check_01_system_features.cmake +++ b/deal.II/cmake/checks/check_01_system_features.cmake @@ -117,3 +117,13 @@ IF(CMAKE_SYSTEM_NAME MATCHES "Windows") STRIP_FLAG(DEAL_II_SHARED_LINKER_FLAGS_DEBUG "-g") ENDIF() +IF(CMAKE_SYSTEM_NAME MATCHES "CYGWIN") + # + # Workaround for a miscompilation and linkage issue with shared libraries + # under Cygwin. Replacing -O0 with -O1 helps. + # + # - Matthias Maier, 2013 + # + REPLACE_FLAG(DEAL_II_CXX_FLAGS_DEBUG "-O0" "-O1") + +ENDIF() diff --git a/deal.II/cmake/macros/macro_add_flags.cmake b/deal.II/cmake/macros/macro_add_flags.cmake index 2bcddaa0a8..a56bb3ae30 100644 --- a/deal.II/cmake/macros/macro_add_flags.cmake +++ b/deal.II/cmake/macros/macro_add_flags.cmake @@ -21,8 +21,10 @@ # MACRO(ADD_FLAGS _variable _flags) - IF(NOT "${_flags}" STREQUAL "") + STRING(STRIP "${_flags}" _flags_stripped) + IF(NOT "${_flags_stripped}" STREQUAL "") SET(${_variable} "${${_variable}} ${_flags}") + STRING(STRIP "${${_variable}}" ${_variable}) ENDIF() ENDMACRO() diff --git a/deal.II/cmake/macros/macro_enable_if_links.cmake b/deal.II/cmake/macros/macro_enable_if_links.cmake index 5a8525afe3..2a1bf93127 100644 --- a/deal.II/cmake/macros/macro_enable_if_links.cmake +++ b/deal.II/cmake/macros/macro_enable_if_links.cmake @@ -22,18 +22,22 @@ # MACRO(ENABLE_IF_LINKS _variable _flag) - STRING(REGEX REPLACE "^-" "" _flag_name "${_flag}") + STRING(STRIP "${_flag}" _flag_stripped) + STRING(REGEX REPLACE "^-" "" _flag_name "${_flag_stripped}") - ADD_FLAGS(CMAKE_REQUIRED_FLAGS "${_flag}") - CHECK_CXX_SOURCE_COMPILES( - " - int main() { return 0; } - " - DEAL_II_HAVE_FLAG_${_flag_name} - ) - STRIP_FLAG(CMAKE_REQUIRED_FLAGS "${_flag}") - IF(DEAL_II_HAVE_FLAG_${_flag_name}) - SET(${_variable} "${${_variable}} ${_flag}") + IF(NOT "${_flag_stripped}" STREQUAL "") + ADD_FLAGS(CMAKE_REQUIRED_FLAGS "${_flag_stripped}") + CHECK_CXX_SOURCE_COMPILES( + " + int main() { return 0; } + " + DEAL_II_HAVE_FLAG_${_flag_name} + ) + STRIP_FLAG(CMAKE_REQUIRED_FLAGS "${_flag_stripped}") + IF(DEAL_II_HAVE_FLAG_${_flag_name}) + SET(${_variable} "${${_variable}} ${_flag_stripped}") + STRING(STRIP "${${_variable}}" ${_variable}) + ENDIF() ENDIF() ENDMACRO() diff --git a/deal.II/cmake/macros/macro_enable_if_supported.cmake b/deal.II/cmake/macros/macro_enable_if_supported.cmake index d843de50da..ed63ec4788 100644 --- a/deal.II/cmake/macros/macro_enable_if_supported.cmake +++ b/deal.II/cmake/macros/macro_enable_if_supported.cmake @@ -21,14 +21,16 @@ # MACRO(ENABLE_IF_SUPPORTED _variable _flag) - IF(NOT "${_flag}" STREQUAL "") - STRING(REGEX REPLACE "^-" "" _flag_name "${_flag}") + STRING(STRIP "${_flag}" _flag_stripped) + IF(NOT "${_flag_stripped}" STREQUAL "") + STRING(REGEX REPLACE "^-" "" _flag_name "${_flag_stripped}") CHECK_CXX_COMPILER_FLAG( - "${_flag}" + "${_flag_stripped}" DEAL_II_HAVE_FLAG_${_flag_name} ) IF(DEAL_II_HAVE_FLAG_${_flag_name}) - SET(${_variable} "${${_variable}} ${_flag}") + SET(${_variable} "${${_variable}} ${_flag_stripped}") + STRING(STRIP "${${_variable}}" ${_variable}) ENDIF() ENDIF() ENDMACRO() diff --git a/deal.II/cmake/macros/macro_replace_flag.cmake b/deal.II/cmake/macros/macro_replace_flag.cmake new file mode 100644 index 0000000000..5ab43cac49 --- /dev/null +++ b/deal.II/cmake/macros/macro_replace_flag.cmake @@ -0,0 +1,35 @@ +##### +## +## Copyright (C) 2012 by the deal.II authors +## +## This file is part of the deal.II library. +## +## +## This file is dual licensed under QPL 1.0 and LGPL 2.1 or any later +## version of the LGPL license. +## +## Author: Matthias Maier +## +##### + +# +# Replace all occurences of "${flag}" with "${replacement}" in the string +# variable. +# +# Usage: +# STRIP_FLAG(variable flag replacement) +# + +MACRO(REPLACE_FLAG _variable _flag _replacement) + STRING(STRIP "${_replacement}" _replacement_stripped) + STRING(REPLACE " " " " ${_variable} "${${_variable}}") + SET(${_variable} " ${${_variable}} ") + STRING(REPLACE " " " " _flag2 "${_flag}") + IF(NOT "${_replacement_stripped}" STREQUAL "") + STRING(REPLACE " ${_flag2} " " ${_replacement_stripped} " ${_variable} "${${_variable}}") + ELSE() + STRING(REPLACE " ${_flag2} " " " ${_variable} "${${_variable}}") + ENDIF() + STRING(REPLACE " " " " ${_variable} "${${_variable}}") + STRING(STRIP "${${_variable}}" ${_variable}) +ENDMACRO() diff --git a/deal.II/cmake/macros/macro_strip_flag.cmake b/deal.II/cmake/macros/macro_strip_flag.cmake index 70636c139b..d90979ad9b 100644 --- a/deal.II/cmake/macros/macro_strip_flag.cmake +++ b/deal.II/cmake/macros/macro_strip_flag.cmake @@ -20,8 +20,11 @@ # MACRO(STRIP_FLAG _variable _flag) + STRING(REPLACE " " " " ${_variable} "${${_variable}}") SET(${_variable} " ${${_variable}} ") - STRING(REPLACE " ${_flag} " " " "${_variable}" ${${_variable}}) + STRING(REPLACE " " " " _flag2 "${_flag}") + STRING(REPLACE " ${_flag2} " " " ${_variable} "${${_variable}}") + STRING(REPLACE " " " " ${_variable} "${${_variable}}") STRING(STRIP "${${_variable}}" ${_variable}) ENDMACRO()