From d1ed8648c64b39e876ebffae8e4812ff98f8fc27 Mon Sep 17 00:00:00 2001 From: Mizux Seiha Date: Wed, 16 Oct 2024 02:14:04 +0200 Subject: [PATCH] rework --- .dockerignore | 12 ++- CMakeLists.txt | 47 ++++++++- CONTRIBUTING.md | 23 +++++ CONTRIBUTORS | 34 +++++++ ci/Makefile | 2 +- ci/vagrant/freebsd/Vagrantfile | 25 +++-- ci/vagrant/netbsd/Vagrantfile | 111 +++++++++++++++++++++ ci/vagrant/openbsd/Vagrantfile | 111 +++++++++++++++++++++ cmake/check_deps.cmake | 57 +++++++++++ cmake/cpp.cmake | 65 ------------- cmake/dependencies/CMakeLists.txt | 134 +++++++++++++++++++++++++ cmake/host.CMakeLists.txt | 116 ++++++++++++++++++++++ cmake/host.cmake | 37 +++++++ cmake/system_deps.cmake | 33 +++++++ patches/ZLIB-v1.3.1.patch | 146 ++++++++++++++++++++++++++++ patches/abseil-cpp-20240722.0.patch | 79 +++++++++++++++ patches/googletest-v1.15.2.patch | 18 ++++ patches/protobuf-v27.3.patch | 56 +++++++++++ patches/re2-2024-04-01.patch | 18 ++++ 19 files changed, 1042 insertions(+), 82 deletions(-) create mode 100644 CONTRIBUTING.md create mode 100644 CONTRIBUTORS create mode 100644 ci/vagrant/netbsd/Vagrantfile create mode 100644 ci/vagrant/openbsd/Vagrantfile create mode 100644 cmake/check_deps.cmake create mode 100644 cmake/dependencies/CMakeLists.txt create mode 100644 cmake/host.CMakeLists.txt create mode 100644 cmake/host.cmake create mode 100644 cmake/system_deps.cmake create mode 100644 patches/ZLIB-v1.3.1.patch create mode 100644 patches/abseil-cpp-20240722.0.patch create mode 100644 patches/googletest-v1.15.2.patch create mode 100644 patches/protobuf-v27.3.patch create mode 100644 patches/re2-2024-04-01.patch diff --git a/.dockerignore b/.dockerignore index 4c1ce6b..16aff2b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,23 +1,25 @@ +# Project Files unneeded by docker .dockerignore -# Project Files unneeded by docker .git .gitignore .github .clang-format -ci/Makefile +# CMake +cmake/docs +cmake/README.md + ci/docker ci/docs ci/cache -ci/export +ci/Makefile AUTHORS -CONTRIBUTING.md CONTRIBUTORS LICENSE README.md -doc +CONTRIBUTING.md # Native cmake build build/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 52b0d4a..796a6e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,9 @@ # This file is just an orchestration -cmake_minimum_required(VERSION 3.16..3.27) +cmake_minimum_required(VERSION 3.16..3.31) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -option(CMAKE_EXPORT_COMPILE_COMMANDS "Export compile command" TRUE) +# Enable output of compile commands during generation. +option(CMAKE_EXPORT_COMPILE_COMMANDS "Export compile command" ON) project(CMakeCpp VERSION 1.0.0 LANGUAGES CXX) set(PROJECT_NAMESPACE CMakeCpp) @@ -12,6 +13,14 @@ message(STATUS "${PROJECT_NAME} version: ${PROJECT_VERSION}") #message(STATUS "patch: ${PROJECT_VERSION_PATCH}") message(STATUS "system name: ${CMAKE_SYSTEM_NAME}") +# Set max os target version. +set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# Default Build Type to be Release get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(isMultiConfig) if(NOT CMAKE_CONFIGURATION_TYPES) @@ -67,8 +76,42 @@ endif() set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1) include(CTest) +option(BUILD_ZLIB "Build the ZLIB dependency Library" ON) +message(STATUS "Build ZLIB: ${BUILD_ZLIB}") + +option(BUILD_absl "Build the abseil-cpp dependency Library" ON) +message(STATUS "Build abseil-cpp: ${BUILD_absl}") + +option(BUILD_Protobuf "Build the Protobuf dependency Library" ON) +message(STATUS "Build protobuf: ${BUILD_Protobuf}") + +if(BUILD_TESTING) + option(BUILD_re2 "Build the re2 dependency Library" ON) + message(STATUS "Build re2: ${BUILD_re2}") + + option(BUILD_googletest "Build googletest" ON) + message(STATUS "Build googletest: ${BUILD_googletest}") + + option(BUILD_benchmark "Build benchmark" ON) + message(STATUS "Build benchmark: ${BUILD_benchmark}") +else() + set(BUILD_googletest OFF) + set(BUILD_benchmark OFF) +endif() + +# Find system deps +include(system_deps) + +# Build Needed dependencies +add_subdirectory(cmake/dependencies dependencies) + +include(host) +# verify deps +include(check_deps) + include(cpp) +## Examples option(BUILD_EXAMPLES "Build examples" ON) message(STATUS "Build examples: ${BUILD_EXAMPLES}") add_subdirectory(examples) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..ae319c7 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,23 @@ +# How to Contribute + +We'd love to accept your patches and contributions to this project. There are +just a few small guidelines you need to follow. + +## Contributor License Agreement + +Contributions to this project must be accompanied by a Contributor License +Agreement. You (or your employer) retain the copyright to your contribution, +this simply gives us permission to use and redistribute your contributions as +part of the project. Head over to to see +your current agreements on file or to sign a new one. + +You generally only need to submit a CLA once, so if you've already submitted one +(even if it was for a different project), you probably don't need to do it +again. + +## Code reviews + +All submissions, including submissions by project members, require review. We +use GitHub pull requests for this purpose. Consult +[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more +information on using pull requests. diff --git a/CONTRIBUTORS b/CONTRIBUTORS new file mode 100644 index 0000000..4466db1 --- /dev/null +++ b/CONTRIBUTORS @@ -0,0 +1,34 @@ +# This is the official list of people who can contribute +# (and typically have contributed) code to this repository. +# The AUTHORS file lists the copyright holders; this file +# lists people. For example, Google employees are listed here +# but not in AUTHORS, because Google holds the copyright. +# +# The submission process automatically checks to make sure +# that people submitting code are listed in this file (by email address). +# +# Names should be added to this file only after verifying that +# the individual or the individual's organization has agreed to +# the appropriate Contributor License Agreement, found here: +# +# http://code.google.com/legal/individual-cla-v1.0.html +# http://code.google.com/legal/corporate-cla-v1.0.html +# +# The agreement for individuals can be filled out on the web. +# +# When adding J Random Contributor's name to this file, +# either J's name or J's organization's name should be +# added to the AUTHORS file, depending on whether the +# individual or corporate CLA was used. + +# Names should be added to this file like so: +# Individual's name +# Individual's name +# +# An entry with multiple email addresses specifies that the +# first address should be used in the submit logs and +# that the other addresses should be recognized as the +# same person when interacting with Gerrit. + +# Please keep the list sorted. + diff --git a/ci/Makefile b/ci/Makefile index 32c2f32..bd22372 100644 --- a/ci/Makefile +++ b/ci/Makefile @@ -433,4 +433,4 @@ clean: clean_all clean_platforms clean_toolchains clean_web clean_vms distclean: clean -docker container rm -f $$(docker container ls -aq) -docker image rm -f $$(docker image ls -aq) - -vagrant box remove -f generic/freebsd12 + -vagrant box remove -f generic/freebsd14 diff --git a/ci/vagrant/freebsd/Vagrantfile b/ci/vagrant/freebsd/Vagrantfile index f2ef311..198183a 100644 --- a/ci/vagrant/freebsd/Vagrantfile +++ b/ci/vagrant/freebsd/Vagrantfile @@ -13,8 +13,10 @@ Vagrant.configure("2") do |config| # Every Vagrant development environment requires a box. You can search for # boxes at https://vagrantcloud.com/search. config.vm.guest = :freebsd - config.vm.box = "generic/freebsd13" - + config.vm.box = "generic/freebsd14" + config.vm.provider "virtualbox" do |v| + v.name = "ci_freebsd" + end config.ssh.shell = "sh" # Disable automatic box update checking. If you disable this, then @@ -49,13 +51,6 @@ Vagrant.configure("2") do |config| #config.vm.synced_folder "../../..", "/home/vagrant/project" config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true - config.vm.provision "file", source: "../../../CMakeLists.txt", destination: "$HOME/project/" - config.vm.provision "file", source: "../../../cmake", destination: "$HOME/project/" - config.vm.provision "file", source: "../../../Foo", destination: "$HOME/project/" - config.vm.provision "file", source: "../../../Bar", destination: "$HOME/project/" - config.vm.provision "file", source: "../../../FooBar", destination: "$HOME/project/" - config.vm.provision "file", source: "../../../FooBarApp", destination: "$HOME/project/" - config.vm.provision "file", source: "../../../examples", destination: "$HOME/project/" # Provider-specific configuration so you can fine-tune various # backing providers for Vagrant. These expose provider-specific options. @@ -81,21 +76,33 @@ Vagrant.configure("2") do |config| pkg update -f pkg install -y git cmake SHELL + + config.vm.provision "file", source: "../../../CMakeLists.txt", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../cmake", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../Foo", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../Bar", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../FooBar", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../FooBarApp", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../examples", destination: "$HOME/project/" + config.vm.provision "devel", type: "shell", inline:<<-SHELL set -x cd project ls SHELL + config.vm.provision "configure", type: "shell", inline:<<-SHELL set -x cd project cmake -S. -Bbuild SHELL + config.vm.provision "build", type: "shell", inline:<<-SHELL set -x cd project cmake --build build -v SHELL + config.vm.provision "test", type: "shell", inline:<<-SHELL set -x cd project diff --git a/ci/vagrant/netbsd/Vagrantfile b/ci/vagrant/netbsd/Vagrantfile new file mode 100644 index 0000000..5756351 --- /dev/null +++ b/ci/vagrant/netbsd/Vagrantfile @@ -0,0 +1,111 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure("2") do |config| + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. + + # Every Vagrant development environment requires a box. You can search for + # boxes at https://vagrantcloud.com/search. + config.vm.guest = :netbsd + config.vm.box = "generic/netbsd9" + config.vm.provider "virtualbox" do |v| + v.name = "ci_netbsd" + end + config.ssh.shell = "sh" + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + # config.vm.box_check_update = false + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + # NOTE: This will enable public access to the opened port + # config.vm.network "forwarded_port", guest: 80, host: 8080 + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine and only allow access + # via 127.0.0.1 to disable public access + # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + # config.vm.network "private_network", ip: "192.168.33.10" + + # Create a public network, which generally matched to bridged network. + # Bridged networks make the machine appear as another physical device on + # your network. + # config.vm.network "public_network" + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + #config.vm.synced_folder "../../..", "/home/vagrant/project" + config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true + + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + # config.vm.provider "virtualbox" do |vb| + # # Display the VirtualBox GUI when booting the machine + # vb.gui = true + # + # # Customize the amount of memory on the VM: + # vb.memory = "1024" + # end + # + # View the documentation for the provider you are using for more + # information on available options. + + # Enable provisioning with a shell script. Additional provisioners such as + # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the + # documentation for more information about their specific syntax and use. + # note: clang installed by default + config.vm.provision "env", type: "shell", inline:<<-SHELL + set -x + pkg update -f + pkg install -y git cmake + SHELL + + config.vm.provision "file", source: "../../../CMakeLists.txt", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../cmake", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../Foo", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../Bar", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../FooBar", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../FooBarApp", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../examples", destination: "$HOME/project/" + + config.vm.provision "devel", type: "shell", inline:<<-SHELL + set -x + cd project + ls + SHELL + + config.vm.provision "configure", type: "shell", inline:<<-SHELL + set -x + cd project + cmake -S. -Bbuild + SHELL + + config.vm.provision "build", type: "shell", inline:<<-SHELL + set -x + cd project + cmake --build build -v + SHELL + + config.vm.provision "test", type: "shell", inline:<<-SHELL + set -x + cd project + cmake --build build --target test -v + SHELL +end diff --git a/ci/vagrant/openbsd/Vagrantfile b/ci/vagrant/openbsd/Vagrantfile new file mode 100644 index 0000000..a53931d --- /dev/null +++ b/ci/vagrant/openbsd/Vagrantfile @@ -0,0 +1,111 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure("2") do |config| + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. + + # Every Vagrant development environment requires a box. You can search for + # boxes at https://vagrantcloud.com/search. + config.vm.guest = :openbsd + config.vm.box = "generic/openbsd7" + config.vm.provider "virtualbox" do |v| + v.name = "ci_openbsd" + end + config.ssh.shell = "sh" + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + # config.vm.box_check_update = false + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + # NOTE: This will enable public access to the opened port + # config.vm.network "forwarded_port", guest: 80, host: 8080 + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine and only allow access + # via 127.0.0.1 to disable public access + # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + # config.vm.network "private_network", ip: "192.168.33.10" + + # Create a public network, which generally matched to bridged network. + # Bridged networks make the machine appear as another physical device on + # your network. + # config.vm.network "public_network" + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + #config.vm.synced_folder "../../..", "/home/vagrant/project" + config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true + + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + # config.vm.provider "virtualbox" do |vb| + # # Display the VirtualBox GUI when booting the machine + # vb.gui = true + # + # # Customize the amount of memory on the VM: + # vb.memory = "1024" + # end + # + # View the documentation for the provider you are using for more + # information on available options. + + # Enable provisioning with a shell script. Additional provisioners such as + # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the + # documentation for more information about their specific syntax and use. + # note: clang installed by default + config.vm.provision "env", type: "shell", inline:<<-SHELL + set -x + pkg update -f + pkg install -y git cmake + SHELL + + config.vm.provision "file", source: "../../../CMakeLists.txt", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../cmake", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../Foo", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../Bar", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../FooBar", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../FooBarApp", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../examples", destination: "$HOME/project/" + + config.vm.provision "devel", type: "shell", inline:<<-SHELL + set -x + cd project + ls + SHELL + + config.vm.provision "configure", type: "shell", inline:<<-SHELL + set -x + cd project + cmake -S. -Bbuild + SHELL + + config.vm.provision "build", type: "shell", inline:<<-SHELL + set -x + cd project + cmake --build build -v + SHELL + + config.vm.provision "test", type: "shell", inline:<<-SHELL + set -x + cd project + cmake --build build --target test -v + SHELL +end diff --git a/cmake/check_deps.cmake b/cmake/check_deps.cmake new file mode 100644 index 0000000..bb11789 --- /dev/null +++ b/cmake/check_deps.cmake @@ -0,0 +1,57 @@ +# Check dependencies +if(NOT TARGET ZLIB::ZLIB) + message(FATAL_ERROR "Target ZLIB::ZLIB not available.") +endif() + +if(NOT TARGET absl::base) + message(FATAL_ERROR "Target absl::base not available.") +endif() +set(ABSL_DEPS + absl::base + absl::core_headers + absl::absl_check + absl::absl_log + absl::check + absl::die_if_null + absl::flags + absl::flags_commandlineflag + absl::flags_marshalling + absl::flags_parse + absl::flags_reflection + absl::flags_usage + absl::log + absl::log_flags + absl::log_globals + absl::log_initialize + absl::log_internal_message + absl::cord + absl::random_random + absl::raw_hash_set + absl::hash + absl::leak_check + absl::memory + absl::meta + absl::stacktrace + absl::status + absl::statusor + absl::str_format + absl::strings + absl::synchronization + absl::time + absl::any + ) + +if(NOT TARGET protobuf::libprotobuf) + message(FATAL_ERROR "Target protobuf::libprotobuf not available.") +endif() + +# CXX Test +if(BUILD_TESTING) + if(NOT TARGET re2::re2) + message(FATAL_ERROR "Target re2::re2 not available.") + endif() + + if(NOT TARGET GTest::gtest_main) + message(FATAL_ERROR "Target GTest::gtest_main not available.") + endif() +endif() diff --git a/cmake/cpp.cmake b/cmake/cpp.cmake index 1cf44c6..32fc7cf 100644 --- a/cmake/cpp.cmake +++ b/cmake/cpp.cmake @@ -33,72 +33,7 @@ if(CHECK_TYPE) cmake_pop_check_state() endif() -# Check dependencies -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREAD_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads REQUIRED) - -include(FetchContent) -set(FETCHCONTENT_QUIET OFF) -set(FETCHCONTENT_UPDATES_DISCONNECTED ON) -set(CMAKE_POSITION_INDEPENDENT_CODE ON) -set(CMAKE_Fortran_COMPILER OFF) - -# ############################################################################## -# ABSEIL-CPP -# ############################################################################## -message(CHECK_START "Fetching Abseil-cpp") -list(APPEND CMAKE_MESSAGE_INDENT " ") -set(ABSL_USE_SYSTEM_INCLUDES ON) -# We want Abseil to declare what C++ standard it was compiled with. -set(ABSL_PROPAGATE_CXX_STD ON) -# We want Abseil to keep the INSTALL rules enabled, even though it is a -# subproject. Otherwise the install rules in this project break. -set(ABSL_ENABLE_INSTALL ON) -FetchContent_Declare( - absl - GIT_REPOSITORY "https://github.com/abseil/abseil-cpp.git" - GIT_TAG "20240116.2" - GIT_SHALLOW TRUE - PATCH_COMMAND git apply --ignore-whitespace "${CMAKE_CURRENT_LIST_DIR}/../patches/abseil-cpp-20240116.2.patch" - OVERRIDE_FIND_PACKAGE) -FetchContent_MakeAvailable(absl) -list(POP_BACK CMAKE_MESSAGE_INDENT) -message(CHECK_PASS "fetched") - -# ############################################################################## -# Protobuf -# ############################################################################## -message(CHECK_START "Fetching Protobuf") -list(APPEND CMAKE_MESSAGE_INDENT " ") -set(protobuf_BUILD_TESTS OFF) -set(protobuf_BUILD_SHARED_LIBS OFF) -set(protobuf_BUILD_EXPORT OFF) -set(protobuf_MSVC_STATIC_RUNTIME OFF) -set(protobuf_WITH_ZLIB OFF) -FetchContent_Declare( - protobuf - GIT_REPOSITORY "https://github.com/protocolbuffers/protobuf.git" - GIT_TAG "v27.2" - GIT_SUBMODULES "" - GIT_SHALLOW TRUE - PATCH_COMMAND git apply --ignore-whitespace "${CMAKE_CURRENT_LIST_DIR}/../patches/protobuf-v27.2.patch") -FetchContent_MakeAvailable(protobuf) -list(POP_BACK CMAKE_MESSAGE_INDENT) -message(CHECK_PASS "fetched") - if(BUILD_TESTING) - message(CHECK_START "Fetching Googletest") - FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG main - GIT_SHALLOW TRUE - FIND_PACKAGE_ARGS NAMES GTest GMock) - #set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - FetchContent_MakeAvailable(googletest) - message(CHECK_PASS "fetched") - message(CHECK_START "Fetching Catch2") FetchContent_Declare( Catch2 diff --git a/cmake/dependencies/CMakeLists.txt b/cmake/dependencies/CMakeLists.txt new file mode 100644 index 0000000..14ef0aa --- /dev/null +++ b/cmake/dependencies/CMakeLists.txt @@ -0,0 +1,134 @@ +include(FetchContent) +set(FETCHCONTENT_QUIET OFF) +set(FETCHCONTENT_UPDATES_DISCONNECTED ON) +set(BUILD_SHARED_LIBS ON) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) +set(BUILD_TESTING OFF) +set(CMAKE_Fortran_COMPILER OFF) + +# ############################################################################## +# ZLIB +# ############################################################################## +if(BUILD_ZLIB) + message(CHECK_START "Fetching ZLIB") + list(APPEND CMAKE_MESSAGE_INDENT " ") + set(ZLIB_BUILD_EXAMPLES OFF) + FetchContent_Declare( + ZLIB + GIT_REPOSITORY "https://github.com/madler/ZLIB.git" + GIT_TAG "v1.3.1" + PATCH_COMMAND git apply --ignore-whitespace + "${CMAKE_CURRENT_LIST_DIR}/../../patches/ZLIB-v1.3.1.patch") + FetchContent_MakeAvailable(ZLIB) + list(POP_BACK CMAKE_MESSAGE_INDENT) + message(CHECK_PASS "fetched") +endif() + +# ############################################################################## +# ABSEIL-CPP +# ############################################################################## +if(BUILD_absl) + message(CHECK_START "Fetching Abseil-cpp") + list(APPEND CMAKE_MESSAGE_INDENT " ") + set(ABSL_USE_SYSTEM_INCLUDES ON) + # We want Abseil to declare what C++ standard it was compiled with. + set(ABSL_PROPAGATE_CXX_STD ON) + # We want Abseil to keep the INSTALL rules enabled, even though it is a + # subproject. Otherwise the install rules in this project break. + set(ABSL_ENABLE_INSTALL ON) + set(ABSL_BUILD_TESTING OFF) + FetchContent_Declare( + absl + GIT_REPOSITORY "https://github.com/abseil/abseil-cpp.git" + GIT_TAG "20240722.0" + GIT_SHALLOW TRUE + PATCH_COMMAND git apply --ignore-whitespace + "${CMAKE_CURRENT_LIST_DIR}/../../patches/abseil-cpp-20240722.0.patch" + OVERRIDE_FIND_PACKAGE) + FetchContent_MakeAvailable(absl) + list(POP_BACK CMAKE_MESSAGE_INDENT) + message(CHECK_PASS "fetched") +endif() + +# ############################################################################## +# Protobuf +# ############################################################################## +if(BUILD_Protobuf) + message(CHECK_START "Fetching Protobuf") + list(APPEND CMAKE_MESSAGE_INDENT " ") + set(protobuf_BUILD_TESTS OFF) + set(protobuf_BUILD_SHARED_LIBS ON) + set(protobuf_BUILD_EXPORT OFF) + set(protobuf_MSVC_STATIC_RUNTIME OFF) + #set(protobuf_BUILD_LIBUPB ON) + set(protobuf_WITH_ZLIB OFF) + FetchContent_Declare( + Protobuf + GIT_REPOSITORY "https://github.com/protocolbuffers/protobuf.git" + GIT_TAG "v27.3" + GIT_SHALLOW TRUE + GIT_SUBMODULES "" + PATCH_COMMAND git apply --ignore-whitespace + "${CMAKE_CURRENT_LIST_DIR}/../../patches/protobuf-v27.3.patch" + ) + FetchContent_MakeAvailable(Protobuf) + list(POP_BACK CMAKE_MESSAGE_INDENT) + message(CHECK_PASS "fetched") +endif() + +############### +## TESTING ## +############### +if(BUILD_re2) + message(CHECK_START "Fetching re2") + list(APPEND CMAKE_MESSAGE_INDENT " ") + set(RE2_BUILD_TESTING OFF) + FetchContent_Declare( + re2 + GIT_REPOSITORY "https://github.com/google/re2.git" + GIT_TAG "2024-04-01" + GIT_SHALLOW TRUE + PATCH_COMMAND git apply --ignore-whitespace + "${CMAKE_CURRENT_LIST_DIR}/../../patches/re2-2024-04-01.patch" + ) + FetchContent_MakeAvailable(re2) + list(POP_BACK CMAKE_MESSAGE_INDENT) + message(CHECK_PASS "fetched") +endif() + +if(BUILD_googletest) + message(CHECK_START "Fetching googletest") + list(APPEND CMAKE_MESSAGE_INDENT " ") + FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG v1.15.2 + GIT_SHALLOW TRUE + PATCH_COMMAND git apply --ignore-whitespace + "${CMAKE_CURRENT_LIST_DIR}/../../patches/googletest-v1.15.2.patch" + FIND_PACKAGE_ARGS NAMES GTest GMock) + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + set(INSTALL_GTEST OFF) + set(GTEST_HAS_ABSL ON) + FetchContent_MakeAvailable(googletest) + list(POP_BACK CMAKE_MESSAGE_INDENT) + message(CHECK_PASS "fetched") +endif() + +if(BUILD_benchmark) + message(CHECK_START "Fetching benchmark") + list(APPEND CMAKE_MESSAGE_INDENT " ") + FetchContent_Declare( + benchmark + GIT_REPOSITORY https://github.com/google/benchmark.git + GIT_TAG v1.8.4 + GIT_SHALLOW TRUE + #PATCH_COMMAND git apply --ignore-whitespace "" + ) + set(BENCHMARK_ENABLE_TESTING OFF) + set(BENCHMARK_ENABLE_WERROR OFF) + set(BENCHMARK_ENABLE_INSTALL OFF) + FetchContent_MakeAvailable(benchmark) + list(POP_BACK CMAKE_MESSAGE_INDENT) + message(CHECK_PASS "fetched") +endif() diff --git a/cmake/host.CMakeLists.txt b/cmake/host.CMakeLists.txt new file mode 100644 index 0000000..833a7b0 --- /dev/null +++ b/cmake/host.CMakeLists.txt @@ -0,0 +1,116 @@ +cmake_minimum_required(VERSION 3.14) + +# fetch_git_dependency() +# +# CMake function to download, build and install (in staging area) a dependency at configure +# time. +# +# Parameters: +# NAME: name of the dependency +# REPOSITORY: git url of the dependency +# TAG: tag of the dependency +# PATCH_COMMAND: apply patch +# SOURCE_SUBDIR: Path to source CMakeLists.txt relative to root dir +# CMAKE_ARGS: List of specific CMake args to add +# +# e.g.: +# fetch_git_dependency( +# NAME +# abseil-cpp +# URL +# https://github.com/abseil/abseil-cpp.git +# TAG +# main +# PATCH_COMMAND +# "git apply ${CMAKE_SOURCE_DIR}/patches/abseil-cpp.patch" +# ) +function(fetch_git_dependency) + set(options "") + set(oneValueArgs NAME REPOSITORY TAG PATCH_COMMAND SOURCE_SUBDIR) + set(multiValueArgs CMAKE_ARGS) + cmake_parse_arguments(GIT_DEP + "${options}" + "${oneValueArgs}" + "${multiValueArgs}" + ${ARGN} + ) + message(STATUS "Building ${GIT_DEP_NAME}: ...") + string(TOLOWER ${GIT_DEP_NAME} NAME_LOWER) + + if(GIT_DEP_PATCH_COMMAND) + set(PATCH_CMD "${GIT_DEP_PATCH_COMMAND}") + else() + set(PATCH_CMD "") + endif() + configure_file( + ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt.in + ${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-subbuild/CMakeLists.txt @ONLY) + + execute_process( + COMMAND ${CMAKE_COMMAND} -S. -Bproject_build -G "${CMAKE_GENERATOR}" + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-subbuild) + if(result) + message(FATAL_ERROR "CMake step for ${GIT_DEP_NAME} failed: ${result}") + endif() + + execute_process( + COMMAND ${CMAKE_COMMAND} --build project_build --config ${CMAKE_BUILD_TYPE} + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-subbuild) + if(result) + message(FATAL_ERROR "Build step for ${GIT_DEP_NAME} failed: ${result}") + endif() + + if(GIT_DEP_SOURCE_SUBDIR) + add_subdirectory( + ${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-src/${GIT_DEP_SOURCE_SUBDIR} + ${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-build) + else() + add_subdirectory( + ${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-src + ${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-build) + endif() + + message(STATUS "Building ${GIT_DEP_NAME}: ...DONE") +endfunction() + +project(host-meta CXX) + +include(FetchContent) +set(FETCHCONTENT_QUIET OFF) +set(FETCHCONTENT_UPDATES_DISCONNECTED ON) +set(BUILD_SHARED_LIBS OFF) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) +set(BUILD_TESTING OFF) + +message(CHECK_START "Fetching Abseil-cpp") +list(APPEND CMAKE_MESSAGE_INDENT " ") +set(ABSL_ENABLE_INSTALL ON) +set(ABSL_USE_SYSTEM_INCLUDES ON) +set(ABSL_PROPAGATE_CXX_STD ON) +FetchContent_Declare( + absl + GIT_REPOSITORY "https://github.com/abseil/abseil-cpp.git" + GIT_TAG "20240722.0" + PATCH_COMMAND git apply "${CMAKE_CURRENT_LIST_DIR}/@PATCHES_PATH@/abseil-cpp-20240722.0.patch") +FetchContent_MakeAvailable(absl) +list(POP_BACK CMAKE_MESSAGE_INDENT) +message(CHECK_PASS "fetched") + +message(CHECK_START "Fetching Protobuf") +list(APPEND CMAKE_MESSAGE_INDENT " ") +set(protobuf_BUILD_TESTS OFF) +set(protobuf_BUILD_SHARED_LIBS ON) +set(protobuf_BUILD_EXPORT OFF) +set(protobuf_MSVC_STATIC_RUNTIME OFF) +set(protobuf_WITH_ZLIB OFF) +FetchContent_Declare( + protobuf + GIT_REPOSITORY "https://github.com/protocolbuffers/protobuf.git" + GIT_TAG "v27.3" + GIT_SUBMODULES "" + PATCH_COMMAND git apply "${CMAKE_CURRENT_LIST_DIR}/@PATCHES_PATH@/protobuf-v27.3.patch") +FetchContent_MakeAvailable(protobuf) +list(POP_BACK CMAKE_MESSAGE_INDENT) +message(CHECK_PASS "fetched") diff --git a/cmake/host.cmake b/cmake/host.cmake new file mode 100644 index 0000000..d217c65 --- /dev/null +++ b/cmake/host.cmake @@ -0,0 +1,37 @@ +if(NOT CMAKE_CROSSCOMPILING) + set(PROTOC_PRG protobuf::protoc) + return() +endif() + +message(STATUS "Subproject: HostTools...") + +file(RELATIVE_PATH + PATCHES_PATH + ${CMAKE_CURRENT_BINARY_DIR}/host_tools + ${CMAKE_CURRENT_SOURCE_DIR}/patches) + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/host.CMakeLists.txt + ${CMAKE_CURRENT_BINARY_DIR}/host_tools/CMakeLists.txt + @ONLY) + +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/host_tools + COMMAND ${CMAKE_COMMAND} -E remove_directory build + COMMAND ${CMAKE_COMMAND} -S. -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH=${CMAKE_CURRENT_BINARY_DIR}/host_tools/bin + COMMAND ${CMAKE_COMMAND} --build build --config Release -v + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/host_tools +) + +add_custom_target(host_tools + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/host_tools + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + +add_executable(host_protoc IMPORTED GLOBAL) +set_target_properties(host_protoc PROPERTIES + IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/host_tools/bin/protoc) + +add_dependencies(host_protoc host_tools) +set(PROTOC_PRG host_protoc) + +message(STATUS "Subproject: HostTools...DONE") diff --git a/cmake/system_deps.cmake b/cmake/system_deps.cmake new file mode 100644 index 0000000..4683390 --- /dev/null +++ b/cmake/system_deps.cmake @@ -0,0 +1,33 @@ +# Check dependencies +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREAD_PREFER_PTHREAD_FLAG TRUE) +find_package(Threads REQUIRED) + +# Tell find_package() to try “Config” mode before “Module” mode if no mode was specified. +# This should avoid find_package() to first find our FindXXX.cmake modules if +# distro package already provide a CMake config file... +set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE) + +# libprotobuf force us to depends on ZLIB::ZLIB target +if(NOT BUILD_ZLIB) + find_package(ZLIB REQUIRED) +endif() + +if(NOT BUILD_absl) + find_package(absl REQUIRED) +endif() + +if(NOT BUILD_Protobuf) + find_package(Protobuf REQUIRED) +endif() + +# CXX Test +if(BUILD_TESTING) + if(NOT BUILD_re2) + find_package(re2 REQUIRED) + endif() + + if(NOT BUILD_googletest) + find_package(GTest REQUIRED) + endif() +endif() diff --git a/patches/ZLIB-v1.3.1.patch b/patches/ZLIB-v1.3.1.patch new file mode 100644 index 0000000..64f8097 --- /dev/null +++ b/patches/ZLIB-v1.3.1.patch @@ -0,0 +1,146 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 15ceebe..03825a2 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -1,23 +1,21 @@ +-cmake_minimum_required(VERSION 2.4.4...3.15.0) +-set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) ++cmake_minimum_required(VERSION 3.15) + +-project(zlib C) +- +-set(VERSION "1.3.1") ++project(zlib VERSION 1.3.1 LANGUAGES C) + + option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" ON) + +-set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") +-set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") +-set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers") +-set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages") +-set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files") ++include(GNUInstallDirs) ++set(INSTALL_BIN_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH "Installation directory for executables") ++set(INSTALL_LIB_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Installation directory for libraries") ++set(INSTALL_INC_DIR "${CMAKE_INSTALL_INCLUDEDIR}" CACHE PATH "Installation directory for headers") ++set(INSTALL_MAN_DIR "${CMAKE_INSTALL_MANDIR}" CACHE PATH "Installation directory for manual pages") ++set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_DATADIR}/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files") + + include(CheckTypeSize) + include(CheckFunctionExists) + include(CheckIncludeFile) + include(CheckCSourceCompiles) +-enable_testing() ++include(CTest) + + check_include_file(sys/types.h HAVE_SYS_TYPES_H) + check_include_file(stdint.h HAVE_STDINT_H) +@@ -149,12 +147,21 @@ if(MINGW) + set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj) + endif(MINGW) + +-add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) +-target_include_directories(zlib PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) +-add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) +-target_include_directories(zlibstatic PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) +-set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL) +-set_target_properties(zlib PROPERTIES SOVERSION 1) ++if(BUILD_SHARED_LIBS) ++ add_library(ZLIB SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) ++ set_target_properties(ZLIB PROPERTIES DEFINE_SYMBOL ZLIB_DLL) ++ set_target_properties(ZLIB PROPERTIES SOVERSION 1) ++else() ++ add_library(ZLIB STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) ++endif() ++ ++target_include_directories(ZLIB PUBLIC ++ $ ++ $ ++ $) ++ ++add_library(ZLIB::ZLIB ALIAS ZLIB) ++ + + if(NOT CYGWIN) + # This property causes shared libraries on Linux to have the full version +@@ -164,26 +171,45 @@ if(NOT CYGWIN) + # + # This has no effect with MSVC, on that platform the version info for + # the DLL comes from the resource file win32/zlib1.rc +- set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION}) ++ set_target_properties(ZLIB PROPERTIES VERSION ${ZLIB_FULL_VERSION}) + endif() + + if(UNIX) + # On unix-like platforms the library is almost always called libz +- set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z) +- if(NOT APPLE AND NOT(CMAKE_SYSTEM_NAME STREQUAL AIX)) +- set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"") ++ set_target_properties(ZLIB PROPERTIES OUTPUT_NAME z) ++ if(NOT APPLE AND NOT(CMAKE_SYSTEM_NAME STREQUAL AIX) AND BUILD_SHARED_LIBS) ++ set_target_properties(ZLIB PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"") + endif() + elseif(BUILD_SHARED_LIBS AND WIN32) + # Creates zlib1.dll when building shared library version +- set_target_properties(zlib PROPERTIES SUFFIX "1.dll") ++ set_target_properties(ZLIB PROPERTIES SUFFIX "1.dll") ++endif() ++ ++if(NOT UNIX) ++ set_target_properties(ZLIB PROPERTIES OUTPUT_NAME zlib) + endif() + +-if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) +- install(TARGETS zlib zlibstatic +- RUNTIME DESTINATION "${INSTALL_BIN_DIR}" +- ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" +- LIBRARY DESTINATION "${INSTALL_LIB_DIR}" ) ++if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) ++ install(TARGETS ZLIB ++ EXPORT ZLIBTargets ++ RUNTIME DESTINATION "${INSTALL_BIN_DIR}" ++ ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" ++ LIBRARY DESTINATION "${INSTALL_LIB_DIR}") ++ install(EXPORT ZLIBTargets ++ NAMESPACE ZLIB:: ++ DESTINATION lib/cmake/ZLIB) ++ include(CMakePackageConfigHelpers) ++ write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/ZLIBConfigVersion.cmake" ++ VERSION ${PROJECT_VERSION} ++ COMPATIBILITY SameMajorVersion) ++ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/ZLIBConfig.cmake" ++ "include(\"\${CMAKE_CURRENT_LIST_DIR}/ZLIBTargets.cmake\")" ++ ) ++ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ZLIBConfig.cmake" ++ "${CMAKE_CURRENT_BINARY_DIR}/ZLIBConfigVersion.cmake" ++ DESTINATION lib/cmake/ZLIB) + endif() ++ + if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL ) + install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR}") + endif() +@@ -199,20 +225,20 @@ endif() + #============================================================================ + if(ZLIB_BUILD_EXAMPLES) + add_executable(example test/example.c) +- target_link_libraries(example zlib) ++ target_link_libraries(example ZLIB) + add_test(example example) + + add_executable(minigzip test/minigzip.c) +- target_link_libraries(minigzip zlib) ++ target_link_libraries(minigzip ZLIB) + + if(HAVE_OFF64_T) + add_executable(example64 test/example.c) +- target_link_libraries(example64 zlib) ++ target_link_libraries(example64 ZLIB) + set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") + add_test(example64 example64) + + add_executable(minigzip64 test/minigzip.c) +- target_link_libraries(minigzip64 zlib) ++ target_link_libraries(minigzip64 ZLIB) + set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") + endif() + endif() diff --git a/patches/abseil-cpp-20240722.0.patch b/patches/abseil-cpp-20240722.0.patch new file mode 100644 index 0000000..7703e80 --- /dev/null +++ b/patches/abseil-cpp-20240722.0.patch @@ -0,0 +1,79 @@ +diff --git a/CMake/AbseilDll.cmake b/CMake/AbseilDll.cmake +index 32cc28f..e51d6df 100644 +--- a/CMake/AbseilDll.cmake ++++ b/CMake/AbseilDll.cmake +@@ -699,31 +699,44 @@ set(ABSL_INTERNAL_TEST_DLL_TARGETS + + include(CheckCXXSourceCompiles) + +-check_cxx_source_compiles( +- [==[ +-#ifdef _MSC_VER +-# if _MSVC_LANG < 201703L +-# error "The compiler defaults or is configured for C++ < 17" +-# endif +-#elif __cplusplus < 201703L +-# error "The compiler defaults or is configured for C++ < 17" +-#endif +-int main() { return 0; } +-]==] ++message(WARNING "ABSL_CXX_STANDARD: ${ABSL_CXX_STANDARD}") ++message(WARNING "CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD}") ++message(WARNING "CMAKE_CXX_STANDARD_REQUIRED: ${CMAKE_CXX_STANDARD_REQUIRED}") ++message(WARNING "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") ++ ++if(CMAKE_CXX_STANDARD GREATER_EQUAL 17) ++ set(ABSL_INTERNAL_AT_LEAST_CXX17 TRUE) ++else() ++ check_cxx_source_compiles( ++ [==[ ++ #ifdef _MSC_VER ++ # if _MSVC_LANG < 201703L ++ # error "The compiler defaults or is configured for C++ < 17" ++ # endif ++ #elif __cplusplus < 201703L ++ # error "The compiler defaults or is configured for C++ < 17" ++ #endif ++ int main() { return 0; } ++ ]==] + ABSL_INTERNAL_AT_LEAST_CXX17) ++endif() + +-check_cxx_source_compiles( +- [==[ +-#ifdef _MSC_VER +-# if _MSVC_LANG < 202002L +-# error "The compiler defaults or is configured for C++ < 20" +-# endif +-#elif __cplusplus < 202002L +-# error "The compiler defaults or is configured for C++ < 20" +-#endif +-int main() { return 0; } +-]==] ++if(CMAKE_CXX_STANDARD GREATER_EQUAL 20) ++ set(ABSL_INTERNAL_AT_LEAST_CXX20 TRUE) ++else() ++ check_cxx_source_compiles( ++ [==[ ++ #ifdef _MSC_VER ++ # if _MSVC_LANG < 202002L ++ # error "The compiler defaults or is configured for C++ < 20" ++ # endif ++ #elif __cplusplus < 202002L ++ # error "The compiler defaults or is configured for C++ < 20" ++ #endif ++ int main() { return 0; } ++ ]==] + ABSL_INTERNAL_AT_LEAST_CXX20) ++endif() + + if(ABSL_INTERNAL_AT_LEAST_CXX20) + set(ABSL_INTERNAL_CXX_STD_FEATURE cxx_std_20) +@@ -731,6 +744,7 @@ elseif(ABSL_INTERNAL_AT_LEAST_CXX17) + set(ABSL_INTERNAL_CXX_STD_FEATURE cxx_std_17) + else() + set(ABSL_INTERNAL_CXX_STD_FEATURE cxx_std_14) ++ message(FATAL_ERROR "Should not pass here !!!") + endif() + + function(absl_internal_dll_contains) diff --git a/patches/googletest-v1.15.2.patch b/patches/googletest-v1.15.2.patch new file mode 100644 index 0000000..1d5da3c --- /dev/null +++ b/patches/googletest-v1.15.2.patch @@ -0,0 +1,18 @@ +diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake +index 580ac1c..c6cc44c 100644 +--- a/googletest/cmake/internal_utils.cmake ++++ b/googletest/cmake/internal_utils.cmake +@@ -190,6 +190,13 @@ function(cxx_library_with_type name type cxx_flags) + COMPILE_DEFINITIONS "GTEST_CREATE_SHARED_LIBRARY=1") + target_compile_definitions(${name} INTERFACE + $) ++ if(APPLE) ++ set_target_properties(${name} PROPERTIES ++ INSTALL_RPATH "@loader_path") ++ elseif(UNIX) ++ set_target_properties(${name} PROPERTIES ++ INSTALL_RPATH "$ORIGIN") ++ endif() + endif() + if (DEFINED GTEST_HAS_PTHREAD) + target_link_libraries(${name} PUBLIC Threads::Threads) diff --git a/patches/protobuf-v27.3.patch b/patches/protobuf-v27.3.patch new file mode 100644 index 0000000..331e026 --- /dev/null +++ b/patches/protobuf-v27.3.patch @@ -0,0 +1,56 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 807ef014..8937d5eb 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -42,7 +42,7 @@ else (BUILD_SHARED_LIBS) + endif (BUILD_SHARED_LIBS) + option(protobuf_BUILD_SHARED_LIBS "Build Shared Libraries" ${protobuf_BUILD_SHARED_LIBS_DEFAULT}) + include(CMakeDependentOption) +-cmake_dependent_option(protobuf_MSVC_STATIC_RUNTIME "Link static runtime libraries" ON ++cmake_dependent_option(protobuf_MSVC_STATIC_RUNTIME "Link static runtime libraries" OFF + "NOT protobuf_BUILD_SHARED_LIBS" OFF) + set(protobuf_WITH_ZLIB_DEFAULT ON) + option(protobuf_WITH_ZLIB "Build with zlib support" ${protobuf_WITH_ZLIB_DEFAULT}) +@@ -160,24 +160,16 @@ endif() + + set(_protobuf_FIND_ZLIB) + if (protobuf_WITH_ZLIB) +- find_package(ZLIB) +- if (ZLIB_FOUND) +- set(HAVE_ZLIB 1) +- # FindZLIB module define ZLIB_INCLUDE_DIRS variable +- # Set ZLIB_INCLUDE_DIRECTORIES for compatible +- set(ZLIB_INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIRECTORIES} ${ZLIB_INCLUDE_DIRS}) +- # Using imported target if exists +- if (TARGET ZLIB::ZLIB) +- set(ZLIB_LIBRARIES ZLIB::ZLIB) +- set(_protobuf_FIND_ZLIB "if(NOT ZLIB_FOUND)\n find_package(ZLIB)\nendif()") +- endif (TARGET ZLIB::ZLIB) +- else (ZLIB_FOUND) +- set(HAVE_ZLIB 0) +- # Explicitly set these to empty (override NOT_FOUND) so cmake doesn't +- # complain when we use them later. +- set(ZLIB_INCLUDE_DIRECTORIES) +- set(ZLIB_LIBRARIES) +- endif (ZLIB_FOUND) ++ if (NOT TARGET ZLIB::ZLIB) ++ find_package(ZLIB REQUIRED) ++ endif() ++ set(HAVE_ZLIB 1) ++ # FindZLIB module define ZLIB_INCLUDE_DIRS variable ++ # Set ZLIB_INCLUDE_DIRECTORIES for compatible ++ set(ZLIB_INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIRECTORIES} ${ZLIB_INCLUDE_DIRS}) ++ # Using imported target if exists ++ set(ZLIB_LIBRARIES ZLIB::ZLIB) ++ set(_protobuf_FIND_ZLIB "if(NOT ZLIB_FOUND AND NOT TARGET ZLIB::ZLIB)\n find_package(ZLIB REQUIRED)\nendif()") + endif (protobuf_WITH_ZLIB) + + # We need to link with libatomic on systems that do not have builtin atomics, or +@@ -279,7 +271,6 @@ else (MSVC) + endif (MSVC) + + include_directories( +- ${ZLIB_INCLUDE_DIRECTORIES} + ${protobuf_BINARY_DIR} + # Support #include-ing other top-level directories, i.e. upb_generator. + ${protobuf_SOURCE_DIR} diff --git a/patches/re2-2024-04-01.patch b/patches/re2-2024-04-01.patch new file mode 100644 index 0000000..73f73a6 --- /dev/null +++ b/patches/re2-2024-04-01.patch @@ -0,0 +1,18 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index bdac5af..cedaf6e 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -131,6 +131,13 @@ set(RE2_HEADERS + + add_library(re2 ${RE2_SOURCES}) + target_compile_features(re2 PUBLIC cxx_std_14) ++if(APPLE) ++ set_target_properties(re2 PROPERTIES ++ INSTALL_RPATH "@loader_path") ++elseif(UNIX) ++ set_target_properties(re2 PROPERTIES ++ INSTALL_RPATH "$ORIGIN") ++endif() + target_include_directories(re2 PUBLIC $) + # CMake gives "set_target_properties called with incorrect number of arguments." + # errors if we don't quote ${RE2_HEADERS}, so quote it despite prevailing style.