Skip to content

Commit

Permalink
Merge pull request #252 from rbrich/cmake-COMPILE_ONLY
Browse files Browse the repository at this point in the history
[build] cmake: Use COMPILE_ONLY
  • Loading branch information
rbrich authored Oct 16, 2024
2 parents 188967e + 5c01242 commit 719956d
Show file tree
Hide file tree
Showing 20 changed files with 178 additions and 69 deletions.
8 changes: 0 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
version: 2.1

executors:
debian11:
docker:
- image: rbrich/xcikit-debian:11
resource_class: large
debian12:
docker:
- image: rbrich/xcikit-debian:12
Expand Down Expand Up @@ -95,10 +91,6 @@ workflows:
version: 2
workflow:
jobs:
- build:
name: Debian 11 - GCC 10
image: debian11
label: debian11-gcc10
- build:
name: Debian 12 - GCC 12
image: debian12
Expand Down
7 changes: 3 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# 3.18.4 in Debian 11
# 3.22.1 in Ubuntu 22.04 / Emscripten Docker image
# 3.25.1 in Debian 12
cmake_minimum_required(VERSION 3.18...3.30)
# 3.28.3 in Ubuntu 24.04 (noble)
# 3.30.3 in Debian 12 (bookworm-backports)
cmake_minimum_required(VERSION 3.27...3.30)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(XciBuildType)
Expand Down
15 changes: 15 additions & 0 deletions cmake/XciBuildOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ option(BUILD_WITH_ASAN "Build with AddressSanitizer." OFF)
option(BUILD_WITH_LSAN "Build with standalone LeakSanitizer." OFF)
option(BUILD_WITH_UBSAN "Build with UndefinedBehaviorSanitizer." OFF)
option(BUILD_WITH_TSAN "Build with ThreadSanitizer." OFF)
option(BUILD_HARDENING "Build with std lib hardening." OFF)

# warnings (+ compile time checking tools)
option(ENABLE_WARNINGS "Enable compiler warnings: -Wall -Wextra ..." ON)
Expand Down Expand Up @@ -164,6 +165,20 @@ if (BUILD_WITH_TSAN)
add_link_options(-fsanitize=thread)
endif ()

if (BUILD_HARDENING)
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# https://gcc.gnu.org/onlinedocs/libstdc++/manual/debug_mode_using.html
add_compile_definitions(-D_GLIBCXX_DEBUG)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# https://libcxx.llvm.org/Hardening.html
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_definitions(-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG)
else ()
add_compile_definitions(-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE)
endif ()
endif ()
endif ()

# Strip dead-code
if (APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-dead_strip")
Expand Down
20 changes: 10 additions & 10 deletions conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@

requirements:
fmt:
cmake: "fmt/10.0.0"
conan: "fmt/11.0.1"
upstream: "github.com fmtlib/fmt 11.0.1"
cmake: "fmt/11.0.0"
conan: "fmt/11.0.2"
upstream: "github.com fmtlib/fmt 11.0.2"
cmake_defs: FMT_TEST=OFF FMT_DOC=OFF FMT_SYSTEM_HEADERS=ON
public: True
range_v3:
cmake: "range-v3/0.12.0"
conan: "range-v3/0.12.0"
conan: "range-v3/cci.20240905"
upstream: "github.com ericniebler/range-v3 0.12.0"
cmake_defs: RANGE_V3_TESTS=OFF RANGE_V3_EXAMPLES=OFF RANGE_V3_PERF=OFF RANGE_V3_DOCS=OFF RANGE_V3_HEADER_CHECKS=OFF
prereq:
Expand All @@ -39,8 +39,8 @@ requirements:
- widgets
pegtl:
cmake: "pegtl/"
conan: "taocpp-pegtl/3.2.7"
upstream: "github.com taocpp/PEGTL 3.2.7"
conan: "taocpp-pegtl/3.2.8"
upstream: "github.com taocpp/PEGTL 3.2.8"
cmake_defs: PEGTL_BUILD_TESTS=OFF PEGTL_BUILD_EXAMPLES=OFF
public: True
magic_enum:
Expand All @@ -59,7 +59,7 @@ requirements:
- data
libzip:
cmake: "libzip/1.7.0"
conan: "libzip/1.10.1"
conan: "libzip/1.11.1"
sdl:
cmake: "SDL2/2.0.14"
conan: "sdl/2.30.5"
Expand Down Expand Up @@ -104,13 +104,13 @@ requirements:
- data
catch2:
cmake: "Catch2/3"
conan: "catch2/3.6.0"
upstream: "github.com catchorg/Catch2 v3.6.0"
conan: "catch2/3.7.1"
upstream: "github.com catchorg/Catch2 v3.7.1"
cmake_defs: CATCH_INSTALL_DOCS=OFF CMAKE_CXX_STANDARD=20
prereq:
- tests
benchmark:
cmake: "benchmark/1.5.0"
conan: "benchmark/1.8.4"
conan: "benchmark/1.9.0"
prereq:
- benchmarks
19 changes: 10 additions & 9 deletions docker/debian_11.dockerfile → docker/clang_tidy-arm64.dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# Debian 11 with GCC 10
# Debian 13 with Clang-Tidy 16
#
# CI builder (DockerHub public image), local build check:
# docker build --pull --build-arg UID=$(id -u) -t rbrich/xcikit-debian:11 . -f docker/debian_11.dockerfile
# docker run --rm -v $PWD:/src -w /src -it rbrich/xcikit-debian:11
# docker build --platform linux/arm64/v8 --pull --build-arg UID=$(id -u) -t rbrich/xcikit-tidy-arm64 . -f docker/clang_tidy-arm64.dockerfile
# docker run --platform linux/arm64/v8 --rm -v $PWD:/src -w /src -it rbrich/xcikit-tidy-arm64
# CMake arguments (for Clion IDE):
# -DFORCE_COLORS=1
# -DCONAN_OPTIONS="-o;xcikit/*:system_sdl=True;-o;xcikit/*:system_vulkan=True;-o;xcikit/*:system_freetype=True;-o;xcikit/*:system_harfbuzz=True;-o;xcikit/*:system_benchmark=True;-o;xcikit/*:system_zlib=True;-o;xcikit/*:system_range_v3=True;-o;xcikit/*:with_hyperscan=True"

FROM debian:bullseye-slim AS builder
FROM debian:trixie-slim AS builder

RUN echo "gcc"; apt-get update && apt-get install --no-install-recommends -y \
g++ && rm -rf /var/lib/apt/lists/*
# Clang with libstdc++. Alternatively, install also: libc++-dev libc++abi-dev
RUN echo "clang"; apt-get update && apt-get install --no-install-recommends -y \
clang clang-tidy && rm -rf /var/lib/apt/lists/*

RUN echo "dev tools"; apt-get update && apt-get install --no-install-recommends -y \
gdb ca-certificates curl cmake make ninja-build ccache \
Expand All @@ -22,15 +23,15 @@ RUN echo "xcikit deps"; apt-get update && apt-get install --no-install-recommend
librange-v3-dev libsdl2-dev glslang-tools libvulkan-dev libfreetype6-dev libharfbuzz-dev \
libhyperscan-dev libbenchmark-dev && rm -rf /var/lib/apt/lists/*

RUN echo "conan"; pip3 install --no-cache-dir conan
RUN echo "conan"; pip3 install --no-cache-dir --break-system-packages conan

ARG UID=10002
RUN useradd -m -p np -u ${UID} -s /bin/bash builder
USER builder

COPY --chown=builder docker/conan /home/builder/conan
RUN conan config install /home/builder/conan
ENV CONAN_DEFAULT_PROFILE=linux_gcc10
ENV CONAN_DEFAULT_PROFILE=linux_clang16_arm64

# Preinstall Conan deps
ENV XCIKIT=/home/builder/xcikit
Expand All @@ -41,4 +42,4 @@ RUN $XCIKIT/build.sh deps --debug
# Configure ccache
RUN ccache -o max_size=200M

CMD ./build.sh
CMD ./build.sh --tidy -DCMAKE_DISABLE_PRECOMPILE_HEADERS=1
4 changes: 2 additions & 2 deletions docker/clang_tidy.dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Debian 13 with Clang-Tidy 16
#
# CI builder (DockerHub public image), local build check:
# docker build --pull --build-arg UID=$(id -u) -t rbrich/xcikit-tidy . -f docker/clang_tidy.dockerfile
# docker run --rm -v $PWD:/src -w /src -it rbrich/xcikit-tidy
# docker build --platform linux/amd64 --pull --build-arg UID=$(id -u) -t rbrich/xcikit-tidy . -f docker/clang_tidy.dockerfile
# docker run --platform linux/amd64 --rm -v $PWD:/src -w /src -it rbrich/xcikit-tidy
# CMake arguments (for Clion IDE):
# -DFORCE_COLORS=1
# -DCONAN_OPTIONS="-o;xcikit/*:system_sdl=True;-o;xcikit/*:system_vulkan=True;-o;xcikit/*:system_freetype=True;-o;xcikit/*:system_harfbuzz=True;-o;xcikit/*:system_benchmark=True;-o;xcikit/*:system_zlib=True;-o;xcikit/*:system_range_v3=True;-o;xcikit/*:with_hyperscan=True"
Expand Down
2 changes: 1 addition & 1 deletion docker/conan/profiles/emscripten
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
os=Emscripten
arch=wasm
compiler=clang
compiler.version=17
compiler.version=19
compiler.cppstd=20
build_type=Release

Expand Down
7 changes: 7 additions & 0 deletions docker/conan/profiles/linux_clang
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[settings]
os=Linux
arch=x86_64
build_type=Release
compiler=clang
compiler.cppstd=20
compiler.libcxx=libstdc++11
8 changes: 2 additions & 6 deletions docker/conan/profiles/linux_clang16
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
include(linux_clang)

[settings]
os=Linux
arch=x86_64
build_type=Release
compiler=clang
compiler.version=16
compiler.cppstd=20
compiler.libcxx=libstdc++11
5 changes: 5 additions & 0 deletions docker/conan/profiles/linux_clang16_arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include(linux_clang)

[settings]
arch=armv8
compiler.version=16
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include(linux_gcc)

[settings]
compiler.version=10
arch=armv8
compiler.version=12
50 changes: 50 additions & 0 deletions docker/debian_12-arm64.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Debian 12 ARM64 with GCC 12
#
# CI builder (DockerHub public image), local build check:
# docker build --platform linux/arm64/v8 --pull --build-arg UID=$(id -u) -t rbrich/xcikit-debian-arm64:12 . -f docker/debian_12-arm64.dockerfile
# docker run --platform linux/arm64/v8 --rm -v $PWD:/src -w /src -it rbrich/xcikit-debian-arm64:12
# CMake arguments (for Clion IDE):
# -DFORCE_COLORS=1
# -DCONAN_OPTIONS="-o;xcikit/*:system_sdl=True;-o;xcikit/*:system_vulkan=True;-o;xcikit/*:system_freetype=True;-o;xcikit/*:system_harfbuzz=True;-o;xcikit/*:system_benchmark=True;-o;xcikit/*:system_zlib=True;-o;xcikit/*:system_range_v3=True;-o;xcikit/*:with_hyperscan=True"

FROM debian:bookworm-slim AS builder

RUN echo 'deb https://deb.debian.org/debian bookworm-backports main' > /etc/apt/sources.list.d/backports.list

RUN echo "gcc"; apt-get update && apt-get install --no-install-recommends -y \
g++ && rm -rf /var/lib/apt/lists/*

RUN echo "dev tools"; apt-get update && apt-get install --no-install-recommends -y \
gdb ca-certificates curl make ninja-build ccache \
python3-minimal python3-pip libpython3-stdlib && \
rm -rf /var/lib/apt/lists/*

RUN echo "xcikit deps"; apt-get update && apt-get install --no-install-recommends -y \
librange-v3-dev libsdl2-dev glslang-tools libvulkan-dev libfreetype6-dev libharfbuzz-dev \
libvectorscan-dev libbenchmark-dev && rm -rf /var/lib/apt/lists/*

# Install CMake 3.30.3 from backports
RUN echo "cmake"; apt-get update && apt-get install --no-install-recommends -y -t bookworm-backports cmake \
&& rm -rf /var/lib/apt/lists/*
ENV CMAKE_GENERATOR=Ninja CONAN_CMAKE_GENERATOR=Ninja

RUN echo "conan"; pip3 install --no-cache-dir --break-system-packages conan

ARG UID=10002
RUN useradd -m -p np -u ${UID} -s /bin/bash builder
USER builder

COPY --chown=builder docker/conan /home/builder/conan
RUN conan config install /home/builder/conan
ENV CONAN_DEFAULT_PROFILE=linux_gcc12_arm64

# Preinstall Conan deps
ENV XCIKIT=/home/builder/xcikit
COPY --chown=builder build.sh detect_system_deps.py conanfile.py conandata.yml VERSION $XCIKIT/
RUN $XCIKIT/build.sh deps
RUN $XCIKIT/build.sh deps --debug

# Configure ccache
RUN ccache -o max_size=200M

CMD ./build.sh
14 changes: 10 additions & 4 deletions docker/debian_12.dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
# Debian 12 with GCC 12
#
# CI builder (DockerHub public image), local build check:
# docker build --pull --build-arg UID=$(id -u) -t rbrich/xcikit-debian:12 . -f docker/debian_12.dockerfile
# docker run --rm -v $PWD:/src -w /src -it rbrich/xcikit-debian:12
# docker build --platform linux/amd64 --pull --build-arg UID=$(id -u) -t rbrich/xcikit-debian:12 . -f docker/debian_12.dockerfile
# docker run --platform linux/amd64 --rm -v $PWD:/src -w /src -it rbrich/xcikit-debian:12
# CMake arguments (for Clion IDE):
# -DFORCE_COLORS=1
# -DCONAN_OPTIONS="-o;xcikit/*:system_sdl=True;-o;xcikit/*:system_vulkan=True;-o;xcikit/*:system_freetype=True;-o;xcikit/*:system_harfbuzz=True;-o;xcikit/*:system_benchmark=True;-o;xcikit/*:system_zlib=True;-o;xcikit/*:system_range_v3=True;-o;xcikit/*:with_hyperscan=True"

FROM debian:bookworm-slim AS builder

RUN echo 'deb https://deb.debian.org/debian bookworm-backports main' > /etc/apt/sources.list.d/backports.list

RUN echo "gcc"; apt-get update && apt-get install --no-install-recommends -y \
g++ && rm -rf /var/lib/apt/lists/*

RUN echo "dev tools"; apt-get update && apt-get install --no-install-recommends -y \
gdb ca-certificates curl cmake make ninja-build ccache \
python3-minimal python3-pip libpython3-stdlib && \
rm -rf /var/lib/apt/lists/*
ENV CMAKE_GENERATOR=Ninja CONAN_CMAKE_GENERATOR=Ninja

RUN echo "xcikit deps"; apt-get update && apt-get install --no-install-recommends -y \
librange-v3-dev libsdl2-dev glslang-tools libvulkan-dev libfreetype6-dev libharfbuzz-dev \
libhyperscan-dev libbenchmark-dev && rm -rf /var/lib/apt/lists/*
libvectorscan-dev libbenchmark-dev && rm -rf /var/lib/apt/lists/*

# Install CMake 3.30.3 from backports
RUN echo "cmake"; apt-get update && apt-get install --no-install-recommends -y -t bookworm-backports cmake \
&& rm -rf /var/lib/apt/lists/*
ENV CMAKE_GENERATOR=Ninja CONAN_CMAKE_GENERATOR=Ninja

RUN echo "conan"; pip3 install --no-cache-dir --break-system-packages conan

Expand Down
39 changes: 39 additions & 0 deletions docker/emscripten-arm64.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# CI builder with Emscripten (DockerHub public image), local build check:
# docker build --platform linux/arm64/v8 --pull --build-arg UID=$(id -u) -t rbrich/xcikit-emscripten-arm64 . -f docker/emscripten-arm64.dockerfile
# docker run --platform linux/arm64/v8 --rm -v $PWD:/src -w /src -it rbrich/xcikit-emscripten-arm64
# CMake arguments (for Clion IDE):
# -DFORCE_COLORS=1 -DXCI_WIDGETS=0 -DXCI_TEXT=0 -DXCI_GRAPHICS=0
# -DCONAN_OPTIONS="-c;tools.cmake.cmaketoolchain:user_toolchain=['/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake']"

FROM emscripten/emsdk:3.1.64-arm64 AS builder

RUN echo "dev tools"; apt-get update && apt-get install --no-install-recommends -y \
gdb ninja-build python3-setuptools gpg && rm -rf /var/lib/apt/lists/*

# Ubuntu 22.04 has CMake 3.22.1, which is too old. Get newer version (https://apt.kitware.com/).
RUN echo "cmake"; apt-get purge -y cmake && \
curl https://apt.kitware.com/keys/kitware-archive-latest.asc | gpg --dearmor - > /usr/share/keyrings/kitware-archive-keyring.gpg && \
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' > /etc/apt/sources.list.d/kitware.list && \
apt-get update && apt-get install --no-install-recommends -y cmake && rm -rf /var/lib/apt/lists/*

RUN echo "conan"; pip3 --no-cache-dir install conan

ARG UID=10001
RUN useradd -m -p np -u ${UID} -s /bin/bash builder
USER builder

COPY --chown=builder docker/conan /home/builder/conan
RUN conan config install /home/builder/conan
ENV CONAN_DEFAULT_PROFILE=emscripten

# Preinstall Conan deps
ENV XCIKIT=/home/builder/xcikit
COPY --chown=builder build.sh detect_system_deps.py conanfile.py conandata.yml VERSION $XCIKIT/
RUN $XCIKIT/build.sh deps --emscripten script
RUN $XCIKIT/build.sh deps --emscripten script --debug

# Preinstall Emscripten ports (it has no explicit install command, workaround...)
RUN echo "int main(){}" > ~/dummy.c
RUN cd ; emcc -s USE_ZLIB=1 dummy.c -o dummy.out && rm dummy.*

CMD ./build.sh --emscripten core vfs data script
14 changes: 10 additions & 4 deletions docker/emscripten.dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# CI builder with Emscripten (DockerHub public image), local build check:
# docker build --pull --build-arg UID=$(id -u) -t rbrich/xcikit-emscripten . -f docker/emscripten.dockerfile
# docker run --rm -v $PWD:/src -w /src -it rbrich/xcikit-emscripten
# docker build --platform linux/amd64 --pull --build-arg UID=$(id -u) -t rbrich/xcikit-emscripten . -f docker/emscripten.dockerfile
# docker run --platform linux/amd64 --rm -v $PWD:/src -w /src -it rbrich/xcikit-emscripten
# CMake arguments (for Clion IDE):
# -DFORCE_COLORS=1 -DXCI_WIDGETS=0 -DXCI_TEXT=0 -DXCI_GRAPHICS=0
# -DCONAN_OPTIONS="-c;tools.cmake.cmaketoolchain:user_toolchain=['/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake']"

FROM emscripten/emsdk:3.1.62 AS builder
FROM emscripten/emsdk:3.1.64 AS builder

RUN echo "dev tools"; apt-get update && apt-get install --no-install-recommends -y \
gdb ninja-build python3-setuptools && rm -rf /var/lib/apt/lists/*
gdb ninja-build python3-setuptools gpg && rm -rf /var/lib/apt/lists/*

# Ubuntu 22.04 has CMake 3.22.1, which is too old. Get newer version (https://apt.kitware.com/).
RUN echo "cmake"; apt-get purge -y cmake && \
curl https://apt.kitware.com/keys/kitware-archive-latest.asc | gpg --dearmor - > /usr/share/keyrings/kitware-archive-keyring.gpg && \
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' > /etc/apt/sources.list.d/kitware.list && \
apt-get update && apt-get install --no-install-recommends -y cmake && rm -rf /var/lib/apt/lists/*

RUN echo "conan"; pip3 --no-cache-dir install conan

Expand Down
8 changes: 3 additions & 5 deletions src/xci/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ add_library(xci-config
add_library(xcikit::xci-config ALIAS xci-config)
target_precompile_headers(xci-config REUSE_FROM xci-core)

target_link_libraries(xci-config PUBLIC xci-core)
target_include_directories(xci-config
PRIVATE $<TARGET_PROPERTY:taocpp::pegtl,INTERFACE_INCLUDE_DIRECTORIES>
)

target_link_libraries(xci-config
PUBLIC xci-core
PRIVATE $<COMPILE_ONLY:taocpp::pegtl>)

if (BUILD_SHARED_LIBS)
set_target_properties(xci-config PROPERTIES CXX_VISIBILITY_PRESET default)
Expand Down
Loading

0 comments on commit 719956d

Please sign in to comment.