Skip to content

Commit 9ee8c7f

Browse files
committed
cmake: Restructure CMake CFLAGS for clang
In the past CFLAGS for Clang was not set on x86, now it is. Print a warning if we don't know what the compiler is. Signed-off-by: Robin Getz <[email protected]>
1 parent a0994c5 commit 9ee8c7f

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

CMakeLists.txt

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,19 @@ if (WITH_TESTS)
5353
set(NEED_THREADS 1)
5454
endif()
5555

56+
if (NOT LOG_LEVEL)
57+
set(LOG_LEVEL Info CACHE STRING "Log level" FORCE)
58+
set_property(CACHE LOG_LEVEL PROPERTY STRINGS NoLog Error Warning Info Debug)
59+
endif()
60+
5661
if (MSVC)
5762
# Avoid annoying warnings from Visual Studio
5863
add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)
5964

6065
set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "")
6166
set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll.a" ".a" ".lib")
62-
endif()
63-
64-
if (NOT LOG_LEVEL)
65-
set(LOG_LEVEL Info CACHE STRING "Log level" FORCE)
66-
set_property(CACHE LOG_LEVEL PROPERTY STRINGS NoLog Error Warning Info Debug)
67-
endif()
6867

69-
if (CMAKE_COMPILER_IS_GNUCC)
68+
elseif (CMAKE_COMPILER_IS_GNUCC)
7069
if (NOT WIN32)
7170
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
7271
endif()
@@ -86,17 +85,27 @@ if (CMAKE_COMPILER_IS_GNUCC)
8685
endif()
8786
endif()
8887
if(DEFINED ENV{TRAVIS} AND DEFINED ENV{CI})
88+
message(STATUS "Running in a Travis-CI environment, setting -Werror")
8989
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
9090
endif()
91-
endif()
9291

93-
if(APPLE)
94-
#full Single Unix Standard v3 (SUSv3) conformance (the Unix API)
95-
add_definitions(-D_DARWIN_C_SOURCE)
92+
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
9693
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -Wno-unused-parameter -Wno-sign-compare")
9794
if(DEFINED ENV{TRAVIS} AND DEFINED ENV{CI})
95+
message(STATUS "Running in a Travis-CI environment, setting -Werror")
9896
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
9997
endif()
98+
99+
else()
100+
message(STATUS "Unknown compiler, please report upstream")
101+
message(STATUS "CMAKE_C_COMPILER_ID : " ${CMAKE_C_COMPILER_ID})
102+
message(STATUS "CFLAGS set to " ${CMAKE_C_FLAGS})
103+
endif()
104+
105+
# No matter what compiler you are using, set this on macos
106+
if(APPLE)
107+
#full Single Unix Standard v3 (SUSv3) conformance (the Unix API)
108+
add_definitions(-D_DARWIN_C_SOURCE)
100109
endif()
101110

102111
include(CheckSymbolExists)

0 commit comments

Comments
 (0)