Add convenience functions to CMakeLists.txt

The helper functions allow setting compiler flags only if compiler
supports them.
This commit is contained in:
Michał Janiszewski 2016-10-22 22:20:37 +02:00
parent 88ccfad303
commit c70639302c
1 changed files with 36 additions and 0 deletions

View File

@ -60,8 +60,44 @@ execute_process(
)
add_definitions(-DOPENRCT2_COMMIT_SHA1_SHORT="${OPENRCT2_COMMIT_SHA1_SHORT}")
# Convenience functions to set compiler flags only if available
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
function(ADD_CHECK_C_COMPILER_FLAG
_CFLAGS
_CACHE_VAR
_FLAG
)
CHECK_C_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}")
if(${_CACHE_VAR})
# message(STATUS "Using CFLAG: ${_FLAG}")
set(${_CFLAGS} "${${_CFLAGS}} ${_FLAG}" PARENT_SCOPE)
else()
message(STATUS "Unsupported CFLAG: ${_FLAG}")
endif()
endfunction()
function(ADD_CHECK_CXX_COMPILER_FLAG
_CXXFLAGS
_CACHE_VAR
_FLAG
)
CHECK_CXX_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}")
if(${_CACHE_VAR})
# message(STATUS "Using CXXFLAG: ${_FLAG}")
set(${_CXXFLAGS} "${${_CXXFLAGS}} ${_FLAG}" PARENT_SCOPE)
else()
message(STATUS "Unsupported CXXFLAG: ${_FLAG}")
endif()
endfunction()
# pkg-config
INCLUDE(FindPkgConfig)
# Needed for linking with non-broken OpenSSL on Apple platforms
if (APPLE)
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/opt/openssl/lib/pkgconfig")
endif (APPLE)