|
1 | | -# We might support earlier versions, too, but try to use a recent one. |
2 | 1 | cmake_minimum_required(VERSION 3.8) |
3 | 2 |
|
4 | 3 | project(sha256) |
5 | 4 |
|
| 5 | +# If the option ENABLE_LTO is enabled (e. g. via `cmake -DENABLE_LTO=ON`) |
| 6 | +# during the build, then all binaries will use link-time optimization (LTO). |
| 7 | +option(ENABLE_LTO "Enable link-time optimization" OFF) |
| 8 | +# Not all compilers support LTO / IPO, so it has to be checked. |
| 9 | +if (ENABLE_LTO) |
| 10 | + cmake_policy(SET CMP0069 NEW) |
| 11 | + include(CheckIPOSupported) |
| 12 | + check_ipo_supported(RESULT HAS_LTO_SUPPORT OUTPUT LTO_FAIL_REASON |
| 13 | + LANGUAGES C CXX) |
| 14 | + if (NOT HAS_LTO_SUPPORT) |
| 15 | + message(FATAL "IPO / LTO is not supported: ${LTO_FAIL_REASON}") |
| 16 | + else() |
| 17 | + message(STATUS "IPO / LTO is supported. Using it.") |
| 18 | + endif() |
| 19 | +endif (ENABLE_LTO) |
| 20 | + |
| 21 | +# If ENABLE_STATIC_LINKING is on (e. g. via `cmake -DENABLE_STATIC_LINKING=ON`), |
| 22 | +# then all libraries are linked statically. The option is off by default. |
| 23 | +# |
| 24 | +# Static linking increases the size of the binaries, but those binaries do not |
| 25 | +# need the libraries to be present on the system. |
| 26 | +# |
| 27 | +# WARNING: This option is still experimental and may not work completely. |
| 28 | +option(ENABLE_STATIC_LINKING "Links all libraries statically" OFF) |
| 29 | +if (ENABLE_STATIC_LINKING) |
| 30 | + set(CMAKE_LINK_SEARCH_START_STATIC 1) |
| 31 | + set(CMAKE_LINK_SEARCH_END_STATIC 1) |
| 32 | + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") |
| 33 | + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++ -static") |
| 34 | +endif () |
| 35 | + |
6 | 36 | # Recurse into subdirectory for sha256 executable. |
7 | 37 | add_subdirectory (sha256) |
8 | 38 |
|
|
0 commit comments