Skip to content

Commit

Permalink
turn LTO off by default
Browse files Browse the repository at this point in the history
  • Loading branch information
KRM7 committed Dec 28, 2023
1 parent 2717488 commit 7ddb719
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: setup-build
env:
CXX: ${{ matrix.compiler.cxx }}
run: cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DBUILD_SHARED_LIBS=OFF
run: cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DGAPP_USE_LTO=ON

- name: build
run: cmake --build . --parallel 8
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
run: sudo bash ./install_catch.sh -DCMAKE_CXX_COMPILER=${{ matrix.compiler.cxx }} -DCMAKE_CXX_FLAGS="${{ matrix.compiler.extra-flags }}" -DCMAKE_EXE_LINKER_FLAGS="${{ matrix.compiler.linker-flags }}"

- name: setup-build
run: cmake .. -DCMAKE_CXX_COMPILER=${{ matrix.compiler.cxx }} -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DGAPP_CXX_FLAGS="${{ matrix.compiler.extra-flags }}" -DCMAKE_EXE_LINKER_FLAGS="${{ matrix.compiler.linker-flags }}" -DGAPP_USE_LTO=OFF
run: cmake .. -DCMAKE_CXX_COMPILER=${{ matrix.compiler.cxx }} -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DGAPP_CXX_FLAGS="${{ matrix.compiler.extra-flags }}" -DCMAKE_EXE_LINKER_FLAGS="${{ matrix.compiler.linker-flags }}"

- name: build
run: cmake --build . --parallel 8
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
platform: [ x64, Win32 ]
compiler: [ v143, ClangCL ]
generator: [ "Visual Studio 17 2022" ]
lib-type: [ { name: Static, cmake-shared-flag: "OFF" }, { name: Shared, cmake-shared-flag: "ON" } ]
build-shared: [ "ON", "OFF" ]
exclude:
- platform: Win32
compiler: ClangCL
Expand All @@ -23,7 +23,7 @@ jobs:
run:
working-directory: ${{ github.workspace }}/build

name: ${{ matrix.compiler }}-${{ matrix.platform }}, ${{ matrix.build-type }}, ${{ matrix.lib-type.name }}
name: ${{ matrix.compiler }}-${{ matrix.platform }}, ${{ matrix.build-type }}, Shared=${{ matrix.build-shared }}


steps:
Expand All @@ -45,7 +45,7 @@ jobs:
CMAKE_GENERATOR: ${{ matrix.generator }}
CMAKE_GENERATOR_TOOLSET: ${{ matrix.compiler }}
CMAKE_GENERATOR_PLATFORM: ${{ matrix.platform }}
run: cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DBUILD_SHARED_LIBS=${{ matrix.lib-type.cmake-shared-flag }}
run: cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DBUILD_SHARED_LIBS=${{ matrix.build-shared }} -DGAPP_USE_LTO=ON

- name: build
run: cmake --build . --parallel --config ${{ matrix.build-type }}
Expand Down
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ option(GAPP_BUILD_TESTS "Build the tests for the library when ON." ON)
option(GAPP_BUILD_BENCHMARKS "Build the benchmarks for the library when ON." OFF)
option(GAPP_BUILD_EXAMPLES "Build the examples for the library when ON." OFF)
option(GAPP_USE_WERROR "Treat all warnings as errors during the build." ON)
option(GAPP_USE_LTO "Use link time optimizations for the library." ON)
option(GAPP_USE_LTO "Use link time optimizations for the library (only used for optimized builds)." OFF)
option(GAPP_USE_MARCH_NATIVE "Optimize for the host architecture in release builds (only used for gcc and clang)." OFF)
option(GAPP_DISABLE_EXCEPTIONS "Disable exception support when building the library." OFF)
option(GAPP_DISABLE_RTTI "Disable run-time type information when building the library." OFF)
Expand Down Expand Up @@ -115,9 +115,10 @@ endif()

# LTO setup
check_ipo_supported(RESULT LTO_SUPPORTED)
if(GAPP_USE_LTO AND LTO_SUPPORTED AND CMAKE_BUILD_TYPE MATCHES "(Release|RelWithDebInfo)")
if (BUILD_SHARED_LIBS AND MSVC)
message(WARNING "LTO is not available for shared libs using MSVC because of CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS.")
if(CMAKE_INTERPROCEDURAL_OPTIMIZATION OR (GAPP_USE_LTO AND CMAKE_BUILD_TYPE MATCHES "(Release|RelWithDebInfo)"))
if((NOT LTO_SUPPORTED) OR (BUILD_SHARED_LIBS AND MSVC)) # because of CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS
message(WARNING "LTO is not supported.")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
else()
message(STATUS "Using link time optimizations.")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
Expand Down
16 changes: 8 additions & 8 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"configurationType": "Debug",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "-DGAPP_CXX_FLAGS=/analyze:WX- -DGAPP_BUILD_TESTS=ON -DGAPP_BUILD_BENCHMARKS=ON -DGAPP_BUILD_EXAMPLES=ON",
"cmakeCommandArgs": "-DGAPP_CXX_FLAGS=/analyze:WX- -DGAPP_BUILD_TESTS=ON -DGAPP_BUILD_BENCHMARKS=ON -DGAPP_BUILD_EXAMPLES=ON -DGAPP_USE_LTO=ON",
"ctestCommandArgs": "--output-on-failure --schedule-random",
"codeAnalysisRuleset": "${projectDir}\\core-guidelines.ruleset",
"enableMicrosoftCodeAnalysis": false,
Expand All @@ -18,7 +18,7 @@
"configurationType": "Release",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "-DGAPP_CXX_FLAGS=-analyze:WX- -DGAPP_BUILD_TESTS=ON -DGAPP_BUILD_BENCHMARKS=ON -DGAPP_BUILD_EXAMPLES=ON",
"cmakeCommandArgs": "-DGAPP_CXX_FLAGS=-analyze:WX- -DGAPP_BUILD_TESTS=ON -DGAPP_BUILD_BENCHMARKS=ON -DGAPP_BUILD_EXAMPLES=ON -DGAPP_USE_LTO=ON",
"ctestCommandArgs": "--output-on-failure --schedule-random",
"codeAnalysisRuleset": "${projectDir}\\core-guidelines.ruleset",
"enableMicrosoftCodeAnalysis": false,
Expand All @@ -30,7 +30,7 @@
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "-DGAPP_CXX_FLAGS=-analyze:WX- -DGAPP_BUILD_TESTS=ON -DGAPP_BUILD_BENCHMARKS=ON -DGAPP_BUILD_EXAMPLES=ON",
"cmakeCommandArgs": "-DGAPP_CXX_FLAGS=-analyze:WX- -DGAPP_BUILD_TESTS=ON -DGAPP_BUILD_BENCHMARKS=ON -DGAPP_BUILD_EXAMPLES=ON -DGAPP_USE_LTO=ON",
"ctestCommandArgs": "--output-on-failure --schedule-random",
"codeAnalysisRuleset": "${projectDir}\\core-guidelines.ruleset",
"enableMicrosoftCodeAnalysis": false,
Expand All @@ -42,7 +42,7 @@
"configurationType": "Debug",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "-DGAPP_BUILD_TESTS=ON -DGAPP_BUILD_BENCHMARKS=ON -DGAPP_BUILD_EXAMPLES=ON",
"cmakeCommandArgs": "-DGAPP_BUILD_TESTS=ON -DGAPP_BUILD_BENCHMARKS=ON -DGAPP_BUILD_EXAMPLES=ON -DGAPP_USE_LTO=ON",
"ctestCommandArgs": "--output-on-failure --schedule-random",
"enableClangTidyCodeAnalysis": false,
"inheritEnvironments": [ "clang_cl_x64_x64" ]
Expand All @@ -53,7 +53,7 @@
"configurationType": "Release",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "-DGAPP_BUILD_TESTS=ON -DGAPP_BUILD_BENCHMARKS=ON -DGAPP_BUILD_EXAMPLES=ON",
"cmakeCommandArgs": "-DGAPP_BUILD_TESTS=ON -DGAPP_BUILD_BENCHMARKS=ON -DGAPP_BUILD_EXAMPLES=ON -DGAPP_USE_LTO=ON",
"ctestCommandArgs": "--output-on-failure --schedule-random",
"inheritEnvironments": [ "clang_cl_x64_x64" ]
},
Expand All @@ -63,7 +63,7 @@
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "-DGAPP_BUILD_TESTS=ON -DGAPP_BUILD_BENCHMARKS=ON -DGAPP_BUILD_EXAMPLES=ON",
"cmakeCommandArgs": "-DGAPP_BUILD_TESTS=ON -DGAPP_BUILD_BENCHMARKS=ON -DGAPP_BUILD_EXAMPLES=ON -DGAPP_USE_LTO=ON",
"ctestCommandArgs": "--output-on-failure --schedule-random",
"inheritEnvironments": [ "clang_cl_x64_x64" ]
},
Expand All @@ -73,7 +73,7 @@
"configurationType": "Release",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "-DGAPP_CXX_FLAGS=-analyze:WX- -DBUILD_SHARED_LIBS=ON -DGAPP_BUILD_TESTS=ON -DGAPP_BUILD_BENCHMARKS=ON -DGAPP_BUILD_EXAMPLES=ON",
"cmakeCommandArgs": "-DGAPP_CXX_FLAGS=-analyze:WX- -DBUILD_SHARED_LIBS=ON -DGAPP_BUILD_TESTS=ON -DGAPP_BUILD_BENCHMARKS=ON -DGAPP_BUILD_EXAMPLES=ON -DGAPP_USE_LTO=ON",
"ctestCommandArgs": "--output-on-failure --schedule-random",
"codeAnalysisRuleset": "${projectDir}\\core-guidelines.ruleset",
"enableMicrosoftCodeAnalysis": false,
Expand All @@ -85,7 +85,7 @@
"configurationType": "Release",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "-DBUILD_SHARED_LIBS=ON -DGAPP_BUILD_TESTS=ON -DGAPP_BUILD_BENCHMARKS=ON -DGAPP_BUILD_EXAMPLES=ON",
"cmakeCommandArgs": "-DBUILD_SHARED_LIBS=ON -DGAPP_BUILD_TESTS=ON -DGAPP_BUILD_BENCHMARKS=ON -DGAPP_BUILD_EXAMPLES=ON -DGAPP_USE_LTO=ON",
"ctestCommandArgs": "--output-on-failure --schedule-random",
"codeAnalysisRuleset": "${projectDir}\\core-guidelines.ruleset",
"enableMicrosoftCodeAnalysis": false,
Expand Down
6 changes: 4 additions & 2 deletions docs/install-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,10 @@ headers will be slightly different, ie. you will need to do `#include <gapp.hpp>
- `GAPP_USE_WERROR` - When this option is `ON`, all warnings will be treated as errors during the
build. The default value is `ON`.

- `GAPP_USE_LTO` - When this option is `ON`, the library will be built for using link-time optimization.
The default value is `ON`.
- `GAPP_USE_LTO` - When this option is `ON`, the library will be built using link-time optimizations
in the optimized configurations (Release and RelWithDebInfo). This option has no effect on Debug
builds.
The default value is `OFF`.

- `GAPP_USE_MARCH_NATIVE` - When this option is `ON`, the library will be optimized specifically for the
host architecture in the optimized configurations (Release and RelWithDebInfo). This has no effect on
Expand Down

0 comments on commit 7ddb719

Please sign in to comment.