This repository has been archived on 2022-02-10. You can view files and clone it, but cannot push or open issues or pull requests.
fortuna/CMakeLists.txt
surtur b934b11aa9
All checks were successful
continuous-integration/drone/push Build is passing
cmake(release): harden the build
2021-11-15 23:07:59 +01:00

102 lines
4.2 KiB
CMake

cmake_minimum_required(VERSION 3.20)
project(fortuna LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
# Produce debugging information in the operating system's native format.
# Level 3 includes extra information, such as all the macro definitions
# present in the program. Some debuggers support macro expansion when you
# use -g3
if(NOT CMAKE_CXX_FLAGS MATCHES "-g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
endif(NOT CMAKE_CXX_FLAGS MATCHES "-g")
# Optimize debugging experience. -Og should be the optimization level of
# choice for the standard edit-compile-debug cycle, offering a reasonable
# level of optimization while maintaining fast compilation and a good
# debugging experience. It is a better choice than -O0 for producing
# debuggable code because some compiler passes that collect debug
# information are disabled at -O0.
if(NOT CMAKE_CXX_FLAGS MATCHES "-Og")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Og")
endif(NOT CMAKE_CXX_FLAGS MATCHES "-Og")
if(NOT $ENV{VALGRIND} MATCHES "true")
# If DWARF debugging information is enabled, separate as much debugging
# information as possible into a separate output file with the extension
# .dwo. This option allows the build system to avoid linking files with
# debug information.
if(NOT CMAKE_CXX_FLAGS MATCHES "-gsplit-dwarf")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gsplit-dwarf")
endif(NOT CMAKE_CXX_FLAGS MATCHES "-gsplit-dwarf")
else()
message(STATUS "VALGRIND=true, not setting '-gsplit-dwarf'")
endif(NOT $ENV{VALGRIND} MATCHES "true")
if(NOT CMAKE_CXX_FLAGS MATCHES "-Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif(NOT CMAKE_CXX_FLAGS MATCHES "-Wall")
if(NOT CMAKE_CXX_FLAGS MATCHES "-Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
endif(NOT CMAKE_CXX_FLAGS MATCHES "-Wextra")
if(NOT CMAKE_CXX_FLAGS MATCHES "-Wpedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic")
endif(NOT CMAKE_CXX_FLAGS MATCHES "-Wpedantic")
endif(CMAKE_BUILD_TYPE MATCHES "Debug")
if(CMAKE_BUILD_TYPE MATCHES "Release")
if(NOT CMAKE_CXX_FLAGS MATCHES "-Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif(NOT CMAKE_CXX_FLAGS MATCHES "-Wall")
# Optimize yet more.
if(NOT CMAKE_CXX_FLAGS MATCHES "-O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif(NOT CMAKE_CXX_FLAGS MATCHES "-O3")
if(NOT CMAKE_CXX_FLAGS MATCHES "-DNDEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG")
endif(NOT CMAKE_CXX_FLAGS MATCHES "-DNDEBUG")
if(NOT CMAKE_CXX_FLAGS MATCHES "-fstack-protector-strong")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong")
endif(NOT CMAKE_CXX_FLAGS MATCHES "-fstack-protector-strong")
if(NOT CMAKE_CXX_FLAGS MATCHES "-funwind-tables")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -funwind-tables")
endif(NOT CMAKE_CXX_FLAGS MATCHES "-funwind-tables")
if(NOT CMAKE_CXX_FLAGS MATCHES "-fasynchronous-unwind-tables")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fasynchronous-unwind-tables")
endif(NOT CMAKE_CXX_FLAGS MATCHES "-fasynchronous-unwind-tables")
endif(CMAKE_BUILD_TYPE MATCHES "Release")
# inspired by https://medium.com/@alasher/colored-c-compiler-output-with-ninja-clang-gcc-10bfe7f2b949
option (COLORS_FOREVER "Always produce ANSI-colored output (GNU/Clang only)." TRUE)
if (${COLORS_FOREVER})
message(STATUS "COLORS_FOREVER: ${COLORS_FOREVER}")
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
add_compile_options (-fdiagnostics-color=always)
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
add_compile_options (-fcolor-diagnostics)
endif ()
endif ()
message(STATUS "Compiler ID: ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
find_program(LLD lld)
if(LLD)
if(NOT CMAKE_EXE_LINKER_FLAGS MATCHES "-fuse-ld=lld")
message(STATUS "Linker: lld: ${LLD}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
endif(NOT CMAKE_EXE_LINKER_FLAGS MATCHES "-fuse-ld=lld")
endif()
add_executable(fortuna main.cpp generator.cpp generator.h fortuna.cpp fortuna.h)
target_link_libraries(fortuna cryptopp)