Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions .github/workflows/cpp-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: C++ Build and Test

on:
push:
branches: [ main, develop, 'copilot/**' ]
pull_request:
branches: [ main, develop ]

jobs:
build-linux:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake g++ ninja-build

- name: Cache CMake build
uses: actions/cache@v4
with:
path: |
build
~/.cache/CPM
key: ${{ runner.os }}-cmake-${{ hashFiles('CMakeLists.txt', 'tests/CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-cmake-

- name: Configure CMake
run: |
mkdir -p build
cd build
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release

- name: Build
run: |
cd build
ninja -j$(nproc)

- name: Run tests
run: |
cd build
ctest --output-on-failure --timeout 60

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-results-linux
path: build/Testing/Temporary/LastTest.log

build-macos:
runs-on: macos-latest

steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
brew install cmake ninja

- name: Cache CMake build
uses: actions/cache@v4
with:
path: |
build
~/Library/Caches/CPM
key: ${{ runner.os }}-cmake-${{ hashFiles('CMakeLists.txt', 'tests/CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-cmake-

- name: Configure CMake
run: |
mkdir -p build
cd build
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release

- name: Build
run: |
cd build
ninja -j$(sysctl -n hw.ncpu)

- name: Run tests
run: |
cd build
ctest --output-on-failure --timeout 60

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-results-macos
path: build/Testing/Temporary/LastTest.log

build-windows:
runs-on: windows-latest

steps:
- uses: actions/checkout@v4

- name: Setup MSVC
uses: ilammy/msvc-dev-cmd@v1

- name: Cache CMake build
uses: actions/cache@v4
with:
path: |
build
~\AppData\Local\CPM
key: ${{ runner.os }}-cmake-${{ hashFiles('CMakeLists.txt', 'tests/CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-cmake-

- name: Configure CMake
run: |
mkdir build
cd build
cmake .. -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=Release

- name: Build
run: |
cd build
cmake --build . --config Release -j

- name: Run tests
run: |
cd build
ctest -C Release --output-on-failure --timeout 60

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-results-windows
path: build/Testing/Temporary/LastTest.log
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,36 @@
*.pyc
*.pyo
*.lp

# C++ build artifacts
build/
cmake-build-*/
*.o
*.a
*.so
*.dylib
*.dll
*.exe
*.wasm
*.js
*.out

# CMake
CMakeCache.txt
CMakeFiles/
cmake_install.cmake
Makefile
*.cmake
!CMakeLists.txt
!CPM*.cmake

# IDE
.vscode/
.idea/
*.swp
*.swo
*~

# Dependencies
_deps/
.cache/
78 changes: 78 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
cmake_minimum_required(VERSION 3.20)
project(optimizer VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Download CPM.cmake
set(CPM_DOWNLOAD_VERSION 0.42.0)
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
endif()

include(${CPM_DOWNLOAD_LOCATION})

# Add GoogleTest
CPMAddPackage(
NAME googletest
GITHUB_REPOSITORY google/googletest
GIT_TAG v1.17.0
OPTIONS
"INSTALL_GTEST OFF"
"gtest_force_shared_crt ON"
)

# Add OR-Tools
CPMAddPackage(
NAME ortools
GITHUB_REPOSITORY google/or-tools
GIT_TAG v9.14
OPTIONS
"BUILD_DEPS ON"
"BUILD_SAMPLES OFF"
"BUILD_EXAMPLES OFF"
)

# Enable testing
enable_testing()
include(GoogleTest)

# Common include directory

# Collect all source files recursively from src directory
# Exclude main.cpp and wasm_bindings.cpp as they are entry points
file(GLOB_RECURSE SOURCES
"src/*.cpp"
)
list(FILTER SOURCES EXCLUDE REGEX "src/main\\.cpp$")
list(FILTER SOURCES EXCLUDE REGEX "src/wasm_bindings\\.cpp$")

# Create static library
add_library(liboptimizer STATIC)
target_sources(liboptimizer PRIVATE ${SOURCES})
target_include_directories(liboptimizer PUBLIC ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(liboptimizer PUBLIC ortools::ortools)
set_target_properties(liboptimizer PROPERTIES OUTPUT_NAME "optimizer")

# Executable target
add_executable(optimizer src/main.cpp)
target_link_libraries(optimizer PRIVATE liboptimizer)

# WebAssembly target
if(EMSCRIPTEN)
add_executable(optimizer_wasm src/wasm_bindings.cpp)
target_link_libraries(optimizer_wasm PRIVATE liboptimizer)
set_target_properties(optimizer_wasm PROPERTIES
LINK_FLAGS "-s WASM=1 -s EXPORTED_FUNCTIONS='[\"_optimize_build\"]' -s EXPORTED_RUNTIME_METHODS='[\"ccall\",\"cwrap\"]' -s MODULARIZE=1 -s EXPORT_NAME='TwOptimizerModule'"
)
endif()

# Tests
add_subdirectory(tests)
Loading
Loading