Skip to content

Commit ee3cdbf

Browse files
committed
further simplifications
* only support the CMake standard way to define variables via `-DFOO=On` and not via the environment * clean-up switches only used for unit tests * mingw's ID is "gcc", so we match on the full compiler name instead * use `CMAKE_SYSTEM_NAME` instead of `$ENV{PLATFORM}` * unconditionally set {C,LD}FLAGS passed by user Signed-off-by: Steffen Jaeckel <[email protected]>
1 parent bafc708 commit ee3cdbf

File tree

1 file changed

+15
-34
lines changed

1 file changed

+15
-34
lines changed

CMakeLists.txt

+15-34
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,16 @@ option(BUILD_SHARED_LIBS "Build shared library and only the shared library if \"
2626
# Basic set
2727
set(LTM_C_FLAGS -Wall -Wsign-compare -Wextra -Wshadow)
2828
set(LTM_C_FLAGS ${LTM_C_FLAGS} -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align)
29-
set(LTM_C_FLAGS ${LTM_C_FLAGS} -Wstrict-prototypes -Wpointer-arith)
29+
set(LTM_C_FLAGS ${LTM_C_FLAGS} -Wstrict-prototypes -Wpointer-arith -Wsystem-headers)
3030

31-
# Do we run the sanitizer?
32-
if(DEFINED ENV{SANITIZER})
33-
set(LTM_C_FLAGS ${LTM_C_FLAGS} -fsanitize=undefined -fno-sanitize-recover=all -fno-sanitize=float-divide-by-zero)
34-
endif()
35-
36-
if(DEFINED ENV{CONV_WARNINGS})
37-
set(LTM_C_FLAGS ${LTM_C_FLAGS} -std=c89 -Wconversion -Wsign-conversion)
38-
if($ENV{CONV_WARNINGS} EQUAL "strict")
39-
set(LTM_C_FLAGS ${LTM_C_FLAGS} -Wc++-compat)
40-
endif()
41-
else()
42-
set(LTM_C_FLAGS ${LTM_C_FLAGS} -Wsystem-headers)
43-
endif()
44-
45-
if(DEFINED ENV{COMPILE_DEBUG})
31+
if(COMPILE_DEBUG)
4632
set(LTM_C_FLAGS ${LTM_C_FLAGS} -g3)
4733
endif()
4834

49-
if(DEFINED ENV{COMPILE_SIZE})
35+
if(COMPILE_SIZE)
5036
set(LTM_C_FLAGS ${LTM_C_FLAGS} -Os)
5137
else()
52-
if(NOT DEFINED ENV{IGNORE_SPEED})
38+
if(NOT IGNORE_SPEED)
5339
set(LTM_C_FLAGS ${LTM_C_FLAGS} -O3 -funroll-loops)
5440
#x86 optimizations [should be valid for any GCC install though]
5541
set(LTM_C_FLAGS ${LTM_C_FLAGS} -fomit-frame-pointer)
@@ -67,33 +53,28 @@ endif()
6753

6854
# What compiler do we have and what are their...uhm... peculiarities
6955
# TODO: is the check for a C++ compiler necessary?
70-
if( (CMAKE_C_COMPILER_ID MATCHES "(C|c?)lang") OR (CMAKE_CXX_COMPILER_ID MATCHES "(C|c?)lang"))
56+
if(CMAKE_C_COMPILER_ID MATCHES "(C|c?)lang")
7157
set(LTM_C_FLAGS ${LTM_C_FLAGS} -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header)
7258
endif()
73-
74-
if( (CMAKE_C_COMPILER_ID MATCHES "mingw") OR (CMAKE_CXX_COMPILER_ID MATCHES "mingw"))
59+
if(CMAKE_C_COMPILER MATCHES "mingw")
7560
set(LTM_C_FLAGS ${LTM_C_FLAGS} -Wno-shadow)
7661
endif()
7762

78-
if(DEFINED ENV{PLATFORM})
79-
if($ENV{PLATFORM} MATCHES "Darwin")
80-
set(LTM_C_FLAGS ${LTM_C_FLAGS} -Wno-nullability-completeness)
81-
endif()
82-
if($ENV{PLATFORM} MATCHES "CYGWIN")
83-
set(LTM_C_FLAGS ${LTM_C_FLAGS} -no-undefined)
84-
endif()
63+
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
64+
set(LTM_C_FLAGS ${LTM_C_FLAGS} -Wno-nullability-completeness)
65+
endif()
66+
if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN")
67+
set(LTM_C_FLAGS ${LTM_C_FLAGS} -no-undefined)
8568
endif()
8669

8770
# TODO: coverage (lgcov)
8871

8972
# If the user set the environment variables at generate-time, append them
9073
# in order to allow overriding our defaults.
91-
if(DEFINED ENV{LTM_CFLAGS})
92-
set(LTM_C_FLAGS ${LTM_C_FLAGS} $ENV{LTM_CFLAGS})
93-
endif()
94-
if(DEFINED ENV{LTM_LDFLAGS})
95-
set(LTM_LD_FLAGS ${LTM_LD_FLAGS} $ENV{LTM_LDFLAGS})
96-
endif()
74+
# ${LTM_CFLAGS} means the user passed it via sth like:
75+
# $ cmake -DLTM_CFLAGS="foo"
76+
set(LTM_C_FLAGS ${LTM_C_FLAGS} ${LTM_CFLAGS})
77+
set(LTM_LD_FLAGS ${LTM_LD_FLAGS} ${LTM_LDFLAGS})
9778

9879
#-----------------------------------------------------------------------------
9980
# library target

0 commit comments

Comments
 (0)