cmake-build

[![Build](https://github.com/eliasku/cmake-build/actions/workflows/build.yml/badge.svg)](https://github.com/eliasku/cmake-build/actions/workflows/build.yml) [![Version](https://img.shields.io/npm/v/cmake-build)](https://www.npmjs.com/package/cmake-build)

Usage no npm install needed!

<script type="module">
  import cmakeBuild from 'https://cdn.skypack.dev/cmake-build';
</script>

README

cmake-build

Build Version Downloads

Utility for configuring and building CMake projects with NPM packages support. Basic cross-compile features are provided (building for another system from a host system).

CMake NPM packages

Link CMake projects installed from NPM packages

include(npm.cmake)
  • Add cmake-build to your package.json in dependencies section (not devDependencies because we want to resolve dependencies after install automatically)
  • Add include(npm.cmake) to the beginning of your CMakeLists.txt
  • Run npx cmake-build to generate configuration module npm.cmake with resolved NPM dependencies

Package name convention

  • Scoped NPM package name @scope/package-name transforms to CMake target scope::package-name
  • Packages without scope is not transform

Cross-compile

Status

  • MacOS
    • Android
    • WebAssembly
    • iOS
    • macOS
    • Windows (Mingw)
    • Linux (Docker)
  • Windows
  • Linux

Requirements

macOS

Install Mingw for building Windows platform.

brew install mingw-w64

Install docker and follow guides how to build from images.

IDE

It's very hard to fix platform-side code inside generated projects (XCode, Android Studio), so we able to switch platform inside your cmake-compatible IDE (like CLion).

  1. Create Debug-Emscripten
  2. Set the path to CMake Emscripten Toolchain
# Emscripten
-DCMAKE_TOOLCHAIN_FILE=/Users/PATH_TO_emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake

# iOS (https://github.com/leetal/ios-cmake/blob/master/ios.toolchain.cmake)
-DPLATFORM=SIMULATOR64 -DCMAKE_TOOLCHAIN_FILE=./cmake/ios.cmake

# Android
-DANDROID_ABI=x86_64 -DCMAKE_TOOLCHAIN_FILE=/Users/USER/Library/Android/sdk/ndk/23.0.7599858/build/cmake/android.toolchain.cmake

# Windows from MacOS
brew install mingw-w64
-DCMAKE_TOOLCHAIN_FILE=./cmake/mingw-w64-x86_64.cmake

Docker

Docker files for cross-platform building

# build docker image for linux build
cd images/linux
docker build -t eliasku/ubuntu:1.0 .

# run docker in your current project dir
cd your/project/path
docker run -it --mount type=bind,source=$(pwd),target=/mnt eliasku/ubuntu:1.0 /bin/sh -c "cd /mnt && bash"