Skip to content

Add CMake build system and cross-platform compatibility#5

Open
keisuke-ishihara wants to merge 4 commits intomorphometry:masterfrom
keisuke-ishihara:crossplatform
Open

Add CMake build system and cross-platform compatibility#5
keisuke-ishihara wants to merge 4 commits intomorphometry:masterfrom
keisuke-ishihara:crossplatform

Conversation

@keisuke-ishihara
Copy link

Summary

  • Add CMake build system (CMakeLists.txt, vcpkg.json) for cross-platform builds
  • Fix MSVC compatibility: remove default arguments from explicit template instantiations, add _USE_MATH_DEFINES for M_PI
  • Fix cross-platform source issues: replace POSIX mkdir() with std::filesystem::create_directories(), replace and alternative token with &&, add missing <sstream> include, fix arm64 debug trap in Catch
  • Add GitHub Actions CI workflow (Linux, macOS, Windows)

Tested on

  • macOS (Make)
  • Windows MinGW (Make)
  • Windows MSVC (CMake)

Test plan

  • Build with cmake -B build && cmake --build build or existing make
  • Run tests with ctest --test-dir build or make test
  • Verify existing Makefile workflow is unchanged

🤖 Generated with Claude Code

keisuke-ishihara and others added 3 commits February 14, 2026 11:20
Replace POSIX mkdir() with std::filesystem::create_directories() and
fix platform-specific issues (MSVC alternative tokens, arm64 debug trap,
missing <sstream> include) to enable building on Windows, macOS arm64,
and Linux. Add GitHub Actions CI workflow and vcpkg manifest.

Tested: builds and passes all tests on macOS arm64 (Apple Silicon).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Build and tests confirmed successful on Windows with make using MINGW64.
This flag is a no-op on macOS/Linux where M_PI is already defined.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… MSVC build

MSVC (C2765) disallows default arguments on explicit template instantiations.
The defaults are already declared in the header (calculate_wxxx.h), so removing
them from the .cpp instantiations is standards-compliant and cross-platform.
Tested with Windows+CMake (MSVC), MinGW, and macOS builds.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@keisuke-ishihara
Copy link
Author

hi, thanks for creating this package. We are using it for our research and it's been very useful!
We've had to tweak the original files occasionally to install on MacOS arm64 and our Windows machine.
I took the opportunity to use Claude Code and make the package easier to install across all platforms.

Copy link
Contributor

@skapfer skapfer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the pull request! It looks pretty good, some small changes might be in order.

Makefile Outdated
CXX = g++

CXXFLAGS = -Wall -O2 -DNDEBUG #-ansi
CXXFLAGS = -std=c++17 -Wall -O2 -DNDEBUG -D_USE_MATH_DEFINES #-ansi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a more portable fix and include this after the <cmath> include?

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

Copy link
Author

@keisuke-ishihara keisuke-ishihara Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I removed -D_USE_MATH_DEFINES from both Makefile and CMakeLists.txt, and added #ifndef M_PI after <math.h> in each file that uses it.


static
void throw_error (const std::string &message, ...) {
void throw_error (const std::string message, ...) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this need to change?

Copy link
Author

@keisuke-ishihara keisuke-ishihara Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is needed for MSVC compatibility. Per the C++ standard, passing a reference as the last named parameter before ... and then using it in va_start is undefined behavior — MSVC rejects it with an error. Passing by value avoids this.

#ifdef CATCH_PLATFORM_MAC

#define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */
#if defined(__aarch64__)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should look into upgrading catch :-)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! The arm64 fix in this PR is just a minimal workaround to unblock macOS arm64 users with the existing single-header Catch v1. Upgrading to Catch2 would be a cleaner long-term solution — happy to do that in a follow-up PR if you'd like.

vcpkg.json Outdated
@@ -0,0 +1,7 @@
{
"name": "karambola",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems VC specific? Can we remove it?

Copy link
Author

@keisuke-ishihara keisuke-ishihara Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. I used vckpkg to install GSL but this did not have to be part of the PR.

- Replace -D_USE_MATH_DEFINES compiler flag with #ifndef M_PI guard
  in each source file after <math.h>, per reviewer suggestion
- Remove vcpkg.json (MSVC-specific, not needed for cross-platform build)
- Remove _USE_MATH_DEFINES from CMakeLists.txt (no longer needed)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments