summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt6
-rw-r--r--cmake/Modules/GrMiscUtils.cmake13
2 files changed, 17 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a74ff4c90..c175bdd77 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -55,13 +55,15 @@ file(WRITE ${EXPORT_FILE}) #blank the file (subdirs will append)
########################################################################
# Compiler specific setup
########################################################################
+include(GrMiscUtils) #compiler flag check
+
if(CMAKE_COMPILER_IS_GNUCXX AND NOT WIN32)
#http://gcc.gnu.org/wiki/Visibility
- add_definitions(-fvisibility=hidden)
+ GR_ADD_CXX_COMPILER_FLAG_IF_AVAILABLE(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN)
endif()
if(CMAKE_COMPILER_IS_GNUCXX)
- add_definitions(-Wsign-compare)
+ GR_ADD_CXX_COMPILER_FLAG_IF_AVAILABLE(-Wsign-compare HAVE_SIGN_COMPARE)
endif(CMAKE_COMPILER_IS_GNUCXX)
if(MSVC)
diff --git a/cmake/Modules/GrMiscUtils.cmake b/cmake/Modules/GrMiscUtils.cmake
index 871861e35..10de21c7c 100644
--- a/cmake/Modules/GrMiscUtils.cmake
+++ b/cmake/Modules/GrMiscUtils.cmake
@@ -84,3 +84,16 @@ macro(GR_INCLUDE_SUBDIRECTORY subdir)
list(REMOVE_AT _cmake_source_dirs 0)
list(REMOVE_AT _cmake_binary_dirs 0)
endmacro(GR_INCLUDE_SUBDIRECTORY)
+
+########################################################################
+# Check if a compiler flag works and conditionally set a compile define.
+# - flag the compiler flag to check for
+# - have the variable to set with result
+########################################################################
+INCLUDE(CheckCXXCompilerFlag)
+MACRO(GR_ADD_CXX_COMPILER_FLAG_IF_AVAILABLE flag have)
+ CHECK_CXX_COMPILER_FLAG(${flag} ${have})
+ IF(${have})
+ ADD_DEFINITIONS(${flag})
+ ENDIF(${have})
+ENDMACRO(GR_ADD_CXX_COMPILER_FLAG_IF_AVAILABLE)