@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.9)
2
2
3
3
project (quickjs LANGUAGES C )
4
4
5
+ include (CheckCCompilerFlag )
5
6
include (GNUInstallDirs )
6
7
7
8
# TODO:
@@ -11,44 +12,43 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
11
12
set (CMAKE_C_EXTENSIONS ON )
12
13
set (CMAKE_C_STANDARD 11 )
13
14
14
- add_compile_options (
15
- -Wall
16
- -Werror
17
- )
18
- if (CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang" )
19
- add_compile_options (
20
- -Wextra
21
- -Wno-sign-compare
22
- -Wno-missing-field-initializers
23
- -Wno-unused-parameter
24
- -Wno-unused-variable
25
- -Wno-unused-but-set-variable
26
- -funsigned-char
27
- )
28
- else ()
29
- add_compile_options (
30
- -Wno-array-bounds
31
- -Wno-format-truncation
32
- -Wno-unused-variable
33
- -Wno-unused-but-set-variable
34
- )
35
- endif ()
36
-
37
15
if (NOT CMAKE_BUILD_TYPE )
38
16
message (STATUS "No build type selected, default to Release" )
39
17
set (CMAKE_BUILD_TYPE "Release" )
40
18
endif ()
41
19
42
20
message (STATUS "Building in ${CMAKE_BUILD_TYPE} mode" )
43
21
message (STATUS "Building with ${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION} on ${CMAKE_SYSTEM} " )
22
+
23
+ macro (xcheck_add_c_compiler_flag FLAG )
24
+ string (REPLACE "-" "" FLAG_NO_HYPHEN ${FLAG} )
25
+ check_c_compiler_flag (${FLAG} COMPILER_SUPPORTS_${FLAG_NO_HYPHEN} )
26
+ if (COMPILER_SUPPORTS_${FLAG_NO_HYPHEN} )
27
+ add_compile_options (${FLAG} )
28
+ endif ()
29
+ endmacro ()
30
+
31
+ xcheck_add_c_compiler_flag (-Wall )
32
+ xcheck_add_c_compiler_flag (-Werror )
33
+ # -Wextra is too spartan on GCC
34
+ if (CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang" )
35
+ add_compile_options (-Wextra )
36
+ endif ()
37
+ xcheck_add_c_compiler_flag (-Wno-sign-compare )
38
+ xcheck_add_c_compiler_flag (-Wno-missing-field-initializers )
39
+ xcheck_add_c_compiler_flag (-Wno-unused-parameter )
40
+ xcheck_add_c_compiler_flag (-Wno-unused-variable )
41
+ xcheck_add_c_compiler_flag (-Wno-unused-but-set-variable )
42
+ xcheck_add_c_compiler_flag (-Wno-array-bounds )
43
+ xcheck_add_c_compiler_flag (-Wno-format-truncation )
44
+ xcheck_add_c_compiler_flag (-funsigned-char )
45
+
44
46
if (CMAKE_BUILD_TYPE MATCHES "Debug" )
45
- add_compile_options (
46
- -ggdb
47
- -O0
48
- -fno-omit-frame-pointer
49
- )
47
+ add_compile_options (-O0 )
48
+ xcheck_add_c_compiler_flag (-ggdb )
49
+ xcheck_add_c_compiler_flag (-fno-omit-frame-pointer )
50
50
else ()
51
- add_compile_options (-g )
51
+ xcheck_add_c_compiler_flag (-g )
52
52
endif ()
53
53
54
54
macro (xoption OPTION_NAME OPTION_TEXT OPTION_DEFAULT )
0 commit comments