Skip to content

Commit 9ffe8da

Browse files
aperezdczdobersek
authored andcommitted
cmake: Pass -Wall and check that compiler flags are supported (#51)
Adds checks to ensure that command line flags passed to the C/C++ copmilers are supported before adding them to the list of flags. This also leaves to CMake the responsibility of determining which compiler flags are needed to choose C++11/C99, instead of passing -std=xyz, because different compilers might use other options for this.
1 parent 0862a9e commit 9ffe8da

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

CMakeLists.txt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,25 @@ CALCULATE_LIBRARY_VERSIONS_FROM_LIBTOOL_TRIPLE(LIBWPE 3 1 2)
1818

1919
project(libwpe VERSION "${PROJECT_VERSION}")
2020

21-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -D_POSIX_SOURCE")
22-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
21+
include(CheckCCompilerFlag)
22+
include(CheckCXXCompilerFlag)
23+
24+
set(CMAKE_CXX_STANDARD 11)
25+
set(CMAKE_C_STANDARD 99)
26+
27+
foreach (cxxflag -fno-exceptions -fno-rtti -Wall)
28+
check_cxx_compiler_flag("${cxxflag}" CXX_HAS_FLAG_${cxxflag})
29+
if (CXX_HAS_FLAG_${cxxflag})
30+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${cxxflag}")
31+
endif ()
32+
endforeach ()
33+
34+
foreach (cflag -Wall)
35+
check_c_compiler_flag("${cflag}" CC_HAS_FLAG_${cflag})
36+
if (CC_HAS_FLAG_${cflag})
37+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${cflag}")
38+
endif ()
39+
endforeach ()
2340

2441
set(DERIVED_SOURCES_DIR "${CMAKE_BINARY_DIR}/DerivedSources/wpe")
2542
configure_file(include/wpe/version.h.cmake ${DERIVED_SOURCES_DIR}/version.h @ONLY)

0 commit comments

Comments
 (0)