Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e847366
corrected version-check
petergjoel Dec 28, 2023
d164472
Merge branch 'main' into fixing_version_check
mikucionisaau May 11, 2026
5e0266c
updated build scripts
mikucionisaau May 11, 2026
ef835a6
Fixed cmake build scripts to fetch latest boost
mikucionisaau May 11, 2026
dc412fb
Merge remote-tracking branch 'gh/update-build' into fixing_version_check
mikucionisaau May 11, 2026
ec6d69c
Fixed CMake installation script
mikucionisaau May 11, 2026
e288f73
Fixed library build scripts, added usage example
mikucionisaau May 11, 2026
ff83ab6
Fixed missing nlohmann_json include path for strategy and strategySta…
mikucionisaau Jun 30, 2026
714f339
Fixed README inaccuracies and example ctest registration
mikucionisaau Jun 30, 2026
5c155ff
Removed nlohmann_json from public headers and fixed install interface
mikucionisaau Jun 30, 2026
b74c356
Fixed CMake install: include dirs, missing headers, visibility, stati…
mikucionisaau Jun 30, 2026
eee9409
Add MinGW-w64 cross-compilation toolchain for Windows x86-64
mikucionisaau Jun 30, 2026
ce54514
Fix Boost component targets missing when system Boost is found via Bo…
mikucionisaau Jul 1, 2026
edf76d0
Fix DLL-not-found crash for tests on Windows (0xc0000135)
mikucionisaau Jul 1, 2026
7484e7c
Upgraded ptrie to 1.1.3 which has a lot of quality fixes
mikucionisaau Jul 1, 2026
c6391de
Replace boost::program_options with custom CLI parsing in main.cpp
mikucionisaau Jul 1, 2026
1861172
Converted Boost.Test into Doctest and removed dependency for Boost
mikucionisaau Jul 1, 2026
fd598b5
Added compiler warnings and fixed some, renamed node_t to Node
mikucionisaau Jul 1, 2026
7940134
Fix to_double for AppleClang missing floating-point std::from_chars
mikucionisaau Jul 1, 2026
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
20 changes: 8 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
cmake_minimum_required(VERSION 3.28)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.30.0")
cmake_policy(SET CMP0167 NEW) # use FindBoost from boost installation (as opposed to CMake own)
endif ()
project(libstrategy VERSION 1.0.9 LANGUAGES CXX C)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

include(cmake/warnings.cmake)
include(cmake/sanitizers.cmake)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")

option(LIBSTRATEGY_TESTS "libstrategy Unit Tests" ON)
option(LIBSTRATEGY_OnlyLibrary "Build only the library (no binary utilities)" OFF)

include(cmake/ptrie.cmake)
include(cmake/warnings.cmake)
include(cmake/sanitizers.cmake)
include(cmake/nlohmann_json.cmake)
include(cmake/ptrie.cmake)

if(NOT LIBSTRATEGY_OnlyLibrary)
cmake_policy(SET CMP0069 NEW) # INTERPROCEDURAL_OPTIMIZATIONS flags
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.30.0")
cmake_policy(SET CMP0167 NEW) # use FindBoost from boost installation (as opposed to CMake own)
endif ()
find_package(Boost 1.83 COMPONENTS program_options REQUIRED)
endif()

add_subdirectory(src)

if (LIBSTRATEGY_TESTS)
include(cmake/doctest.cmake)
enable_testing()
add_subdirectory(test)
endif()
94 changes: 81 additions & 13 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,115 @@
"include": ["cmake/CommonPresets.json"],
"configurePresets": [
{
"name": "libonly",
"name": "quick",
"inherits": "multi",
"binaryDir": "${sourceDir}/build-libonly",
"binaryDir": "${sourceDir}/build-quick",
"cacheVariables": {
"LIBSTRATEGY_TESTS": "OFF" ,
"LIBSTRATEGY_OnlyLibrary": "ON"
},
"displayName": "Configure Library-Only for Debug and Release"
"displayName": "Configure quick build (no utilities, no testing) for Debug and Release"
},
{
"name": "quick-san",
"inherits": "multi-san",
"binaryDir": "${sourceDir}/build-quick-san",
"cacheVariables": {
"LIBSTRATEGY_TESTS": "OFF" ,
"LIBSTRATEGY_OnlyLibrary": "ON"
},
"displayName": "Configure quick build (no utilities, no testing) with Sanitizers for Debug and Release"
}
],
"buildPresets": [
{
"name": "libonly-release",
"name": "quick-release",
"inherits": "release",
"configurePreset": "libonly",
"configurePreset": "quick",
"displayName": "Build Library-Only for Release"
},
{
"name": "quick-debug",
"inherits": "debug",
"configurePreset": "quick",
"displayName": "Build Library-Only for Debug"
},
{
"name": "libonly-debug",
"name": "quick-san-release",
"inherits": "release",
"configurePreset": "quick-san",
"displayName": "Build Library-Only with Sanitizers for Release"
},
{
"name": "quick-san-debug",
"inherits": "debug",
"configurePreset": "libonly",
"displayName": "Build Library-Only for Release"
"configurePreset": "quick-san",
"displayName": "Build Library-Only with Sanitizers for Debug"
}
],
"testPresets": [],
"workflowPresets": [
{
"name": "libonly",
"displayName": "Configure and Build Library-Only for Debug and Release (no testing)",
"name": "quick",
"displayName": "Configure and Build Library-Only (no testing) for Debug and Release",
"steps": [
{
"type": "configure",
"name": "libonly"
"name": "quick"
},
{
"type": "build",
"name": "quick-release"
},
{
"type": "build",
"name": "libonly-release"
"name": "quick-debug"
}
]
},
{
"name": "quick-release",
"displayName": "Configure and Build Library-Only (no testing) for Release",
"steps": [
{
"type": "configure",
"name": "quick"
},
{
"type": "build",
"name": "quick-release"
}
]
},
{
"name": "quick-san",
"displayName": "Configure and Build Library-Only (no testing) with Sanitizers for Debug and Release",
"steps": [
{
"type": "configure",
"name": "quick-san"
},
{
"type": "build",
"name": "quick-san-release"
},
{
"type": "build",
"name": "quick-san-debug"
}
]
},
{
"name": "quick-san-release",
"displayName": "Configure and Build Library-Only (no testing) for Release",
"steps": [
{
"type": "configure",
"name": "quick-san"
},
{
"type": "build",
"name": "libonly-debug"
"name": "quick-san-release"
}
]
}
Expand Down
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,36 @@ Full project requires:

For Ubuntu 24.04 install build tools and library dependencies:
```shell
sudo apt install cmake ninja-build g++ libboost-program-options-dev libboost-test-dev
sudo apt install cmake ninja-build g++
sudo apt install libboost-program-options-dev libboost-test-dev # optional
```

For macOS install build tools and library dependencies:
```shell
brew install cmake ninja boost
brew install cmake ninja gcc
brew install boost # optional
```

## Compile and Install
Run minimal compilation (just the library) with `Debug` and `Release` settings into `build-libonly/lib`:
Run minimal compilation (just the library) with `Release` settings into `build-quick/lib`:
```shell
cmake --workflow libonly
cmake --workflow --preset quick-release
```
Install the `Release` build of `build-libonly` into `$PWD/local` path:
Install the `Release` build of `build-quick` into `$PWD/local` path:
```shell
cmake --install build-libonly --config Release --prefix $PWD/local
cmake --install build-quick --config Release --prefix $PWD/local
```

## Example Usage
Directory [example](example) contains minimal example demonstrating how to use the library.

Test the example with libstrategy installed into [local](local) directory:
```shell
cmake -S example -B build-example -DCMAKE_PREFIX_PATH=$PWD/local -DCMAKE_MODULE_PATH=$PWD/cmake
```
```shell
cmake --build build-example
ctest --test-dir build-example --output-on-failure
```

## Other Presets
Expand All @@ -39,7 +53,7 @@ cmake --workflow --list-presets

For example, configure, build and **test** for Development with **Sanitizers** (GCC/Clang/AppleClang):
```shell
cmake --workflow debug-san
cmake --workflow --preset debug-san
```

Other configuration presets:
Expand Down
33 changes: 33 additions & 0 deletions cmake/boost.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#set(FETCHCONTENT_QUIET ON)
#set(FETCHCONTENT_UPDATES_DISCONNECTED ON)
include(FetchContent)
FetchContent_Declare(Boost
# URL https://github.com/boostorg/boost/releases/download/boost-1.91.0-1/boost-1.91.0-1-cmake.7z
URL https://people.cs.aau.dk/~marius/mirrors/boost/boost-1.91.0-1-cmake.7z
URL_HASH SHA256=29c7d4f4ac36ad853b6765d03571ea60d90286775df026b4efd9f3281131972b
#GIT_REPOSITORY https://github.com/boostorg/boost.git
#GIT_TAG boost-1.91.0-1
#GIT_SHALLOW TRUE # download specific revision only (git clone --depth 1)
#GIT_PROGRESS TRUE # show download progress in Ninja
USES_TERMINAL_DOWNLOAD TRUE
EXCLUDE_FROM_ALL # don't build if not used
FIND_PACKAGE_ARGS 1.91.0 COMPONENTS unit_test_framework)

set(BOOST_ENABLE_MPI OFF CACHE BOOL "Boost.MPI and its dependents (requires MPI, CMake 3.10)")
set(BOOST_ENABLE_PYTHON OFF CACHE BOOL "Boost.Python and its dependents (requires Python, CMake 3.14)")
set(BUILD_TESTING OFF CACHE BOOL "Build the tests.")
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries")


FetchContent_MakeAvailable(Boost)

if (Boost_FOUND) # find_package
message(STATUS "Found Boost: ${Boost_INCLUDE_DIRS}")
else (Boost_program_options_FOUND) # fetch_content
message(STATUS "Got Boost: ${Boost_SOURCE_DIR}")
endif (Boost_FOUND)

if (TARGET Boost::unit_test_framework)
message(STATUS " Available target: Boost::unit_test_framework")
endif ()

33 changes: 33 additions & 0 deletions cmake/doctest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Downloads and compiles DocTest unit testing framework
include(FetchContent)
#set(FETCHCONTENT_QUIET ON)
#set(FETCHCONTENT_UPDATES_DISCONNECTED ON)

FetchContent_Declare(doctest
GIT_REPOSITORY https://github.com/doctest/doctest.git
GIT_TAG v2.5.2 # "main" for latest
GIT_SHALLOW TRUE # download specific revision only (git clone --depth 1)
GIT_PROGRESS TRUE # show download progress in Ninja
EXCLUDE_FROM_ALL ON # don't build if not used
FIND_PACKAGE_ARGS 2.4.12)

set(DOCTEST_WITH_TESTS OFF CACHE BOOL "Build tests/examples")
set(DOCTEST_WITH_MAIN_IN_STATIC_LIB ON CACHE BOOL "Build a static lib for doctest::doctest_with_main")
set(DOCTEST_NO_INSTALL OFF CACHE BOOL "Skip the installation process")
set(DOCTEST_USE_STD_HEADERS OFF CACHE BOOL "Use std headers")

FetchContent_MakeAvailable(doctest)

if(doctest_FOUND) # find_package
message(STATUS "Found doctest: ${doctest_DIR}")
else(doctest_FOUND) # FetchContent
message(STATUS "Fetched doctest: ${doctest_SOURCE_DIR}")
endif(doctest_FOUND)

if (TARGET doctest::doctest)
message(STATUS " Available target: doctest::doctest")
endif ()

if (TARGET doctest::doctest_with_main)
message(STATUS " Available target: doctest::doctest_with_main")
endif ()
26 changes: 26 additions & 0 deletions cmake/libstrategy.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
include(FetchContent)
FetchContent_Declare(libstrategy
GIT_REPOSITORY https://github.com/DEIS-Tools/libstrategy
GIT_TAG fixing_version_check
GIT_SHALLOW TRUE # download specific revision only (git clone --depth 1)
GIT_PROGRESS TRUE # show download progress in Ninja
USES_TERMINAL_DOWNLOAD TRUE
EXCLUDE_FROM_ALL # don't build if not used
FIND_PACKAGE_ARGS 1.0.9)

set(LIBSTRATEGY_TESTS OFF CACHE BOOL "libstrategy Unit Tests")
set(LIBSTRATEGY_OnlyLibrary ON CACHE BOOL "Build only the library (no binary utilities)")
FetchContent_MakeAvailable(libstrategy)

if (libstrategy_FOUND) # find_package
message(STATUS "Found libstrategy: ${libstrategy_DIR}")
else (libstrategy_FOUND) # fetch_content
message(STATUS "Fetched libstrategy: ${libstrategy_SOURCE_DIR}")
endif (libstrategy_FOUND)

if (TARGET libstrategy::strategy)
message(STATUS " Available target: libstrategy::strategy")
endif ()
if (TARGET libstrategy::strategyStatic)
message(STATUS " Available target: libstrategy::strategyStatic")
endif ()
12 changes: 12 additions & 0 deletions cmake/mingw-w64-x86_64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x86_64)

set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)

set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
5 changes: 2 additions & 3 deletions cmake/nlohmann_json.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ FetchContent_Declare(nlohmann_json
GIT_SHALLOW TRUE # download specific revision only (git clone --depth 1)
GIT_PROGRESS TRUE # show download progress in Ninja
USES_TERMINAL_DOWNLOAD TRUE
EXCLUDE_FROM_ALL # don't build if not used
FIND_PACKAGE_ARGS 3.12.0)

set(NLOHMANN_JSON_BUILD_MODULES OFF CACHE BOOL "Build C++ modules support")
Expand All @@ -25,11 +26,9 @@ set(JSON_MultipleHeaders ON CACHE BOOL "Use non-amalgamated version
set(JSON_SystemInclude OFF CACHE BOOL "Include as system headers (skip for clang-tidy).")

FetchContent_MakeAvailable(nlohmann_json)
message(STATUS "Got nlohmann_json: ${nlohmann_json_SOURCE_DIR}")

if (nlohmann_json_FOUND) # find_package
get_target_property(nlohmann_json_INCLUDE_DIRS nlohmann_json::nlohmann_json INTERFACE_INCLUDE_DIRECTORIES)
message(STATUS "Found nlohmann_json: ${nlohmann_json_INCLUDE_DIRS}")
message(STATUS "Found nlohmann_json: ${nlohmann_json_DIRS}")
else (nlohmann_json_FOUND) # FetchContent
message(STATUS "Fetched nlohmann_json: ${nlohmann_json_SOURCE_DIR}")
endif (nlohmann_json_FOUND)
Expand Down
16 changes: 9 additions & 7 deletions cmake/ptrie.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@
include(FetchContent)
FetchContent_Declare(ptrie
GIT_REPOSITORY https://github.com/DEIS-Tools/ptrie
GIT_TAG v1.1.2
GIT_TAG v1.1.3
GIT_SHALLOW TRUE # download specific revision only (git clone --depth 1)
GIT_PROGRESS TRUE # show download progress in Ninja
USES_TERMINAL_DOWNLOAD TRUE
FIND_PACKAGE_ARGS 1.1.2)
EXCLUDE_FROM_ALL # don't build if not used
FIND_PACKAGE_ARGS 1.1.3)

set(PTRIE_BuildTests OFF CACHE BOOL "Build the unit tests when BUILD_TESTING is enabled.")
set(PTRIE_BuildBenchmark OFF CACHE BOOL "Build the simple benchmark suite")
FetchContent_MakeAvailable(ptrie)

if (ptrie_FOUND) # find_package
get_target_property(ptrie_INCLUDE_DIRS ptrie::ptrie INTERFACE_INCLUDE_DIRECTORIES)
message(STATUS "Found ptrie: ${ptrie_INCLUDE_DIRS}")
message(STATUS "Found ptrie: ${ptrie_DIR}")
else (ptrie_FOUND) # fetch_content
message(STATUS "Got ptrie: ${ptrie_SOURCE_DIR}")
message(STATUS "Fetched ptrie: ${ptrie_SOURCE_DIR}")
# Workaround until ptrie exports proper cmake config:
add_library(ptrie::ptrie INTERFACE IMPORTED GLOBAL)
target_include_directories(ptrie::ptrie INTERFACE ${ptrie_SOURCE_DIR}/src)
if (NOT TARGET ptrie::ptrie)
add_library(ptrie::ptrie INTERFACE IMPORTED GLOBAL)
target_include_directories(ptrie::ptrie INTERFACE ${ptrie_SOURCE_DIR}/src)
endif()
endif (ptrie_FOUND)

if (TARGET ptrie::ptrie)
Expand Down
Loading
Loading