ref: f1740a2c5e0d2fce39ae009a5c1324dd04989a92
parent: ed1ff2f275ff2f43cb0cad64cf40a2a032349016
author: Clownacy <Clownacy@users.noreply.github.com>
date: Wed Jan 29 20:19:45 EST 2020
Add native-optimisations and LTO to DoConfig and bin2h Forgot bin2h even had a CMake file
--- a/DoConfig/CMakeLists.txt
+++ b/DoConfig/CMakeLists.txt
@@ -9,6 +9,8 @@
endif()
option(LTO "Enable link-time optimisation" OFF)
+option(NATIVE_OPTIMIZATIONS "Enable processor-specific optimisations (executable might not work on other architectures) (GCC-compatible compilers only)" OFF)
+
option(WARNINGS "Enable common compiler warnings (for GCC-compatible compilers and MSVC only)" OFF)
option(WARNINGS_ALL "Enable ALL compiler warnings (for Clang and MSVC only)" OFF)
option(WARNINGS_FATAL "Stop compilation on any compiler warning (for GCC-compatible compilers and MSVC only)" OFF)
@@ -54,7 +56,7 @@
# if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
# string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
# else()
- # target_compile_options(CSE2 PRIVATE /W4)
+ # target_compile_options(DoConfig PRIVATE /W4)
# endif()
target_compile_options(DoConfig PRIVATE /W4)
@@ -75,7 +77,7 @@
# if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
# string(REGEX REPLACE "/W[0-4]" "/Wall" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
# else()
- # target_compile_options(CSE2 PRIVATE /Wall)
+ # target_compile_options(DoConfig PRIVATE /Wall)
# endif()
target_compile_options(DoConfig PRIVATE /Wall)
@@ -147,6 +149,25 @@
check_ipo_supported(RESULT result)
if(result)
set_target_properties(DoConfig PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
+ endif()
+ endif()
+endif()
+
+# Enable -march=native if available
+if(NATIVE_OPTIMIZATIONS)
+ include(CheckCXXCompilerFlag)
+ CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) # GCC flag
+ if(COMPILER_SUPPORTS_MARCH_NATIVE)
+ target_compile_options(DoConfig PRIVATE -march=native)
+ else()
+ CHECK_CXX_COMPILER_FLAG("-xHost" COMPILER_SUPPORTS_XHOST) # ICC (Linux) flag
+ CHECK_CXX_COMPILER_FLAG("/QxHost" COMPILER_SUPPORTS_QXHOST) # ICC (Windows) flag
+ if(COMPILER_SUPPORTS_XHOST)
+ target_compile_options(DoConfig PRIVATE -xHost)
+ elseif(COMPILER_SUPPORTS_QXHOST)
+ target_compile_options(DoConfig PRIVATE /QxHost)
+ else()
+ message(WARNING "Couldn't activate native optimizations ! (Unsupported compiler)")
endif()
endif()
endif()
--- a/bin2h/CMakeLists.txt
+++ b/bin2h/CMakeLists.txt
@@ -4,6 +4,9 @@
cmake_policy(SET CMP0069 NEW)
endif()
+option(LTO "Enable link-time optimisation" OFF)
+option(NATIVE_OPTIMIZATIONS "Enable processor-specific optimisations (executable might not work on other architectures) (GCC-compatible compilers only)" OFF)
+
option(WARNINGS "Enable common compiler warnings (for gcc-compatible compilers and MSVC only)" OFF)
option(WARNINGS_ALL "Enable ALL compiler warnings (for clang and MSVC only)" OFF)
option(WARNINGS_FATAL "Stop compilation on any compiler warning (for gcc-compatible compilers and MSVC only)" OFF)
@@ -54,7 +57,7 @@
# if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
# string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
# else()
- # target_compile_options(CSE2 PRIVATE /W4)
+ # target_compile_options(bin2h PRIVATE /W4)
# endif()
target_compile_options(bin2h PRIVATE /W4)
@@ -75,7 +78,7 @@
# if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
# string(REGEX REPLACE "/W[0-4]" "/Wall" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
# else()
- # target_compile_options(CSE2 PRIVATE /Wall)
+ # target_compile_options(bin2h PRIVATE /Wall)
# endif()
target_compile_options(bin2h PRIVATE /Wall)
@@ -90,10 +93,8 @@
# HACK : Replace this with CMake provided stuff when possible (when CMake makes avoiding this possible (it isn't currently))
if (MSVC)
- target_compile_options(CSE2 PRIVATE /WX)
target_compile_options(bin2h PRIVATE /WX)
elseif(COMPILER_IS_GCC_COMPATIBLE)
- target_compile_options(CSE2 PRIVATE -Werror)
target_compile_options(bin2h PRIVATE -Werror)
else()
message(WARNING "Could not activate fatal warnings ! (Unsupported compiler)")
@@ -115,6 +116,36 @@
check_ipo_supported(RESULT result)
if(result)
set_target_properties(bin2h PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
+ endif()
+ endif()
+endif()
+
+# Enable link-time optimisation if available
+if(LTO)
+ if((${CMAKE_VERSION} VERSION_EQUAL 3.9) OR (${CMAKE_VERSION} VERSION_GREATER 3.9))
+ include(CheckIPOSupported)
+ check_ipo_supported(RESULT result)
+ if(result)
+ set_target_properties(bin2h PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
+ endif()
+ endif()
+endif()
+
+# Enable -march=native if available
+if(NATIVE_OPTIMIZATIONS)
+ include(CheckCXXCompilerFlag)
+ CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) # GCC flag
+ if(COMPILER_SUPPORTS_MARCH_NATIVE)
+ target_compile_options(bin2h PRIVATE -march=native)
+ else()
+ CHECK_CXX_COMPILER_FLAG("-xHost" COMPILER_SUPPORTS_XHOST) # ICC (Linux) flag
+ CHECK_CXX_COMPILER_FLAG("/QxHost" COMPILER_SUPPORTS_QXHOST) # ICC (Windows) flag
+ if(COMPILER_SUPPORTS_XHOST)
+ target_compile_options(bin2h PRIVATE -xHost)
+ elseif(COMPILER_SUPPORTS_QXHOST)
+ target_compile_options(bin2h PRIVATE /QxHost)
+ else()
+ message(WARNING "Couldn't activate native optimizations ! (Unsupported compiler)")
endif()
endif()
endif()
--
⑨