Skip to content

Commit

Permalink
Merge pull request #1 from martinjankoehler/cmake-build
Browse files Browse the repository at this point in the history
CMake based workflow
  • Loading branch information
martinjankoehler authored Dec 2, 2024
2 parents c7343e3 + c103444 commit d1195ec
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 3 deletions.
92 changes: 92 additions & 0 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml
name: CMake on multiple platforms

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false

# Set up a matrix to run the following 3 configurations:
# 1. <Windows, Release, latest MSVC compiler toolchain on the default runner image, default generator>
# 2. <Linux, Release, latest GCC compiler toolchain on the default runner image, default generator>
# 3. <Linux, Release, latest Clang compiler toolchain on the default runner image, default generator>
#
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
build_type: [RelWithDebInfo]
c_compiler: [clang, cl]
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
- os: macos-latest
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: windows-latest
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl
- os: ubuntu-latest
c_compiler: gcc
- os: macos-latest
c_compiler: gcc
- os: macos-latest
c_compiler: cl

steps:
- uses: actions/checkout@v4

- name: [C++] Ccache for gh actions
uses: hendrikmuhs/[email protected]
with:
key: ${{ github.job }}-${{ matrix.os }} # Eg. "some_build-ubuntu-latest"

- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs.
# These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: [C++] Configure CMake
# Configure CMake in a 'build' subdirectory.
# `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER_LAUNCHER=ccache
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
-S ${{ github.workspace }}
- name: [C++] Build
# Build your program with the given configuration.
# Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}

- name: [C++] Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
# Execute tests defined by the CMake configuration.
# Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --build-config ${{ matrix.build_type }}
28 changes: 25 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,34 @@ SPDX-License-Identifier: GPL-3.0-or-later
cmake_minimum_required (VERSION 3.12)
project (kpex)

set(CMAKE_CXX_STANDARD 23)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest")
endif(MSVC)

#_____________________________________________________________________________________________

# see https://github.com/protocolbuffers/protobuf/blob/main/docs/cmake_protobuf_generate.md
# add dependencies
include(cmake/CPM.cmake)
CPMAddPackage(
NAME protobuf
GIT_TAG v29.0
GIT_REPOSITORY "https://github.com/protocolbuffers/protobuf.git"
OPTIONS
"protobuf_INSTALL OFF"
"protobuf_BUILD_TESTS OFF"
"protobuf_BUILD_SHARED_LIBS OFF"
"protobuf_BUILD_EXAMPLES OFF"
"ABSL_PROPAGATE_CXX_STD ON"
)

find_package(protobuf CONFIG REQUIRED)
#_____________________________________________________________________________________________

# see https://github.com/protocolbuffers/protobuf/blob/main/docs/cmake_protobuf_generate.md
include(${protobuf_SOURCE_DIR}/cmake/protobuf-generate.cmake)
set(Protobuf_INCLUDE_DIRS ${protobuf_SOURCE_DIR}/src)

set(PROTOBUF_SOURCES
set(PROTOBUF_SOURCES
${CMAKE_CURRENT_LIST_DIR}/protos/tech.proto
${CMAKE_CURRENT_LIST_DIR}/protos/process_stack.proto
${CMAKE_CURRENT_LIST_DIR}/protos/process_parasitics.proto
Expand Down Expand Up @@ -75,6 +96,7 @@ set(GEN_TECH_PB_SOURCES
${CMAKE_CURRENT_LIST_DIR}/cxx/gen_tech_pb/main.cpp
)
add_executable(gen_tech_pb ${GEN_TECH_PB_SOURCES})
target_include_directories(gen_tech_pb PUBLIC ${Protobuf_INCLUDE_DIRS})
target_link_libraries(gen_tech_pb kpex-protobuf)

#_____________________________________________________________________________________________
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
### Prerequisites

- cmake
- NOTE: `cmake/CPM.cmake` will handle C++ dependencies
- protobuf
- python3 with pip packages:
- poetry (will manage additional dependencies)
Expand Down Expand Up @@ -81,3 +82,12 @@ To quickly run a PEX example with KPEX/2.5D and KPEX/FasterCap engines:
In your debugging configuration, set:
- `Modify Options` > `Emulate terminal in output console`
- Add environmental variable `COLUMNS=120`

## Credits

**Thanks to**

- [Protocol Buffers](https://github.com/protocolbuffers/protobuf) for (de)serialization of data and shared data
structures
- [CMake](https://cmake.org/), for building on multiple platforms
- [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) for making CMake dependency management easier
24 changes: 24 additions & 0 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors

set(CPM_DOWNLOAD_VERSION 0.40.2)
set(CPM_HASH_SUM "c8cdc32c03816538ce22781ed72964dc864b2a34a310d3b7104812a5ca2d835d")

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
)

include(${CPM_DOWNLOAD_LOCATION})

0 comments on commit d1195ec

Please sign in to comment.