File: AddCFlagIfSupported.cmake

package info (click to toggle)
libgit2 1.9.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 60,804 kB
  • sloc: ansic: 203,436; javascript: 2,458; sh: 1,763; python: 384; perl: 99; php: 65; makefile: 33
file content (30 lines) | stat: -rw-r--r-- 1,004 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# - Append compiler flag to CMAKE_C_FLAGS if compiler supports it
# ADD_C_FLAG_IF_SUPPORTED(<flag>)
#  <flag> - the compiler flag to test
# This internally calls the CHECK_C_COMPILER_FLAG macro.

include(CheckCCompilerFlag)

macro(ADD_C_FLAG _FLAG)
	string(TOUPPER ${_FLAG} UPCASE)
	string(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE})
	string(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY})
	check_c_compiler_flag(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED)

	if(IS_${UPCASE_PRETTY}_SUPPORTED)
		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}")
	else()
		message(FATAL_ERROR "Required flag ${_FLAG} is not supported")
	endif()
endmacro()

macro(ADD_C_FLAG_IF_SUPPORTED _FLAG)
	string(TOUPPER ${_FLAG} UPCASE)
	string(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE})
	string(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY})
	check_c_compiler_flag(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED)

	if(IS_${UPCASE_PRETTY}_SUPPORTED)
		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}")
	endif()
endmacro()