Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: Restructure CMake CFLAGS for and ensure they are set #475

Merged
merged 1 commit into from
May 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,19 @@ if (WITH_TESTS)
set(NEED_THREADS 1)
endif()

if (NOT LOG_LEVEL)
set(LOG_LEVEL Info CACHE STRING "Log level" FORCE)
set_property(CACHE LOG_LEVEL PROPERTY STRINGS NoLog Error Warning Info Debug)
endif()

if (MSVC)
# Avoid annoying warnings from Visual Studio
add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)

set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll.a" ".a" ".lib")
endif()

if (NOT LOG_LEVEL)
set(LOG_LEVEL Info CACHE STRING "Log level" FORCE)
set_property(CACHE LOG_LEVEL PROPERTY STRINGS NoLog Error Warning Info Debug)
endif()

if (CMAKE_COMPILER_IS_GNUCC)
elseif (CMAKE_COMPILER_IS_GNUCC)
if (NOT WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
endif()
Expand All @@ -86,17 +85,27 @@ if (CMAKE_COMPILER_IS_GNUCC)
endif()
endif()
if(DEFINED ENV{TRAVIS} AND DEFINED ENV{CI})
message(STATUS "Running in a Travis-CI environment, setting -Werror")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
endif()
endif()

if(APPLE)
#full Single Unix Standard v3 (SUSv3) conformance (the Unix API)
add_definitions(-D_DARWIN_C_SOURCE)
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -Wno-unused-parameter -Wno-sign-compare")
if(DEFINED ENV{TRAVIS} AND DEFINED ENV{CI})
message(STATUS "Running in a Travis-CI environment, setting -Werror")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
endif()

else()
message(STATUS "Unknown compiler, please report upstream")
message(STATUS "CMAKE_C_COMPILER_ID : " ${CMAKE_C_COMPILER_ID})
message(STATUS "CFLAGS set to " ${CMAKE_C_FLAGS})
endif()

# No matter what compiler you are using, set this on macos
if(APPLE)
#full Single Unix Standard v3 (SUSv3) conformance (the Unix API)
add_definitions(-D_DARWIN_C_SOURCE)
endif()

include(CheckSymbolExists)
Expand Down