Skip to content

Commit

Permalink
Initial setup for isolated build
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkvdb committed Oct 3, 2023
1 parent 91c8e96 commit d38d443
Show file tree
Hide file tree
Showing 8 changed files with 349 additions and 8 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/vcpkg-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Vcpkg build

on: [push]

jobs:
build:
name: ${{ matrix.cfg.os }}
runs-on: ${{ matrix.cfg.os }}
strategy:
fail-fast: false
matrix:
cfg:
- { os: ubuntu-latest, triplet: x64-linux }
- { os: windows-2022, triplet: x64-windows-static-vs2022 }
- { os: macos-latest, triplet: x64-osx }

steps:
- name: Clone repository
uses: actions/checkout@v4
with:
submodules: true
- name: Install linux dependencies
if: ${{ matrix.cfg.os == 'ubuntu-latest' }}
run: sudo apt-get install nasm openssl ninja-build
- name: Install osx dependencies
if: ${{ matrix.cfg.os == 'macos-latest' }}
run: brew install nasm ninja
- name: Cache vcpkg binary
id: cache-vcpkg-bin
uses: actions/cache@v3
with:
path: |
deps/vcpkg/vcpkg
deps/vcpkg/vcpkg.exe
key: ${{ runner.os }}-${{ hashFiles('deps/vcpkg/bootstrap.cmake') }}
- name: Cache vcpkg packages
id: cache-vcpkg
uses: actions/cache@v3
with:
path: |
~/.cache/vcpkg
~/AppData/Local/vcpkg/archives
key: ${{ runner.os }}-${{ matrix.cfg.triplet }}-${{ hashFiles('vcpkg.json', '.git/modules/deps/vcpkg/shallow') }}
- name: Bootstrap the ports
run: python bootstrap.py --triplet ${{ matrix.cfg.triplet }} --clean-after-build
- name: Build the code
run: python build.py --triplet ${{ matrix.cfg.triplet }} --no-avx2 --python-path '${{ steps.setup-python.outputs.python-path }}' --run-tests
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.clangd
compile_commands.json
.DS_Store
vcpkg_installed
build
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "deps/vcpkg"]
path = deps/vcpkg
url = https://github.com/VITObelgium/vcpkg-ports.git
27 changes: 19 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,32 @@ include(CMakeDependentOption)
include(CMakePackageConfigHelpers)
include(CheckIncludeFileCXX)
include(CheckCXXSourceCompiles)
include(GNUInstallDirs)

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(INFRA_IS_TOPLEVEL ON)
endif()
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" INFRA_IS_TOPLEVEL)

if(INFRA_IS_TOPLEVEL)
cmake_minimum_required(VERSION 3.15)
cmake_minimum_required(VERSION 3.21)

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()

set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

project(Infra
VERSION 0.11.2
LANGUAGES CXX
)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)

include(GNUInstallDirs)
set (LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set (EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})

message(STATUS "Toplevel infra build C++${CMAKE_CXX_STANDARD}")
set(CMAKE_REQUIRED_FLAGS ${CMAKE_CXX17_STANDARD_COMPILE_OPTION})

# set(CMAKE_REQUIRED_FLAGS ${CMAKE_CXX17_STANDARD_COMPILE_OPTION})
if(MSVC OR(WIN32 AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "IntelLLVM"))
# avoid windows specific warnings
add_definitions(
Expand Down Expand Up @@ -347,7 +358,7 @@ if(INFRA_COMPRESSION)

if(INFRA_COMPRESSION_ZSTD)
find_package(zstd CONFIG REQUIRED)
target_link_libraries(infra PUBLIC libzstd)
target_link_libraries(infra PUBLIC $<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>)
target_compile_definitions(infra PUBLIC INFRA_COMPRESSION_ZSTD_SUPPORT ZSTD_STATIC_LINKING_ONLY)
endif()
endif()
Expand Down
70 changes: 70 additions & 0 deletions bootstrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env python3
import os
import sys
import sysconfig
import argparse

from deps.vcpkg.scripts.buildtools import vcpkg

if __name__ == "__main__":
try:
parser = argparse.ArgumentParser(
description="Bootstrap infra.", parents=[vcpkg.bootstrap_argparser()]
)

parser.add_argument(
"--cpp20",
dest="cpp20_enabled",
action="store_true",
help="build with C++20 support",
)

args = parser.parse_args()

platform = sysconfig.get_platform()
triplet = args.triplet
if platform == "win-amd64":
triplet = "x64-windows-static-vs2022"
elif platform == "mingw":
triplet = "x64-mingw"
elif not triplet:
triplet = vcpkg.prompt_for_triplet()

extras = []
features = [
"log",
"cliprogress",
"process",
"hashing",
"xml",
"numeric",
"charset",
"compression",
"gdal",
"db",
"testing",
]

if not args.cpp20_enabled:
features.append("cpp17")

build_root = None
packages_root = None

if args.clean:
vcpkg.clean(triplet=triplet)
else:
vcpkg.bootstrap(
ports_dir=os.path.join(".", "deps"),
triplet=triplet,
additional_ports=extras,
build_root=build_root,
packages_root=packages_root,
additional_features=features,
)
except KeyboardInterrupt:
print("\nInterrupted")
sys.exit(-1)
except RuntimeError as e:
print(e)
sys.exit(-1)
100 changes: 100 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/env python3
import os
import sys
import sysconfig
import platform
import argparse

from deps.vcpkg.scripts.buildtools import vcpkg

if __name__ == "__main__":
try:
parser = argparse.ArgumentParser(
description="Build infra.", parents=[vcpkg.build_argparser()]
)
parser.add_argument(
"--ui", dest="ui_enabled", action="store_true", help="build the ui"
)

parser.add_argument(
"--cpp20",
dest="cpp20_enabled",
action="store_true",
help="build with C++20 support",
)

parser.add_argument(
"--ci",
dest="ci_build",
action="store_true",
help="continuous integration build",
)

parser.add_argument(
"--build-config",
dest="build_config",
help="Build configuration (Debug or Release)",
default="Release",
)

args = parser.parse_args()

build_ui = "ON" if args.ui_enabled else "OFF"
cxx_standard = "17" if (args.cpp20_enabled) else "17"
sys_platform = sysconfig.get_platform()

triplet = args.triplet
if sys_platform == "win-amd64":
triplet = "x64-windows-static-vs2022"
elif sys_platform == "mingw":
triplet = "x64-mingw"
elif not triplet:
triplet = vcpkg.prompt_for_triplet()

cmake_args = [
f"-DCMAKE_CXX_STANDARD={cxx_standard}",
f"-DINFRA_UI_COMPONENTS={build_ui}",
"-DINFRA_LOGGING=ON",
"-DINFRA_GDAL=ON",
"-DINFRA_XML=ON",
"-DINFRA_TBB=ON",
"-DINFRA_NUMERIC=OFF",
"-DINFRA_CHARSET=ON",
"-DINFRA_PROCESS=ON",
"-DINFRA_DATABASE=ON",
"-DINFRA_DATABASE_SQLITE=ON",
"-DINFRA_DATABASE_POSTGRES=ON",
"-DINFRA_DATABASE_HASHING=ON",
"-DINFRA_COMPRESSION=ON",
"-DINFRA_COMPRESSION_ZSTD=ON",
"-DINFRA_ENABLE_TESTS=ON",
"-DINFRA_CLI_PROGRESS=ON",
]

if build_ui and triplet.startswith("x64-osx"):
cmake_args.extend(
[
"-DCMAKE_PREFIX_PATH=/usr/local/opt/qt6",
"-DVCPKG_ALLOW_SYSTEM_LIBS=ON",
]
)

targets = []
build_dir = "infra"

vcpkg.build_project(
os.path.abspath(args.source_dir),
triplet=triplet,
cmake_args=cmake_args,
targets=targets,
build_name=build_dir,
run_tests_after_build=args.run_tests,
test_arguments=args.test_args,
build_config=args.build_config,
)
except KeyboardInterrupt:
print("\nInterrupted")
sys.exit(-1)
except RuntimeError as e:
print(e)
sys.exit(-1)
1 change: 1 addition & 0 deletions deps/vcpkg
Submodule vcpkg added at 6a1e65
107 changes: 107 additions & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"name": "infra",
"version": "0.11.2",
"dependencies": [
"fmt"
],
"features": {
"log": {
"description": "logging support",
"dependencies": [
"spdlog"
]
},
"testing": {
"description": "unit test support",
"dependencies": [
"doctest",
"trompeloeil"
]
},
"cliprogress": {
"description": "progress support",
"dependencies": [
"indicators"
]
},
"process": {
"description": "process support",
"dependencies": [
"reproc"
]
},
"hashing": {
"description": "hashing support",
"dependencies": [
"cryptopp"
]
},
"xml": {
"description": "xml support",
"dependencies": [
"pugixml"
]
},
"tbb": {
"description": "threading building blocks support",
"dependencies": [
"tbb"
]
},
"numeric": {
"description": "numeric support",
"dependencies": [
"eigen3"
]
},
"charset": {
"description": "charset conversion/detection support",
"dependencies": [
"icu"
]
},
"compression": {
"description": "compression support",
"dependencies": [
"zstd"
]
},
"gdal": {
"description": "gdal support",
"dependencies": [
{
"name": "gdal",
"features": [
"geos"
]
}
]
},
"db": {
"description": "database support",
"dependencies": [
{
"name": "sqlpp11",
"features": [
"sqlite",
"postgresql"
]
}
]
},
"cpp17": {
"description": "C++17 build",
"dependencies": [
"date",
"gsl"
]
},
"ui": {
"description": "ui support",
"dependencies": [
"qt6"
]
}
}
}

0 comments on commit d38d443

Please sign in to comment.