From be664c49c8dd7487470ab2ad50909cbfbd082efd Mon Sep 17 00:00:00 2001 From: arcnmx Date: Fri, 23 Jul 2021 17:25:42 -0700 Subject: [PATCH] [all] cmake: use -march=x86-64-v2 when it becomes available Moves the logic in 0525515 to a common cmake include, and applies it to the other binaries. --- client/CMakeLists.txt | 14 +++----------- cmake/OptimizeForNative.cmake | 17 +++++++++++++++++ host/CMakeLists.txt | 23 +++-------------------- obs/CMakeLists.txt | 12 +++--------- profile/client/CMakeLists.txt | 12 +++--------- 5 files changed, 29 insertions(+), 49 deletions(-) create mode 100644 cmake/OptimizeForNative.cmake diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 4ae08556..63b92d30 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -1,21 +1,14 @@ cmake_minimum_required(VERSION 3.0) project(looking-glass-client C CXX) -list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/") +get_filename_component(PROJECT_TOP "${PROJECT_SOURCE_DIR}/.." ABSOLUTE) +list(APPEND CMAKE_MODULE_PATH "${PROJECT_TOP}/cmake/" "${PROJECT_SOURCE_DIR}/cmake/") include(GNUInstallDirs) include(CheckCCompilerFlag) include(FeatureSummary) -option(OPTIMIZE_FOR_NATIVE "Build with -march=native" ON) -if(OPTIMIZE_FOR_NATIVE) - CHECK_C_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) - if(COMPILER_SUPPORTS_MARCH_NATIVE) - add_compile_options("-march=native") - endif() -else() - add_compile_options("-march=nehalem" "-mtune=generic") -endif() +include(OptimizeForNative) # option(OPTIMIZE_FOR_NATIVE) find_package(PkgConfig) pkg_check_modules(FONTCONFIG_PKGCONFIG REQUIRED fontconfig) @@ -87,7 +80,6 @@ find_package(GMP) add_definitions(-D ATOMIC_LOCKING) add_definitions(-D GL_GLEXT_PROTOTYPES) -get_filename_component(PROJECT_TOP "${PROJECT_SOURCE_DIR}/.." ABSOLUTE) add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/version.c diff --git a/cmake/OptimizeForNative.cmake b/cmake/OptimizeForNative.cmake new file mode 100644 index 00000000..a2c5f92c --- /dev/null +++ b/cmake/OptimizeForNative.cmake @@ -0,0 +1,17 @@ +option(OPTIMIZE_FOR_NATIVE "Build with -march=native" OFF) +if(OPTIMIZE_FOR_NATIVE) + CHECK_C_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) + if(COMPILER_SUPPORTS_MARCH_NATIVE) + add_compile_options("-march=native") + endif() +else() + CHECK_C_COMPILER_FLAG("-march=x86-64-v2" COMPILER_SUPPORTS_MARCH_X86_64_V2) + if(COMPILER_SUPPORTS_MARCH_X86_64_V2) + add_compile_options("-march=x86-64-v2") + else() + CHECK_C_COMPILER_FLAG("-march=nehalem" COMPILER_SUPPORTS_MARCH_NEHALEM) + if(COMPILER_SUPPORTS_MARCH_NEHALEM) + add_compile_options("-march=nehalem") + endif() + endif() +endif() diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 1c842cc5..806c3c79 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -4,29 +4,14 @@ project(looking-glass-host C) set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG" CACHE STRING "compiler flags" FORCE) set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG" CACHE STRING "compiler flags" FORCE) -set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/") +get_filename_component(PROJECT_TOP "${PROJECT_SOURCE_DIR}/.." ABSOLUTE) +list(APPEND CMAKE_MODULE_PATH "${PROJECT_TOP}/cmake/" "${PROJECT_SOURCE_DIR}/cmake/") include(GNUInstallDirs) include(CheckCCompilerFlag) include(FeatureSummary) -option(OPTIMIZE_FOR_NATIVE "Build with -march=native" OFF) -if(OPTIMIZE_FOR_NATIVE) - CHECK_C_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) - if(COMPILER_SUPPORTS_MARCH_NATIVE) - add_compile_options("-march=native") - endif() -else() - CHECK_C_COMPILER_FLAG("-march=x86-64-v2" COMPILER_SUPPORTS_MARCH_X86_64_V2) - if(COMPILER_SUPPORTS_MARCH_X86_64_V2) - add_compile_options("-march=x86-64-v2") - else() - CHECK_C_COMPILER_FLAG("-march=nehalem" COMPILER_SUPPORTS_MARCH_NEHALEM) - if(COMPILER_SUPPORTS_MARCH_NEHALEM) - add_compile_options("-march=nehalem") - endif() - endif() -endif() +include(OptimizeForNative) # option(OPTIMIZE_FOR_NATIVE) option(ENABLE_BACKTRACE "Enable backtrace support on crash" ON) add_feature_info(ENABLE_BACKTRACE ENABLE_BACKTRACE "Backtrace support.") @@ -42,8 +27,6 @@ add_compile_options( ) set(CMAKE_C_STANDARD 11) -get_filename_component(PROJECT_TOP "${PROJECT_SOURCE_DIR}/.." ABSOLUTE) - add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/version.c ${CMAKE_BINARY_DIR}/include/version.h diff --git a/obs/CMakeLists.txt b/obs/CMakeLists.txt index ff47c8c4..64045705 100644 --- a/obs/CMakeLists.txt +++ b/obs/CMakeLists.txt @@ -1,19 +1,14 @@ cmake_minimum_required(VERSION 3.0) project(looking-glass-obs C) -set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/") +get_filename_component(PROJECT_TOP "${PROJECT_SOURCE_DIR}/.." ABSOLUTE) +list(APPEND CMAKE_MODULE_PATH "${PROJECT_TOP}/cmake/" "${PROJECT_SOURCE_DIR}/cmake/") include(GNUInstallDirs) include(CheckCCompilerFlag) include(FeatureSummary) -option(OPTIMIZE_FOR_NATIVE "Build with -march=native" ON) -if(OPTIMIZE_FOR_NATIVE) - CHECK_C_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) - if(COMPILER_SUPPORTS_MARCH_NATIVE) - add_compile_options("-march=native") - endif() -endif() +include(OptimizeForNative) # option(OPTIMIZE_FOR_NATIVE) option(ENABLE_BACKTRACE "Enable backtrace support on crash" ON) add_feature_info(ENABLE_BACKTRACE ENABLE_BACKTRACE "Backtrace support.") @@ -50,7 +45,6 @@ else() endif() add_definitions(-D ATOMIC_LOCKING) -get_filename_component(PROJECT_TOP "${PROJECT_SOURCE_DIR}/.." ABSOLUTE) add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/version.c diff --git a/profile/client/CMakeLists.txt b/profile/client/CMakeLists.txt index dad2553c..9bfe6369 100644 --- a/profile/client/CMakeLists.txt +++ b/profile/client/CMakeLists.txt @@ -1,19 +1,14 @@ cmake_minimum_required(VERSION 3.0) project(profiler-client C) -set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/") +get_filename_component(PROJECT_TOP "${PROJECT_SOURCE_DIR}/../.." ABSOLUTE) +list(APPEND CMAKE_MODULE_PATH "${PROJECT_TOP}/cmake/" "${PROJECT_SOURCE_DIR}/cmake/") include(GNUInstallDirs) include(CheckCCompilerFlag) include(FeatureSummary) -option(OPTIMIZE_FOR_NATIVE "Build with -march=native" ON) -if(OPTIMIZE_FOR_NATIVE) - CHECK_C_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) - if(COMPILER_SUPPORTS_MARCH_NATIVE) - add_compile_options("-march=native") - endif() -endif() +include(OptimizeForNative) # option(OPTIMIZE_FOR_NATIVE) add_compile_options( "-Wall" @@ -36,7 +31,6 @@ execute_process( ) add_definitions(-D BUILD_VERSION='"${BUILD_VERSION}"') -get_filename_component(PROJECT_TOP "${PROJECT_SOURCE_DIR}/../.." ABSOLUTE) include_directories( ${PROJECT_SOURCE_DIR}/include