toxcore/cmake/AddCompilerFlag.cmake
iphydf cda770cfe1
Forbid undefined symbols in shared libraries.
Also a little bit of refactoring:
- Moved add_cflag and friends from CMakeLists.txt to a separate
  AddCompilerFlag module.
- Build the spectest SUT if msgpack is found, even if spectest itself is
  not found, so once it exists, users can run it themselves or
  reconfigure cmake.
2017-06-04 10:08:51 +00:00

47 lines
1.3 KiB
CMake

include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
function(add_cflag flag)
string(REGEX REPLACE "[^a-zA-Z0-9_]" "_" var ${flag})
if(NOT DEFINED HAVE_C${var})
message(STATUS "checking for C compiler flag: ${flag}")
endif()
set(CMAKE_REQUIRED_QUIET TRUE)
check_c_compiler_flag("${flag}" HAVE_C${var} QUIET)
if(HAVE_C${var})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE)
endif()
endfunction()
function(add_cxxflag flag)
string(REGEX REPLACE "[^a-zA-Z0-9_]" "_" var ${flag})
if(NOT DEFINED HAVE_CXX${var})
message(STATUS "checking for C++ compiler flag: ${flag}")
endif()
set(CMAKE_REQUIRED_QUIET TRUE)
check_cxx_compiler_flag("${flag}" HAVE_CXX${var} QUIET)
if(HAVE_CXX${var})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE)
endif()
endfunction()
function(add_dllflag flag)
string(REGEX REPLACE "[^a-zA-Z0-9_]" "_" var ${flag})
if(NOT DEFINED HAVE_LD${var})
message(STATUS "checking for C++ compiler flag: ${flag}")
endif()
set(CMAKE_REQUIRED_QUIET TRUE)
check_c_compiler_flag("${flag}" HAVE_LD${var} QUIET)
if(HAVE_LD${var})
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${flag}" PARENT_SCOPE)
endif()
endfunction()
macro(add_flag flag)
add_cflag(${flag})
add_cxxflag(${flag})
endmacro()