Enable OpenMP when it is found in CMakeLists.txt and add two variables called IS_GNU and IS_CLANG
This commit is contained in:
parent
2b84262ea0
commit
e6e12a26ec
|
@ -31,6 +31,8 @@ endif()
|
|||
set(CMAKE_CXX_FLAGS "-Wall")
|
||||
set(MINIMAL_GNU "11.0")
|
||||
set(MINIMAL_CLANG "13.0")
|
||||
set(IS_GNU (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU))
|
||||
set(IS_CLANG (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang))
|
||||
|
||||
if (NOT MSVC)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
||||
|
@ -45,8 +47,14 @@ if(CCACHE_PRESENT)
|
|||
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
|
||||
endif(CCACHE_PRESENT)
|
||||
|
||||
if ((${CMAKE_CXX_COMPILER_ID} STREQUAL GNU) OR (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang))
|
||||
set(CMAKE_CXX_FLAGS "-flto ${CMAKE_CXX_FLAGS} -pipe -fstack-protector-strong -fstack-clash-protection -funwind-tables -fasynchronous-unwind-tables -fexceptions")
|
||||
if (${IS_GNU} OR ${IS_CLANG})
|
||||
if (NOT (MINGW AND ${IS_CLANG})) # llvm-mingw linux packages don't bundle openmp
|
||||
include(FindOpenMP)
|
||||
if (OpenMP_CXX_FOUND)
|
||||
add_definitions(-D_GLIBCXX_PARALLEL)
|
||||
endif()
|
||||
endif()
|
||||
set(CMAKE_CXX_FLAGS "-flto ${OpenMP_CXX_FLAGS} ${CMAKE_CXX_FLAGS} -pipe -fstack-protector-strong -fstack-clash-protection -funwind-tables -fasynchronous-unwind-tables -fexceptions")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ffunction-sections -fdata-sections -fmerge-all-constants -ftree-vectorize")
|
||||
include(CheckCXXCompilerFlag)
|
||||
set(CF_PROTECTION "-fcf-protection")
|
||||
|
@ -56,13 +64,13 @@ if ((${CMAKE_CXX_COMPILER_ID} STREQUAL GNU) OR (${CMAKE_CXX_COMPILER_ID} STREQUA
|
|||
endif()
|
||||
endif()
|
||||
|
||||
if (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
|
||||
if (${IS_GNU})
|
||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MINIMAL_GNU})
|
||||
message(FATAL_ERROR "G++ ${MINIMAL_GNU} or higher is required.")
|
||||
endif()
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -foptimize-strlen -fsched-pressure -flive-range-shrinkage -fpredictive-commoning -ftree-partial-pre -fira-loop-pressure -ftree-loop-distribution -floop-interchange -fsplit-paths -fgcse-las -fgcse-sm -fipa-pta -fstdarg-opt -fivopts -s")
|
||||
set(CMAKE_CXX_FLAGS "-fno-use-linker-plugin -fwhole-program ${CMAKE_CXX_FLAGS}")
|
||||
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
|
||||
elseif(${IS_CLANG})
|
||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MINIMAL_CLANG})
|
||||
message(FATAL_ERROR "Clang ${MINIMAL_CLANG} or higher is required.")
|
||||
endif()
|
||||
|
|
Loading…
Reference in New Issue