[PATCH] Simplify CMake rules in HandleLLVMOptions module.
Alexey Samsonov
samsonov at google.com
Wed Mar 13 03:21:37 PDT 2013
Hi Bigcheese,
No functionality change.
http://llvm-reviews.chandlerc.com/D535
Files:
cmake/modules/HandleLLVMOptions.cmake
Index: cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- cmake/modules/HandleLLVMOptions.cmake
+++ cmake/modules/HandleLLVMOptions.cmake
@@ -59,31 +59,40 @@
endif(UNIX)
endif(WIN32)
+function(add_flag_or_print_warning flag)
+ check_c_compiler_flag(${flag} C_SUPPORTS_${flag})
+ check_cxx_compiler_flag(${flag} CXX_SUPPORTS_${flag})
+ if (C_SUPPORTS_${flag} AND CXX_SUPPORTS_${flag})
+ message(STATUS "Building with ${flag}")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE)
+ else()
+ message(WARNING "${flag} is not supported.")
+ endif()
+endfunction()
+
+function(append_if variable value condition)
+ if (${condition})
+ set(${variable} "${${variable}} ${value}" PARENT_SCOPE)
+ endif()
+endfunction()
+
if( LLVM_ENABLE_PIC )
if( XCODE )
# Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't
# know how to disable this, so just force ENABLE_PIC off for now.
message(WARNING "-fPIC not supported with Xcode.")
elseif( WIN32 OR CYGWIN)
# On Windows all code is PIC. MinGW warns if -fPIC is used.
else()
- check_cxx_compiler_flag("-fPIC" SUPPORTS_FPIC_FLAG)
- if( SUPPORTS_FPIC_FLAG )
- message(STATUS "Building with -fPIC")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
- else( SUPPORTS_FPIC_FLAG )
- message(WARNING "-fPIC not supported.")
- endif()
+ add_flag_or_print_warning("-fPIC")
if( WIN32 OR CYGWIN)
# MinGW warns if -fvisibility-inlines-hidden is used.
else()
check_cxx_compiler_flag("-fvisibility-inlines-hidden" SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG)
- if( SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG )
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden")
- endif()
- endif()
+ append_if(CMAKE_CXX_FLAGS "-fvisibility-inlines-hidden" SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG)
+ endif()
endif()
endif()
@@ -194,24 +203,14 @@
if (LLVM_ENABLE_PEDANTIC)
add_llvm_definitions( -pedantic -Wno-long-long )
check_cxx_compiler_flag("-Werror -Wnested-anon-types" CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG)
- if( CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG )
- set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nested-anon-types" )
- endif()
+ append_if(CMAKE_CXX_FLAGS "-Wno-nested-anon-types" CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG)
endif (LLVM_ENABLE_PEDANTIC)
check_cxx_compiler_flag("-Werror -Wcovered-switch-default" CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG)
- if( CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG )
- set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcovered-switch-default" )
- endif()
+ append_if(CMAKE_CXX_FLAGS "-Wcovered-switch-default" CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG)
check_c_compiler_flag("-Werror -Wcovered-switch-default" C_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG)
- if( C_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG )
- set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcovered-switch-default" )
- endif()
- if (USE_NO_UNINITIALIZED)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-uninitialized")
- endif()
- if (USE_NO_MAYBE_UNINITIALIZED)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-maybe-uninitialized")
- endif()
+ append_if(CMAKE_C_FLAGS "-Wcovered-switch-default" C_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG)
+ append_if(CMAKE_CXX_FLAGS "-Wno-uninitialized" USE_NO_UNINITIALIZED)
+ append_if(CMAKE_CXX_FLAGS "-Wno-maybe-uninitialized" USE_NO_MAYBE_UNINITIALIZED)
endif (LLVM_ENABLE_WARNINGS)
if (LLVM_ENABLE_WERROR)
add_llvm_definitions( -Werror )
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D535.1.patch
Type: text/x-patch
Size: 3754 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130313/2c0a5791/attachment.bin>
More information about the llvm-commits
mailing list