Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into improvement-onlook
Browse files Browse the repository at this point in the history
  • Loading branch information
omarcopires committed Oct 15, 2024
2 parents a2f6ea2 + 92c07cf commit f84dda5
Show file tree
Hide file tree
Showing 26 changed files with 245 additions and 333 deletions.
27 changes: 19 additions & 8 deletions .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,37 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
os: [ubuntu-22.04, ubuntu-24.04]
buildtype: [linux-release, linux-debug]
include:
- os: ubuntu-22.04
triplet: x64-linux
- os: ubuntu-24.04
triplet: x64-linux

steps:
- name: Checkout repository
uses: actions/checkout@main

- name: Install Linux Dependencies
run: >
sudo apt-get update && sudo apt-get install ccache linux-headers-$(uname -r)
sudo apt-get update && sudo apt-get install ccache linux-headers-"$(uname -r)"
- name: Switch to gcc-12 on Ubuntu 22.04
if: matrix.os == 'ubuntu-22.04'
run: |
sudo apt install gcc-12 g++-12
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 100 --slave /usr/bin/g++ g++ /usr/bin/g++-12 --slave /usr/bin/gcov gcov /usr/bin/gcov-12
sudo update-alternatives --set gcc /usr/bin/gcc-12
- name: Switch to gcc-11
if: matrix.os == 'ubuntu-20.04'
- name: Switch to gcc-14 on Ubuntu 24.04
if: matrix.os == 'ubuntu-24.04'
run: |
sudo apt install gcc-11 g++-11
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11
sudo update-alternatives --set gcc /usr/bin/gcc-11
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo apt-get update
sudo apt-get install gcc-14 g++-14 -y
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 100 --slave /usr/bin/g++ g++ /usr/bin/g++-14 --slave /usr/bin/gcov gcov /usr/bin/gcov-14
sudo update-alternatives --set gcc /usr/bin/gcc-14
- name: CCache
uses: hendrikmuhs/ccache-action@main
Expand All @@ -70,7 +81,7 @@ jobs:
run: |
vcpkgCommitId=$(grep '.builtin-baseline' vcpkg.json | awk -F: '{print $2}' | tr -d '," ')
echo "vcpkg commit ID: $vcpkgCommitId"
echo "VCPKG_GIT_COMMIT_ID=$vcpkgCommitId" >> $GITHUB_ENV
echo "VCPKG_GIT_COMMIT_ID=$vcpkgCommitId" >> "$GITHUB_ENV"
- name: Get vcpkg commit id from vcpkg.json
uses: lukka/run-vcpkg@main
Expand Down
63 changes: 15 additions & 48 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,31 @@ cmake_minimum_required(VERSION 3.22 FATAL_ERROR)

# VCPKG
# cmake -DCMAKE_TOOLCHAIN_FILE=/opt/workspace/vcpkg/scripts/buildsystems/vcpkg.cmake ..
# Needed libs is in file vcpkg.json
# Needed libs are in file vcpkg.json
# Windows required libs: .\vcpkg install --triplet x64-windows asio pugixml spdlog curl protobuf parallel-hashmap magic-enum mio luajit libmariadb mpir abseil bshoshany-thread-pool

if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
endif()

if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "")
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "")
endif()

set(VCPKG_FEATURE_FLAGS "versions")
set(VCPKG_BUILD_TYPE "release")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)



# *****************************************************************************
# Project canary
# *****************************************************************************
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
project(canary-debug)
project(canary-debug LANGUAGES CXX)
else()
project(canary)
project(canary LANGUAGES CXX)
endif()


# *****************************************************************************
# Append cmake search path
# *****************************************************************************
Expand All @@ -57,7 +55,7 @@ option(FEATURE_METRICS "Enable metrics feature" OFF)
# Options Code
# *****************************************************************************

if(FEATURE_METRIC)
if(FEATURE_METRICS)
log_option_enabled("metrics")
else ()
log_option_disabled("metrics")
Expand All @@ -69,52 +67,21 @@ if(OPTIONS_ENABLE_CCACHE)
if(CCACHE)
log_option_enabled("ccache")
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
else()
else()
log_option_disabled("ccache")
endif()
endif()


# === SCCACHE ===
if(OPTIONS_ENABLE_SCCACHE)
find_program(SCCACHE_PATH sccache)
if(SCCACHE_PATH)
log_option_enabled("sccache")
set(CMAKE_C_COMPILER_LAUNCHER ${SCCACHE_PATH})
set(CMAKE_CXX_COMPILER_LAUNCHER ${SCCACHE_PATH})
else()
log_option_disabled("sccache")
endif()
endif()


# === IPO ===
if(OPTIONS_ENABLE_IPO)
if(MSVC)
log_option_enabled("IPO/LTO")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /GL")
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
set(CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
set(CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
find_program(SCCACHE_PATH sccache)
if(SCCACHE_PATH)
log_option_enabled("sccache")
set(CMAKE_C_COMPILER_LAUNCHER ${SCCACHE_PATH})
set(CMAKE_CXX_COMPILER_LAUNCHER ${SCCACHE_PATH})
else()
if(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" OR CMAKE_BUILD_TYPE STREQUAL "Release")
log_option_enabled("IPO/LTO")
include(CheckIPOSupported)
check_ipo_supported(RESULT result OUTPUT output)
if(result)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto=auto")
message(STATUS "IPO/LTO enabled with -flto=auto for non-MSVC compiler.")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
log_war("IPO/LTO not supported: ${output}")
endif()
else()
log_option_disabled("IPO/LTO")
endif ()
log_option_disabled("sccache")
endif()
else()
log_option_disabled("IPO/LTO")
endif()

option(BUILD_TESTS "Build tests" OFF) # By default, tests will not be built
Expand Down
101 changes: 69 additions & 32 deletions cmake/modules/BaseConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ cmake_minimum_required(VERSION 3.22 FATAL_ERROR)
# *****************************************************************************
# CMake Features
# *****************************************************************************
set(CMAKE_CXX_STANDARD 20)
set(GNUCXX_MINIMUM_VERSION 11)
set(MSVC_MINIMUM_VERSION "19.32")
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
Expand All @@ -15,9 +13,6 @@ set(Boost_NO_WARN_NEW_VERSIONS ON)
# Make will print more details
set(CMAKE_VERBOSE_MAKEFILE OFF)

# Generate compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# *****************************************************************************
# Packages / Libs
# *****************************************************************************
Expand Down Expand Up @@ -50,21 +45,21 @@ find_path(BOOST_DI_INCLUDE_DIRS "boost/di.hpp")
# === GCC Minimum Version ===
if (CMAKE_COMPILER_IS_GNUCXX)
message("-- Compiler: GCC - Version: ${CMAKE_CXX_COMPILER_VERSION}")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS GNUCXX_MINIMUM_VERSION)
message(FATAL_ERROR "GCC version must be at least ${GNUCXX_MINIMUM_VERSION}!")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11)
message(FATAL_ERROR "GCC version must be at least 11!")
endif()
endif()

# === Minimum required version for visual studio ===
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
message("-- Compiler: Visual Studio - Version: ${CMAKE_CXX_COMPILER_VERSION}")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS MSVC_MINIMUM_VERSION)
message(FATAL_ERROR "Visual Studio version must be at least ${MSVC_MINIMUM_VERSION}")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "19.32")
message(FATAL_ERROR "Visual Studio version must be at least 19.32")
endif()
endif()

# *****************************************************************************
# Sanity Checks
# Options
# *****************************************************************************
option(TOGGLE_BIN_FOLDER "Use build/bin folder for generate compilation files" ON)
option(OPTIONS_ENABLE_OPENMP "Enable Open Multi-Processing support." ON)
Expand All @@ -79,14 +74,14 @@ if(TOGGLE_BIN_FOLDER)
log_option_enabled("TOGGLE_BIN_FOLDER")
else()
log_option_disabled("TOGGLE_BIN_FOLDER")
endif(TOGGLE_BIN_FOLDER)
endif()

# === TOGGLE_BIN_FOLDER ===
# === OPTIONS_ENABLE_OPENMP ===
if(OPTIONS_ENABLE_OPENMP)
log_option_enabled("OPTIONS_ENABLE_OPENMP")
else()
log_option_disabled("OPTIONS_ENABLE_OPENMP")
endif(OPTIONS_ENABLE_OPENMP)
endif()

# === DEBUG LOG ===
# cmake -DDEBUG_LOG=ON ..
Expand All @@ -95,7 +90,7 @@ if(DEBUG_LOG)
log_option_enabled("DEBUG LOG")
else()
log_option_disabled("DEBUG LOG")
endif(DEBUG_LOG)
endif()

# === ASAN ===
if(ASAN_ENABLED)
Expand All @@ -113,7 +108,6 @@ endif()
# === BUILD_STATIC_LIBRARY ===
if(BUILD_STATIC_LIBRARY)
log_option_enabled("STATIC_LIBRARY")

if(MSVC)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib")
elseif(UNIX AND NOT APPLE)
Expand All @@ -130,14 +124,58 @@ if(SPEED_UP_BUILD_UNITY)
log_option_enabled("SPEED_UP_BUILD_UNITY")
else()
log_option_disabled("SPEED_UP_BUILD_UNITY")
endif(SPEED_UP_BUILD_UNITY)
endif()

# === USE_PRECOMPILED_HEADER ===
if(USE_PRECOMPILED_HEADER)
log_option_enabled("USE_PRECOMPILED_HEADER")
else()
log_option_disabled("USE_PRECOMPILED_HEADER")
endif(USE_PRECOMPILED_HEADER)
endif()

# === IPO Configuration ===
function(configure_linking target_name)
if(OPTIONS_ENABLE_IPO)
# Check if IPO/LTO is supported
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_output LANGUAGES CXX)

# Get the GCC compiler version, if applicable
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
OUTPUT_VARIABLE GCC_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()

if(ipo_supported)
set_property(TARGET ${target_name} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
log_option_enabled("IPO/LTO enabled for target ${target_name}.")

if(MSVC)
target_compile_options(${target_name} PRIVATE /GL)
target_link_options(${target_name} PRIVATE /LTCG)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# Check if it's running on Linux, using GCC 14, and in Debug mode
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
GCC_VERSION VERSION_EQUAL "14" AND
CMAKE_BUILD_TYPE STREQUAL "Debug")
log_option_disabled("LTO disabled for GCC 14 in Debug mode on Linux for target ${target_name}.")
# Disable LTO for Debug builds with GCC 14
target_compile_options(${target_name} PRIVATE -fno-lto)
target_link_options(${target_name} PRIVATE -fno-lto)
else()
target_compile_options(${target_name} PRIVATE -flto=auto)
target_link_options(${target_name} PRIVATE -flto=auto)
endif()
endif()
else()
log_option_disabled("IPO/LTO is not supported for target ${target_name}: ${ipo_output}")
endif()
endif()
endfunction()

# *****************************************************************************
# Compiler Options
Expand All @@ -147,39 +185,38 @@ if (MSVC)
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_${type} "${CMAKE_CXX_FLAGS_${type}}")
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_${type} "${CMAKE_C_FLAGS_${type}}")
endforeach(type)

add_compile_options(/MP /FS /Zf /EHsc)
else()
add_compile_options(-Wno-unused-parameter -Wno-sign-compare -Wno-switch -Wno-implicit-fallthrough -Wno-extra)
endif()

## Link compilation files to build/bin folder, else link to the main dir
# === Compiler Features ===
add_library(project_options INTERFACE)
target_compile_features(project_options INTERFACE cxx_std_23)

# *****************************************************************************
# Output Directory Function
# *****************************************************************************
function(set_output_directory target_name)
if (TOGGLE_BIN_FOLDER)
set_target_properties(${target_name}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
)
else()
set_target_properties(${target_name}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/"
)
)
endif()
endfunction()

## Setup shared target basic configurations
# *****************************************************************************
# Setup Target Function
# *****************************************************************************
function(setup_target TARGET_NAME)
if (MSVC AND BUILD_STATIC_LIBRARY)
set_property(TARGET ${TARGET_NAME} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
target_link_libraries(${TARGET_NAME} PUBLIC project_options)
endfunction()

# *****************************************************************************
# DEBUG: Print cmake variables
# *****************************************************************************
#get_cmake_property(_variableNames VARIABLES)
#list (SORT _variableNames)
#foreach (_variableName ${_variableNames})
# message(STATUS "${_variableName}=${${_variableName}}")
#endforeach()
Loading

0 comments on commit f84dda5

Please sign in to comment.