Skip to content

Commit

Permalink
only apply optional flags when compiler works
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Apr 6, 2020
1 parent 8900fa5 commit 418d59b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.15)
project(ninja)

# --- optional link-time optimization
if(CMAKE_BUILD_TYPE MATCHES "Release")
include(CheckIPOSupported)
check_ipo_supported(RESULT lto_supported OUTPUT error)
Expand All @@ -13,13 +14,23 @@ if(CMAKE_BUILD_TYPE MATCHES "Release")
endif()
endif()

# --- compiler flags
if(MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
string(APPEND CMAKE_CXX_FLAGS " /W4 /GR- /Zc:__cplusplus")
else()
string(APPEND CMAKE_CXX_FLAGS " -Wno-deprecated -fdiagnostics-color")
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-Wno-deprecated flag_no_deprecated)
if(flag_no_deprecated)
string(APPEND CMAKE_CXX_FLAGS " -Wno-deprecated")
endif()
check_cxx_compiler_flag(-fdiagnostics-color flag_color_diag)
if(flag_color_diag)
string(APPEND CMAKE_CXX_FLAGS " -fdiagnostics-color")
endif()
endif()

# --- optional re2c
find_program(RE2C re2c)
if(RE2C)
# the depfile parser and ninja lexers are generated using re2c.
Expand Down

0 comments on commit 418d59b

Please sign in to comment.