More CMake: Add flags from dpkg-buildflags to CMake flags
Use same compiler flags that the Debian tools will use when generating
packages
Don't fail due to using "__DATE__" or "__TIME__": add flag "-Wno-error
=date-time"
@@ -3,18 +3,30 @@ cmake_minimum_required(VERSION 2.8)
project("kms-core")
message(STATUS "Running CMake for project: ${PROJECT_NAME}")
-# Set GCC flags common to all projects
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -Wall -Werror")
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror")
+message("If KurentoHelpers is not found, you need to install 'kms-cmake-utils' from the Kurento repository")
+find_package(KurentoHelpers REQUIRED)
-# Reduce default Release optimization level from -O3 to -O2
-set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")
-set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
+# Set GCC flags common to all projects
+# Note - default flags added by dpkg-buildflags for C and C++:
+# -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2
+include(DpkgBuildFlags)
+get_dpkg_buildflags_c(DPKG_BUILDFLAGS_C)
+get_dpkg_buildflags_cxx(DPKG_BUILDFLAGS_CXX)
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DPKG_BUILDFLAGS_C} -std=c11 -Wall -Werror")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DPKG_BUILDFLAGS_CXX} -std=c++11 -Wall -Werror")
+
+# Disable error when macros __TIME__, __DATE__ or __TIMESTAMP__ are encountered
+include(CheckCXXCompilerFlag)
+CHECK_CXX_COMPILER_FLAG("-Wno-error=date-time" HAS_WARNING_DATE_TIME)
+if(HAS_WARNING_DATE_TIME)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=date-time")
+endif()
# This project includes an input "config.h.cmake"
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_CONFIG_H")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_CONFIG_H")
+# Decide between std::regex or boost::regex
include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_FLAGS ${CMAKE_CXX_FLAGS})
check_cxx_source_compiles(
@@ -31,9 +43,6 @@ check_cxx_source_compiles(
HAS_STD_REGEX_REPLACE
)
-message("If KurentoHelpers is not found, you need to install 'kms-cmake-utils' from the Kurento repository")
-find_package(KurentoHelpers REQUIRED)
-
if(DEFINED CMAKE_MODULE_PATH)
list(REVERSE CMAKE_MODULE_PATH)
endif()
