Skip to content

Commit

Permalink
Update compile flags
Browse files Browse the repository at this point in the history
  • Loading branch information
SupSuper committed Mar 9, 2019
1 parent af1621b commit 80b31dd
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ set(CMAKE_C_FLAGS_QUICK "-O1 -g0")
set(CMAKE_CXX_FLAGS_QUICK "-O1 -g0")


CHECK_CXX_COMPILER_FLAG("-flto"
COMPILER_SUPPORTS_LTO)
CHECK_CXX_COMPILER_FLAG("-flto=4"
COMPILER_SUPPORTS_LTO4)

CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden"
CXX_COMPILER_SUPPORTS_HIDDEN_VISIBILITY)
CHECK_C_COMPILER_FLAG("-fvisibility=hidden"
Expand All @@ -55,11 +50,20 @@ if (C_COMPILER_SUPPORTS_HIDDEN_VISIBILITY)
endif()

if (LTO)
CHECK_CXX_COMPILER_FLAG("-flto"
COMPILER_SUPPORTS_LTO)
CHECK_CXX_COMPILER_FLAG("-flto=4"
COMPILER_SUPPORTS_LTO4)

if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
set(CMAKE_AR gcc-ar)
set(CMAKE_RANLIB gcc-ranlib)
endif()
if (COMPILER_SUPPORTS_LTO4)

if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GL")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LTGC")
elseif (COMPILER_SUPPORTS_LTO4)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto=4")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto=4")
elseif(COMPILER_SUPPORTS_LTO)
Expand All @@ -77,21 +81,23 @@ CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)

if (COMPILER_SUPPORTS_CXX17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
elseif (COMPILER_SUPPORTS_CXX14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
elseif (COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
# Other compilers may use different option flags, or not support switching standard versions, so try anyway
message(WARNING "Couldn't find a c++ version this compiler supports, trying with default options")
# Other compilers may use different option flags, or not support switching standard versions, so try anyway
message(WARNING "Couldn't find a c++ version this compiler supports, trying with default options")
endif()

# MSVC has default flags that CMake doesn't set
if (MSVC)
add_definitions(-DUNICODE -D_UNICODE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /permissive-")
add_definitions(-DUNICODE -D_UNICODE -D_CRT_SECURE_NO_WARNINGS)
if (MSVC_VERSION GREATER_EQUAL 1910)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /permissive-")
endif()
endif()

# Clang whines about unused arguments, which is annoying (for example) when
Expand Down

0 comments on commit 80b31dd

Please sign in to comment.