Git Product home page Git Product logo

cmake-js's Introduction

CMake.js (MIT)

Node CI npm

About

CMake.js is a Node.js native addon build tool which works (almost) exactly like node-gyp, but instead of gyp, it is based on CMake build system. It's compatible with the following runtimes:

  • Node.js 14.15+ since CMake.js v7.0.0 (for older runtimes please use an earlier version of CMake.js). Newer versions can produce builds targeting older runtimes
  • NW.js: all CMake.js based native modules are compatible with NW.js out-of-the-box, there is no nw-gyp like magic required
  • Electron: out-of-the-box build support, no post build steps required

If you use node-api for your module instead of nan it should be able to run on all the runtimes above without needing to be built separately for each.

Installation

npm install cmake-js

Help:

cmake-js --help
Usage: cmake-js [<command>] [options]

Commands:
  cmake-js install                Install Node.js distribution files if needed
  cmake-js configure              Configure CMake project
  cmake-js print-configure        Print the configuration command
  cmake-js print-cmakejs-src      Print the value of the CMAKE_JS_SRC variable
  cmake-js print-cmakejs-include  Print the value of the CMAKE_JS_INC variable
  cmake-js print-cmakejs-lib      Print the value of the CMAKE_JS_LIB variable
  cmake-js build                  Build the project (will configure first if
                                  required)
  cmake-js print-build            Print the build command
  cmake-js clean                  Clean the project directory
  cmake-js print-clean            Print the clean command
  cmake-js reconfigure            Clean the project directory then configure the
                                  project
  cmake-js rebuild                Clean the project directory then build the
                                  project
  cmake-js compile                Build the project, and if build fails, try a
                                  full rebuild

Options:
      --version          Show version number                           [boolean]
  -h, --help             Show help                                     [boolean]
  -l, --log-level        set log level (silly, verbose, info, http, warn,
                         error), default is info                        [string]
  -d, --directory        specify CMake project's directory (where CMakeLists.txt
                         located)                                       [string]
  -D, --debug            build debug configuration                     [boolean]
  -B, --config           specify build configuration (Debug, RelWithDebInfo,
                         Release), will ignore '--debug' if specified   [string]
  -c, --cmake-path       path of CMake executable                       [string]
  -m, --prefer-make      use Unix Makefiles even if Ninja is available (Posix)
                                                                       [boolean]
  -x, --prefer-xcode     use Xcode instead of Unix Makefiles           [boolean]
  -g, --prefer-gnu       use GNU compiler instead of default CMake compiler, if
                         available (Posix)                             [boolean]
  -G, --generator        use specified generator                        [string]
  -t, --toolset          use specified toolset                          [string]
  -A, --platform         use specified platform name                    [string]
  -T, --target           only build the specified target                [string]
  -C, --prefer-clang     use Clang compiler instead of default CMake compiler,
                         if available (Posix)                          [boolean]
      --cc               use the specified C compiler                   [string]
      --cxx              use the specified C++ compiler                 [string]
  -r, --runtime          the runtime to use                             [string]
  -v, --runtime-version  the runtime version to use                     [string]
  -a, --arch             the architecture to build in                   [string]
  -p, --parallel         the number of threads cmake can use            [number]
      --CD               Custom argument passed to CMake in format:
                         -D<your-arg-here>                              [string]
  -i, --silent           Prevents CMake.js to print to the stdio       [boolean]
  -O, --out              Specify the output directory to compile to, default is
                         projectRoot/build                              [string]

Requirements:

  • CMake
  • A proper C/C++ compiler toolchain of the given platform
    • Windows:
      • Visual C++ Build Tools. If you installed nodejs with the installer, you can install these when prompted.
      • An alternate way is to install the Chocolatey package manager, and run choco install visualstudio2017-workload-vctools in an Administrator Powershell
      • If you have multiple versions installed, you can select a specific version with npm config set msvs_version 2017 (Note: this will also affect node-gyp)
    • Unix/Posix:
      • Clang or GCC
      • Ninja or Make (Ninja will be picked if both present)

Usage

General

It is advised to use Node-API for new projects instead of NAN. It provides ABI stability making usage simpler and reducing maintainance.

In a nutshell. (For more complete documentation please see the first tutorial.)

  • Install cmake-js for your module npm install --save cmake-js
  • Put a CMakeLists.txt file into your module root with this minimal required content:
cmake_minimum_required(VERSION 3.15)
cmake_policy(SET CMP0091 NEW)
cmake_policy(SET CMP0042 NEW)

project (your-addon-name-here)

add_definitions(-DNAPI_VERSION=4)

include_directories(${CMAKE_JS_INC})

file(GLOB SOURCE_FILES "your-source files-location-here")

add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})

if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET)
  # Generate node.lib
  execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS})
endif()
  • Add the following into your package.json scripts section:
"scripts": {
    "install": "cmake-js compile"
  }
  • Add the following into your package.json, using the same NAPI_VERSION value you provided to cmake
"binary": {
    "napi_versions": [7]
  },

Commandline

With cmake-js installed as a depdendency or devDependency of your module, you can access run commands directly with:

npx cmake-js --help
# OR
yarn cmake-js --help

Please refer to the --help for the lists of available commands (they are like commands in node-gyp).

You can override the project default runtimes via --runtime and --runtime-version, such as: --runtime=electron --runtime-version=0.26.0. See below for more info on runtimes.

CMake Specific

CMAKE_JS_VERSION variable will reflect the actual CMake.js version. So CMake.js based builds could be detected, eg.:

if (CMAKE_JS_VERSION)
    add_subdirectory(node_addon)
else()
    add_subdirectory(other_subproject)
endif()

NPM Config Integration

You can set npm configuration options for CMake.js.

For all users (global):

npm config set cmake_<key> <value> --global

For current user:

npm config set cmake_<key> <value>

CMake.js will set a variable named "<key>" to <value> (by using -D<key>="<value>" option). User settings will overwrite globals.

UPDATE:

You can set CMake.js command line arguments with npm config using the following pattern:

npm config set cmake_js_G "Visual Studio 56 Win128"

Which sets the CMake generator, basically defaults to:

cmake-js -G "Visual Studio 56 Win128"

Example:

Enter at command prompt:

npm config set cmake_Foo="bar"

Then write to your CMakeLists.txt the following:

message (STATUS ${Foo})

This will print during configure:

--- bar

Custom CMake options

You can add custom CMake options by beginning option name with CD.

Example

In command prompt:

cmake-js compile --CDFOO="bar"

Then in your CMakeLists.txt:

message (STATUS ${FOO})

This will print during configure:

--- bar

Runtimes

Important

It is important to understand that this setting is to be configured in the application's root package.json file. If you're creating a native module targeting nw.js for example, then do not specify anything in your module's package.json. It's the actual application's decision to specify its runtime, your module's just compatible anything that was mentioned in the About chapter. Actually defining cmake-js key in your module's package.json file may lead to an error. Why? If you set it up to use nw.js 0.12.1 for example, then when it gets compiled during development time (to run its unit tests for example) it's gonna be compiled against io.js 1.2 runtime. But if you're having io.js 34.0.1 at the command line then, which is binary incompatible with 1.2, then your unit tests will fail for sure. So it is advised to not use cmake-js target settings in your module's package.json, because that way CMake.js will use that you have, and your tests will pass.

Configuration

If any of the runtime, runtimeVersion, or arch configuration parameters is not explicitly configured, sensible defaults will be auto-detected based on the JavaScript environment where CMake.js runs within.

You can configure runtimes for compiling target for all depending CMake.js modules in an application. Define a cmake-js key in the application's root package.json file, eg.:

{
	"name": "ta-taram-taram",
	"description": "pa-param-pam-pam",
	"version": "1.0.0",
	"main": "app.js",
	"cmake-js": {
		"runtime": "node",
		"runtimeVersion": "0.12.0",
		"arch": "ia32"
	}
}

Available settings:

  • runtime: application's target runtime, possible values are:
    • node: Node.js
    • nw: nw.js
    • electron: Electron
  • runtimeVersion: version of the application's target runtime, for example: 0.12.1
  • arch: architecture of application's target runtime (eg: x64, ia32, arm64, arm). Notice: on non-Windows systems the C++ toolset's architecture's gonna be used despite this setting. If you don't specify this on Windows, then architecture of the main node runtime is gonna be used, so you have to choose a matching nw.js runtime.

Node-API and node-addon-api

ABI-stable Node.js API (Node-API), which was previously known as N-API, supplies a set of C APIs that allow to compilation and loading of native modules by different versions of Node.js that support Node-API which includes all versions of Node.js v10.x and later.

To compile a native module that uses only the plain C Node-API calls, follow the directions for plain node native modules.

You must also add the following lines to your CMakeLists.txt, to allow for building on windows

if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET)
  # Generate node.lib
  execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS})
endif()

To compile a native module that uses the header-only C++ wrapper classes provided by node-addon-api, you need to make your package depend on it with:

npm install --save node-addon-api

cmake-js will then add it to the include search path automatically

You should add the following to your package.json, with the correct version number, so that cmake-js knows the module is node-api and that it can skip downloading the nodejs headers

"binary": {
    "napi_versions": [7]
  },

Electron

On Windows, the win_delay_load_hook is required to be embedded in the module or it will fail to load in the render process. cmake-js will add the hook if the CMakeLists.txt contains the library ${CMAKE_JS_SRC}.

Without the hook, the module can only be called from the render process using the Electron remote module.

Runtime options in CMakeLists.txt

The actual node runtime parameters are detectable in CMakeLists.txt files, the following variables are set:

  • NODE_RUNTIME: "node", "nw", "electron"
  • NODE_RUNTIMEVERSION: for example: "0.12.1"
  • NODE_ARCH: "x64", "ia32", "arm64", "arm"

NW.js

To make compatible your NW.js application with any NAN CMake.js based modules, write the following to your application's package.json file (this is not neccessary for node-api modules):

{
	"cmake-js": {
		"runtime": "nw",
		"runtimeVersion": "nw.js-version-here",
		"arch": "whatever-setting-is-appropriate-for-your-application's-windows-build"
	}
}

That's it. There is nothing else to do either on the application's or on the module's side, CMake.js modules are compatible with NW.js out-of-the-box. For more complete documentation please see the third tutorial.

Heroku

Heroku uses the concept of a buildpack to define how an application should be prepared to run in a dyno. The typical buildpack for note-based applications, heroku/nodejs, provides an environment capable of running node-gyp, but not CMake.

The least "painful" way of addressing this is to use heroku's multipack facility:

  • Set the applications' buildpack to https://github.com/heroku/heroku-buildpack-multi.git

  • In the root directory of the application, create a file called .buildpacks with these two lines:

        https://github.com/brave/heroku-cmake-buildpack.git
        https://github.com/heroku/heroku-buildpack-nodejs.git
    
  • Deploy the application to have the changes take effect

The heroku-buildpack-multi will run each buildpack in order allowing the node application to reference CMake in the Heroku build environment.

Tutorials

Real examples

  • @julusian/jpeg-turbo - A Node-API wrapping around libjpeg-turbo. cmake-js was a good fit here, as libjpeg-turbo provides cmake files that can be used, and would be hard to replicate correctly in node-gyp
  • node-datachannel - Easy to use WebRTC data channels and media transport
  • aws-iot-device-sdk-v2 AWS IoT Device SDK for JavaScript v2

Open a PR to add your own project here.

Changelog

View changelog.md

Credits

https://github.com/cmake-js/cmake-js/graphs/contributors

Ty all!

cmake-js's People

Contributors

am11 avatar bperel avatar ci7lus avatar d3x0r avatar dependabot[bot] avatar gerhardberger avatar gjasny avatar ionline247 avatar ivshti avatar javedulu avatar jmcker avatar johanvdwest avatar julusian avatar nicole-mcg avatar nik0c avatar njbrake avatar p-jackson avatar pajn avatar pd4d10 avatar pirxpilot avatar robinwassen avatar rogeriorc avatar rsatom avatar stuk avatar tomzbench avatar topecongiro avatar trxcllnt avatar unbornchikken avatar venediktov avatar victorleach96 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cmake-js's Issues

Choosing non-top VS generator (feature request)

Hello,

As far as I see, when cmake-js initializes the Toolset on Windows, we just grab the top version of Visual Studio as generator. Somewhere here
I could use an option which defines the generator explicitly, like in CMake:
cmake build . -G "Visual Studio 12 2013"
Any chance for that?

Thanks

Remove io.js mentions

from github and package.json

Thank you for creating this project. I've long wanted gyp to disappear.

cmake build tools

I have installed the build tools and when I run 'cmake-js build'. The command fails saying there is no Visual C++ compiler installed. Am I missing something? Does there need to be an environment variable setup?

CMake-js is not respecting CC and CXX env vars

Hi,

I have integrated a CMake based project with a cmake-js based one as a sub-project but cmake-js is not respecting my compiler preference informed through CC and CXX environment vars.
CMake-js has clang (at least under OSX) as its default compiler. I'm aware that cmake-js has -g option to switch to gcc instead but -g option is not a CMake supported feature, so it is not trivial to have cmake and cmake-js together using the same compiler seamlessly.
The main issue I'm facing now, as you may guess, is to have the nodejs native module which depends on a shared library built by the main project being compiled by two different compilers.

I would like to know your thoughts about this issue.

Thanks!

If there isn't an available toolchain CMake.js crashes with unhandlend rejection error

H:\arrayfire_js-master>node_modules.bin\cmake-js
info CMD CONFIGURE
info RUN cmake "H:\arrayfire_js-master" --no-warn-unused-cli -G"Visual Studio 11
2012 [arch] Win64" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_JS_INC="C:\Users\un.cm
ake-js\node-x64\v0.12.4\src;C:\Users\un.cmake-js\node-x64\v0.12.4\deps\v8\inclu
de;C:\Users\un.cmake-js\node-x64\v0.12.4\deps\uv\include;H:\arrayfire_js-master
\node_modules\nan" -DNODE_RUNTIME="node" -DNODE_RUNTIMEVERSION="0.12.4" -DNODE_A
RCH="x64" -DCMAKE_JS_LIB="C:\Users\un.cmake-js\node-x64\v0.12.4\x64\node.lib" -
DAF_PATH="H:/v3"
Not searching for unused variables given on the command line.
CMake Error: Could not create named generator Visual Studio 11 2012 [arch] Win64

Generators
Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files.
Optional [arch] can be "Win64" or "IA64".
Visual Studio 9 2008 [arch] = Generates Visual Studio 2008 project files.
Optional [arch] can be "Win64" or "IA64".
Visual Studio 8 2005 [arch] = Generates Visual Studio 2005 project files.
Optional [arch] can be "Win64".
Visual Studio 7 .NET 2003 = Generates Visual Studio .NET 2003 project
files.
Visual Studio 7 = Deprecated. Generates Visual Studio .NET
2002 project files.
Visual Studio 6 = Deprecated. Generates Visual Studio 6
project files.
Borland Makefiles = Generates Borland makefiles.
NMake Makefiles = Generates NMake makefiles.
NMake Makefiles JOM = Generates JOM makefiles.
Green Hills MULTI = Generates Green Hills MULTI files
(experimental, work-in-progress).
MSYS Makefiles = Generates MSYS makefiles.
MinGW Makefiles = Generates a make file for use with
mingw32-make.
Unix Makefiles = Generates standard UNIX makefiles.
Ninja = Generates build.ninja files.
Watcom WMake = Generates Watcom WMake makefiles.
CodeBlocks - MinGW Makefiles = Generates CodeBlocks project files.
CodeBlocks - NMake Makefiles = Generates CodeBlocks project files.
CodeBlocks - Ninja = Generates CodeBlocks project files.
CodeBlocks - Unix Makefiles = Generates CodeBlocks project files.
CodeLite - MinGW Makefiles = Generates CodeLite project files.
CodeLite - NMake Makefiles = Generates CodeLite project files.
CodeLite - Ninja = Generates CodeLite project files.
CodeLite - Unix Makefiles = Generates CodeLite project files.
Eclipse CDT4 - MinGW Makefiles
= Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - NMake Makefiles
= Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
Kate - MinGW Makefiles = Generates Kate project files.
Kate - NMake Makefiles = Generates Kate project files.
Kate - Ninja = Generates Kate project files.
Kate - Unix Makefiles = Generates Kate project files.
Sublime Text 2 - MinGW Makefiles
= Generates Sublime Text 2 project files.
Sublime Text 2 - NMake Makefiles
= Generates Sublime Text 2 project files.
Sublime Text 2 - Ninja = Generates Sublime Text 2 project files.
Sublime Text 2 - Unix Makefiles
= Generates Sublime Text 2 project files.

ERR! OMG Process terminated: 1
Unhandled rejection Error: Process terminated: 1
at ChildProcess. (H:\arrayfire_js-master\node_modules\cmake-js\li
b\cMake.js:367:24)
at ChildProcess.emit (events.js:110:17)
at Process.ChildProcess._handle.onexit (child_process.js:1074:12)

BUILDING_NODE_EXTENSION is not defined

node-gyp defines BUILDING_NODE_EXTENSION in addon.gypi (https://github.com/nodejs/node-gyp/blob/9bfa0876b46764978492fffea074d2d7aa8954f9/addon.gypi). It's used in node.h below.
cmake-js should define it, too.

#ifdef _WIN32
# ifndef BUILDING_NODE_EXTENSION
#   define NODE_EXTERN __declspec(dllexport)
# else
#   define NODE_EXTERN __declspec(dllimport)
# endif
#else
# define NODE_EXTERN /* nothing */
#endif

#ifdef BUILDING_NODE_EXTENSION
# undef BUILDING_V8_SHARED
# undef BUILDING_UV_SHARED
# define USING_V8_SHARED 1
# define USING_UV_SHARED 1
#endif

cmake-js binary cannot be found when an upper level project has cmake-js dependency.

If the main project has cmake-js as a dependency, you get:

amelie@Samsung-550P7C ~/workspace/projetPFE $ npm install
|
> [email protected] install /home/amelie/workspace/projetPFE/node_modules/albers-core-module
> node ./node_modules/cmake-js/bin/cmake-js rebuild


module.js:340
    throw err;
          ^
Error: Cannot find module '/home/amelie/workspace/projetPFE/node_modules/albers-core-module/node_modules/cmake-js/bin/cmake-js'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:935:3

If the main project has nan as a dependency, you get:

info CMD BUILD
info RUN cmake --build "/home/amelie/workspace/projetPFE/node_modules/albers-core-module/build" --config Release
Scanning dependencies of target addon
[  5%] Building CXX object CMakeFiles/addon.dir/src/addon.cc.o
/home/amelie/workspace/projetPFE/node_modules/albers-core-module/src/addon.cc:2:10: fatal error: 'nan.h' file not found
#include <nan.h>
         ^
1 error generated.
make[2]: *** [CMakeFiles/addon.dir/src/addon.cc.o] Error 1
make[1]: *** [CMakeFiles/addon.dir/all] Error 2
make: *** [all] Error 2
ERR! OMG Process terminated: 2

But it works fine once your remove those dependencies.

Exception thrown when requiring a native addon built by cmake-js

I'm building my addon for Electron v0.29.2. Previously I use node-gyp to build the addon and everything is fine. However after building with cmake-js, requiring the addon in js will throw an exception:

Uncaught Exception:
Error: Module did not self-register.
    at Error (native)
    at Object.module.(anonymous function) (ATOM_SHELL_ASAR.js:137:20)
    at Object.module.(anonymous function) [as .node] (ATOM_SHELL_ASAR.js:137:20)
    at Module.load (module.js:353:32)
    at Function.Module._load (module.js:308:12)
    at Module.require (module.js:363:17)
    at require (module.js:382:17)
    at Object.<anonymous> (/tmp/MyApp.app/Contents/Resources/app/main.js:147:16)
    at Module._compile (module.js:428:26)
    at Object.Module._extensions..js (module.js:446:10)

I've already set the cmake-js.runtime in package.json to electron and runtimeVersion to 0.29.2 with arch set to ia32. The folder node_modules has always been deleted before take a cmake-js rebuild. Could you please give some suggestions about how to fix this issue?

Thanks.

Gyp to cmake tool

Do you know of anyone working on a tool to automate the process of transitioning from node-gyp to cmake.js?

[Doc] Update to tutorial 1

I've read through the wiki's tutorial 1 and made some adjustments:

  • Fixed some mistakes
  • Removed repetitive passages
  • Updated CMakeLists.txt to use target_include_directories()

https://gist.github.com/MajorBreakfast/b92c82ad1701e604f788

Note: I can't provide a PR unfortunately because github doesn't support PRs for wiki repos.

BTW cmake-js worked great for me so far (on all three platforms). So, thanks for that!

Checksum error when building

On Windows 7 Enterprise (x64) with Node.js 0.12.4 (ia32), when building a native extension the following error occur:

cmake-js -D
info DIST Downloading distribution files.
http DIST - http://nodejs.org/dist/v0.12.4/SHASUMS256.txt
http DIST - http://nodejs.org/dist/v0.12.4/win-x86/node.lib
http DIST - http://nodejs.org/dist/v0.12.4/node-v0.12.4.tar.gz
ERR! OMG SHA sum of file 'win-x86/node.lib' mismatch!
ERR! OMG SHA sum of file 'win-x86/node.lib' mismatch!
Unhandled rejection Error: SHA sum of file 'win-x86/node.lib' mismatch!

Any idea on what may be wrong ?

How to alway use latest `runtimeVersion` ?

I don't want declare version directly. Is it possible setup always use the latest version?

something like

"cmake-js":
{
    "runtime": "node",
    "runtimeVersion": "*"
}

Thanks in advance.

Compile cmake upon npm install for "zero"-dependency-style

Hi,

have you considered, building cmake itself upon installation of this module? Something like...

git clone -b master --single-branch --depth 1 https://github.com/Kitware/CMake  node_modules/lib_cmake
./bootstrap --prefix=<this_modules_path>  # path to node_modules/lib_cmake 
make && make install

I currently like to integrate your module in peterbraden/node-opencv. Since opencv and this module have a lot of dependencies itself, I care to reduce them by integrating the native dependencies like this.

This would obviously support you argument about cmake being zero-dependent.

If it's worth a shot, I could send you a quick PR.

All the best!

Linking .dylib libraries for addon

Hi!

I'm writing an addon that needs several .dylib libraries. On OSX after building them, I copy them to /usr/local/lib. In my CMakeLists.txt I write:

target_link_libraries(
  ${PROJECT_NAME}
  ${CMAKE_JS_LIB}
  /usr/local/lib/libExample.dylib
)

And after compiling the addon with cmake-js it runs correctly.
However if I don't copy it into /usr/local/lib and specify its original path in CMakeLists.txt, it doesn't work. It compiles, but at runtime it stops.

How should I link it correctly?

Thanks

"There is no Visual C++ compiler installed. Install Visual C++ Build Toolset or Visual Studio"

I'm receiving this error when running cmake-js compile on Windows 10 with Visual Studio 2015 Community installed. I have all the Visual Studio Visual C++ tools installed, and even restarted for good measure, yet the error remains.

I also tried adding C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\Bin\ to my PATH and even tried to run it as Administrator but that doesn't work either.

Any ideas as to what could be going wrong?

Distributing cmake options in npm packages

I'm maintaining the nbind project which autogenerates NAN and Emscripten bindings (and TypeScript definitions) for C++ classes and functions. It makes writing Node.js addons extremely easy but requires a number of compiler options to use especially when targeting Emscripten, so it comes with a couple of .gypi files.

Another tool, autogypi autogenerates a binding.gyp file for a new project given names of packages it depends on. It plays nicely with both nbind and nan, noticing the former depends on the latter and sets everything up.

I'd like to add support for cmake-js in nbind and autogypi, so that these quick start instructions would be equally easy when using cmake-js instead of node-gyp (this would be an option). That would also get rid of the Python 2 dependency (unless targeting Emscripten, which still depends on it).

For this, maybe some sort of interaction between cmake-js and autogypi would be useful? Do you have any thoughts for a standard way to include the necessary CMakeLists options in npm packages intended to be used as C++ libraries?

Package install cannot find <nan.h>

In manual mode everything (building in from my source directory) works and builds fine. Now i tried to package it all up and do a test install on another machine and there cmake-js cannot find nan.h

My package.json looks like this:

{
  "name": "vtk",
  "version": "1.0.2",
  "description": "node.js bindings to VTK",
  "author": {
    "name": "Axel Kittenberger",
    "email": "[email protected]"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/axkibe/node-vtk"
  },
  "main": "./index",
  "license": "BSD-3-Clause",
  "devDependencies": {
    "cmake-js": "^3.0.0",
    "nan": "^2.2.0"
  },
  "dependencies": {
    "cmake-js": "^3.0.0",
    "nan": "^2.2.0"
  },
  "scripts": {
    "install": "cmake-js compile"
  }
}

Trying to install it:

$ npm install vtk
npm WARN deprecated [email protected]: this package has been reintegrated into npm and is now out of date with respect to npm

> [email protected] install /home/axel/nvtk/node_modules/vtk
> cmake-js compile

info TOOL Using Unix Makefiles generator.
info TOOL Using c++11 compiler standard.
info CMD CONFIGURE
info RUN cmake "/home/axel/nvtk/node_modules/vtk" --no-warn-unused-cli -G"Unix Makefiles" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_LIBRARY_OUTPUT_DIRECTORY="/home/axel/nvtk/node_modules/vtk/build/Release" -DCMAKE_JS_INC="/home/axel/.cmake-js/node-x64/v5.5.0/include/node" -DNODE_RUNTIME="node" -DNODE_RUNTIMEVERSION="5.5.0" -DNODE_ARCH="x64" -DCMAKE_CXX_FLAGS="-std=c++11"
Not searching for unused variables given on the command line.
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- The imported target "vtkCommonCoreTCL" references the file
   "/usr/lib/x86_64-linux-gnu/libvtkCommonCoreTCL-6.1.so.6.1.0"
but this file does not exist.  Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
   "/usr/lib/cmake/vtk-6.1/VTKTargets.cmake"
but not all the files it references.

[Many more of reference fail Wanrs]

-- Configuring done
-- Generating done
-- Build files have been written to: /home/axel/nvtk/node_modules/vtk/build
info CMD BUILD
info RUN cmake --build "/home/axel/nvtk/node_modules/vtk/build" --config Release
Scanning dependencies of target node-vtk
[  0%] Building CXX object CMakeFiles/node-vtk.dir/src/vtkInteractorStyleTrackballCameraWrap.cc.o
/home/axel/nvtk/node_modules/vtk/src/vtkInteractorStyleTrackballCameraWrap.cc:6:17: fatal error: nan.h: No such file or directory
 #include <nan.h>
                 ^
compilation terminated.
CMakeFiles/node-vtk.dir/build.make:54: recipe for target 'CMakeFiles/node-vtk.dir/src/vtkInteractorStyleTrackballCameraWrap.cc.o' failed
make[2]: *** [CMakeFiles/node-vtk.dir/src/vtkInteractorStyleTrackballCameraWrap.cc.o] Error 1
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/node-vtk.dir/all' failed
make[1]: *** [CMakeFiles/node-vtk.dir/all] Error 2
Makefile:76: recipe for target 'all' failed
make: *** [all] Error 2
info REP Build has been failed, trying to do a full rebuild.
info CMD CLEAN
info RUN cmake -E remove_directory "/home/axel/nvtk/node_modules/vtk/build"
info CMD CONFIGURE
info RUN cmake "/home/axel/nvtk/node_modules/vtk" --no-warn-unused-cli -G"Unix Makefiles" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_LIBRARY_OUTPUT_DIRECTORY="/home/axel/nvtk/node_modules/vtk/build/Release" -DCMAKE_JS_INC="/home/axel/.cmake-js/node-x64/v5.5.0/include/node" -DNODE_RUNTIME="node" -DNODE_RUNTIMEVERSION="5.5.0" -DNODE_ARCH="x64" -DCMAKE_CXX_FLAGS="-std=c++11"
Not searching for unused variables given on the command line.
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- The imported target "vtkCommonCoreTCL" references the file
   "/usr/lib/x86_64-linux-gnu/libvtkCommonCoreTCL-6.1.so.6.1.0"
but this file does not exist.  Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
   "/usr/lib/cmake/vtk-6.1/VTKTargets.cmake"
but not all the files it references.

-- The imported target "vtkCommonMathTCL" references the file
   "/usr/lib/x86_64-linux-gnu/libvtkCommonMathTCL-6.1.so.6.1.0"
but this file does not exist.  Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
   "/usr/lib/cmake/vtk-6.1/VTKTargets.cmake"
but not all the files it references.

-- Configuring done
-- Generating done
-- Build files have been written to: /home/axel/nvtk/node_modules/vtk/build
info CMD BUILD
info RUN cmake --build "/home/axel/nvtk/node_modules/vtk/build" --config Release
Scanning dependencies of target node-vtk
[  0%] Building CXX object CMakeFiles/node-vtk.dir/src/vtkInteractorStyleTrackballCameraWrap.cc.o
/home/axel/nvtk/node_modules/vtk/src/vtkInteractorStyleTrackballCameraWrap.cc:6:17: fatal error: nan.h: No such file or directory
 #include <nan.h>
                 ^
compilation terminated.
CMakeFiles/node-vtk.dir/build.make:54: recipe for target 'CMakeFiles/node-vtk.dir/src/vtkInteractorStyleTrackballCameraWrap.cc.o' failed
make[2]: *** [CMakeFiles/node-vtk.dir/src/vtkInteractorStyleTrackballCameraWrap.cc.o] Error 1
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/node-vtk.dir/all' failed
make[1]: *** [CMakeFiles/node-vtk.dir/all] Error 2
Makefile:76: recipe for target 'all' failed
make: *** [all] Error 2
ERR! OMG Process terminated: 2
npm WARN ENOENT ENOENT: no such file or directory, open '/home/axel/nvtk/package.json'
npm WARN EPACKAGEJSON nvtk No description
npm WARN EPACKAGEJSON nvtk No repository field.
npm WARN EPACKAGEJSON nvtk No README data
npm WARN EPACKAGEJSON nvtk No license field.
npm ERR! Linux 3.16.0-4-amd64
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "vtk"
npm ERR! node v5.5.0
npm ERR! npm  v3.3.12
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `cmake-js compile`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script 'cmake-js compile'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the vtk package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     cmake-js compile
npm ERR! You can get their info via:
npm ERR!     npm owner ls vtk
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/axel/nvtk/npm-debug.log

I tried on that machine again manually cloning https://github.com/axkibe/node-vtk and running ./node_modules/.bin/cmake-js bulid manually and that works again...

compile_commands.json

Why does running cmake-js configure not generate compile_commands.json. I have in my CMake file:

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Instead, I have to run cmake on my own after cmake-js configure... it's quite annoying.

Import issue ?

Hello,

I'm working on this module https://github.com/AmelieA/albers-core which now compile thanks to unbornchikken. But I'm still having some trouble using any of the code on the deps folder because of some import issues.
I'm trying to run the code on examples/write.cc but the compiler does not recognize the albers namespace from one of the import.

I've tried importing the same import as the write.cc file on the addon.cc file but then the import file can't import its own header.
I've tried an include_directories("${PROJECT_SOURCE_DIR}/deps") with no success.
I've tried importing the write.cc on the addon.cc but nothing.

I ran out of ideas of what I could do without modifying the deps folder.
Any ideas ?

Unable to compile cmake-js-tut-04-boost-module example

Hi, I have to use cmake for my module building and I've ran into some errors. I've decided to try an example and it also failed. Here's the log:

lyssdod@lynn /storage/work $ git clone https://github.com/cmake-js/cmake-js-tut-04-boost-module
Cloning into 'cmake-js-tut-04-boost-module'...
remote: Counting objects: 47, done.
remote: Total 47 (delta 0), reused 0 (delta 0), pack-reused 47
Unpacking objects: 100% (47/47), done.
Checking connectivity... done.
lyssdod@lynn /storage/work $ cd cmake-js-tut-04-boost-module/
lyssdod@lynn /storage/work/cmake-js-tut-04-boost-module $ npm install
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No license field.
npm WARN deprecated [email protected]: this package has been reintegrated into npm and is now out of date with respect to npm
-
> [email protected] install /storage/work/cmake-js-tut-04-boost-module
> cmake-js compile

info TOOL Using Ninja generator, because ninja is available.
info TOOL Using c++11 compiler standard.
info DIST Downloading distribution files.
http DIST   - http://nodejs.org/dist/v4.4.1/SHASUMS256.txt
http DIST   - http://nodejs.org/dist/v4.4.1/node-v4.4.1-headers.tar.gz
info CMD CONFIGURE
info RUN cmake "/storage/work/cmake-js-tut-04-boost-module" --no-warn-unused-cli -G"Ninja" -DCMAKE_JS_VERSION="3.3.0" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_LIBRARY_OUTPUT_DIRECTORY="/storage/work/cmake-js-tut-04-boost-module/build/Release" -DCMAKE_JS_INC="/home/lyssdod/.cmake-js/node-x64/v4.4.1/include/node;/storage/work/cmake-js-tut-04-boost-module/node_modules/nan" -DNODE_RUNTIME="node" -DNODE_RUNTIMEVERSION="4.4.1" -DNODE_ARCH="x64" -DCMAKE_CXX_FLAGS="-std=c++11"
Not searching for unused variables given on the command line.
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Require Boost Libs module started.
-- Required Boost version: >= 1.58.0
-- Required libs: coroutine
-- Boost Lib Installer starting.
-- Invoking boost-lib to download Boost >= 1.58.0.
info BOOST Searching for Boost >= 1.58.0 in '/home/lyssdod/.cmake-js/boost'.
info BOOST Boost found in '/home/lyssdod/.cmake-js/boost/1.61.0'.
-- Boost path: /home/lyssdod/.cmake-js/boost/1.61.0
-- Boost version: 1.61.0
-- Boost library postfix: 1_61
-- b2 executable found.
-- Generating b2 args.
--  variant=release
-- b2 args: link=static;threading=multi;runtime-link=shared;--build-dir=Build;stage;--stagedir=stage;-d+2;--hash;variant=release;--layout=tagged;-sNO_BZIP2=1;cxxflags=-fPIC;cxxflags=-std=c++11;toolset=gcc-5.4
-- Resolving Boost library: coroutine
-- Setting up external project to build coroutine.
-- Setting boost_coroutine dependent on boost_context
-- Setting boost_coroutine dependent on boost_system
-- Resolving Boost library: context
-- Setting up external project to build context.
-- Setting boost_context dependent on boost_thread
-- Resolving Boost library: system
-- Setting up external project to build system.
-- Resolving Boost library: thread
-- Setting up external project to build thread.
-- Setting boost_thread dependent on boost_chrono
-- Resolving Boost library: chrono
-- Setting up external project to build chrono.
-- Setting boost_chrono dependent on boost_system
-- Boost libs scheduled for build: boost_coroutine;boost_context;boost_system;boost_thread;boost_chrono
-- Generating headers ...
CMake Error at node_modules/boost-lib/cmake/BoostLibInstaller.cmake:185 (message):
  b2 error:


  /home/lyssdod/.cmake-js/boost/1.61.0/tools/build/src/build/feature.jam:494:
  in feature.validate-value-string from module feature

  error: "none" is not a known value of feature <optimization>

  error: legal values: "off" "speed" "space"


  /home/lyssdod/.cmake-js/boost/1.61.0/tools/build/src/build/property.jam:276:
  in validate1 from module property


  /home/lyssdod/.cmake-js/boost/1.61.0/tools/build/src/build/property.jam:302:
  in property.validate from module property


  /home/lyssdod/.cmake-js/boost/1.61.0/tools/build/src/tools/builtin.jam:381:
  in variant from module builtin

  /usr/share/boost-build/site-config.jam:9: in modules.load from module
  site-config

  /home/lyssdod/.cmake-js/boost/1.61.0/tools/build/src/build-system.jam:249:
  in load-config from module build-system

  /home/lyssdod/.cmake-js/boost/1.61.0/tools/build/src/build-system.jam:351:
  in load-configuration-files from module build-system

  /home/lyssdod/.cmake-js/boost/1.61.0/tools/build/src/build-system.jam:524:
  in load from module build-system


  /home/lyssdod/.cmake-js/boost/1.61.0/tools/build/src/kernel/modules.jam:295:
  in import from module modules


  /home/lyssdod/.cmake-js/boost/1.61.0/tools/build/src/kernel/bootstrap.jam:139:
  in boost-build from module

  /home/lyssdod/.cmake-js/boost/1.61.0/boost-build.jam:17: in module scope
  from module



Call Stack (most recent call first):
  node_modules/boost-lib/cmake/BoostLib.cmake:19 (boost_lib_installer)
  CMakeLists.txt:16 (require_boost_libs)


-- Configuring incomplete, errors occurred!
See also "/storage/work/cmake-js-tut-04-boost-module/build/CMakeFiles/CMakeOutput.log".
info REP Build has been failed, trying to do a full rebuild.
info CMD CLEAN
info RUN cmake -E remove_directory "/storage/work/cmake-js-tut-04-boost-module/build"
info CMD CONFIGURE
info RUN cmake "/storage/work/cmake-js-tut-04-boost-module" --no-warn-unused-cli -G"Ninja" -DCMAKE_JS_VERSION="3.3.0" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_LIBRARY_OUTPUT_DIRECTORY="/storage/work/cmake-js-tut-04-boost-module/build/Release" -DCMAKE_JS_INC="/home/lyssdod/.cmake-js/node-x64/v4.4.1/include/node;/storage/work/cmake-js-tut-04-boost-module/node_modules/nan" -DNODE_RUNTIME="node" -DNODE_RUNTIMEVERSION="4.4.1" -DNODE_ARCH="x64" -DCMAKE_CXX_FLAGS="-std=c++11"
Not searching for unused variables given on the command line.
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Require Boost Libs module started.
-- Required Boost version: >= 1.58.0
-- Required libs: coroutine
-- Boost Lib Installer starting.
-- Invoking boost-lib to download Boost >= 1.58.0.
info BOOST Searching for Boost >= 1.58.0 in '/home/lyssdod/.cmake-js/boost'.
info BOOST Boost found in '/home/lyssdod/.cmake-js/boost/1.61.0'.
-- Boost path: /home/lyssdod/.cmake-js/boost/1.61.0
-- Boost version: 1.61.0
-- Boost library postfix: 1_61
-- b2 executable found.
-- Generating b2 args.
--  variant=release
-- b2 args: link=static;threading=multi;runtime-link=shared;--build-dir=Build;stage;--stagedir=stage;-d+2;--hash;variant=release;--layout=tagged;-sNO_BZIP2=1;cxxflags=-fPIC;cxxflags=-std=c++11;toolset=gcc-5.4
-- Resolving Boost library: coroutine
-- Setting up external project to build coroutine.
-- Setting boost_coroutine dependent on boost_context
-- Setting boost_coroutine dependent on boost_system
-- Resolving Boost library: context
-- Setting up external project to build context.
-- Setting boost_context dependent on boost_thread
-- Resolving Boost library: system
-- Setting up external project to build system.
-- Resolving Boost library: thread
-- Setting up external project to build thread.
-- Setting boost_thread dependent on boost_chrono
-- Resolving Boost library: chrono
-- Setting up external project to build chrono.
-- Setting boost_chrono dependent on boost_system
-- Boost libs scheduled for build: boost_coroutine;boost_context;boost_system;boost_thread;boost_chrono
-- Generating headers ...
CMake Error at node_modules/boost-lib/cmake/BoostLibInstaller.cmake:185 (message):
  b2 error:


  /home/lyssdod/.cmake-js/boost/1.61.0/tools/build/src/build/feature.jam:494:
  in feature.validate-value-string from module feature

  error: "none" is not a known value of feature <optimization>

  error: legal values: "off" "speed" "space"


  /home/lyssdod/.cmake-js/boost/1.61.0/tools/build/src/build/property.jam:276:
  in validate1 from module property


  /home/lyssdod/.cmake-js/boost/1.61.0/tools/build/src/build/property.jam:302:
  in property.validate from module property


  /home/lyssdod/.cmake-js/boost/1.61.0/tools/build/src/tools/builtin.jam:381:
  in variant from module builtin

  /usr/share/boost-build/site-config.jam:9: in modules.load from module
  site-config

  /home/lyssdod/.cmake-js/boost/1.61.0/tools/build/src/build-system.jam:249:
  in load-config from module build-system

  /home/lyssdod/.cmake-js/boost/1.61.0/tools/build/src/build-system.jam:351:
  in load-configuration-files from module build-system

  /home/lyssdod/.cmake-js/boost/1.61.0/tools/build/src/build-system.jam:524:
  in load from module build-system


  /home/lyssdod/.cmake-js/boost/1.61.0/tools/build/src/kernel/modules.jam:295:
  in import from module modules


  /home/lyssdod/.cmake-js/boost/1.61.0/tools/build/src/kernel/bootstrap.jam:139:
  in boost-build from module

  /home/lyssdod/.cmake-js/boost/1.61.0/boost-build.jam:17: in module scope
  from module



Call Stack (most recent call first):
  node_modules/boost-lib/cmake/BoostLib.cmake:19 (boost_lib_installer)
  CMakeLists.txt:16 (require_boost_libs)


-- Configuring incomplete, errors occurred!
See also "/storage/work/cmake-js-tut-04-boost-module/build/CMakeFiles/CMakeOutput.log".
ERR! OMG Process terminated: 1

npm ERR! Linux 4.5.2-aufs
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install"
npm ERR! node v4.4.1
npm ERR! npm  v2.14.20
npm ERR! code ELIFECYCLE
npm ERR! [email protected] install: `cmake-js compile`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script 'cmake-js compile'.
npm ERR! This is most likely a problem with the cmake-js-tut-04-boost-module package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     cmake-js compile
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs cmake-js-tut-04-boost-module
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! 
npm ERR!     npm owner ls cmake-js-tut-04-boost-module
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /storage/work/cmake-js-tut-04-boost-module/npm-debug.log

Developing with CLion

I am wondering what has to be done to let CLion compile the addon from within the IDE. Currently I am just executing cmake-js rebuild from the command line, but in CLion everything associated with nan is red and I can't use the debugger CLion provides. It is not possible, at least as far as I know, to execute a custom command to build the project.

I tried to add CMAKE_JS_INC vatiable to the CMake project settings enviroment variables without success. I also tried to configure a external tool to build the project with, but that did not work either.

cmake-js uses old headers

the current node version is 6.5.0
the headers it's including is ~/.cmake-js/node-x64/v6.3.1/include/node

There's no env.h Header?

Is it possible define runtime/runtimeversion/arch on `npm install`?

It has a meaning for developers who start new projects and don't have package.json for root project yet or don't have cmake-js section in it. And according to docs:

If you're creating a native module targeting nw.js for example, then do not specify anything in your module's package.json.

Thanks in advance.

Feedback: What if I say installing Visual Studio won't required on Windows anymore?

Hi,

Just gathering feedback on the title. I think I can implement full MinGW toolchain support for Windows. That means Visual Studio (= 12 GBytes hog) won't required to build CMake.js based modules. MinGW could be installed from SourceForge: http://sourceforge.net/projects/mingw-w64/ and a far less PITA than installing Visual Sutdio. But even I can provide a DropBox based automatic install mechanism, which means to use CMake.js build system there should not be anything installed on Windows other than CMake!

My question is, does it worth my effort? Is the requirement of installing Visual Studio a real problem, or you can live with it?

HELP WANTED: TESTING ON MAC

If anyone has a chance to test this stuff running on Mac that would be greatly appreciated. Please report any issue that you found. And of course if it works as intended, please let me know that too. :)

package.json minimum node version too low

Hi,
I'm wanted to run cmake-js on a machine with Ubuntu 14.04 and legacy node version installed. The default version of the nodejs package is v0.10.25. In your package.json the minimum required version is:

  "engines": {
    "node": ">= 0.10.0",
    "iojs": ">= 1.0.0"
  },

But if I want to run cmake-js compile then I get the following error:

.../node_modules/cmake-js/bin/cmake-js:140
for (var key of _.keys(argv)) {
             ^^
SyntaxError: Unexpected identifier
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3

On another machine with a newer node version cmake-js works perfect!

suggestion: add a pointer on using a heroku buildpack to include cmake

perhaps this is documented somewhere that i couldn't find... but it'd be helpful for the folks that use heroku to know how to get cmake into the build system, e.g.,

    heroku buildpacks:set https://github.com/ddollar/heroku-buildpack-multi.git --app $APP

then create .buildpacks with these two lines:

    https://github.com/brave/heroku-cmake-buildpack.git
    https://github.com/heroku/heroku-buildpack-nodejs.git

using --arch on windows does nothing

Running cmake-js rebuild --runtime=electron --runtime-version=0.28.3 --arch=x64
On a 32-bit windows machine NODE_ARCH=ia32 and on a 64 bit machine NODE_ARCH=x64.

Looks like a typo in bin/cmake-js at line 123

arch: argv.A should be arch: argv.a

v3.1 broken

I am getting the following after installing the new version (Both on OSx and Ubuntu):

$ cmake-js
: No such file or directory

reverting back to v3.0 fixes the problem which suggests that the new version is broken.

How to integrate with a regular CMake based project?

Is some special procedure required to add the cmake-js based project as part of a regular cmake based builds?

I have CMake based project that generates a cpp static library, which is the root project.

I am trying to add the cmake-js addon project as a sub-directory that depends on the root static cpp library.

The cmake-js build command is working fine from command prompt. But, when invoking through the parent project with ADD_SUBDIRECTORY(...) it is not generating the correct js includes / libs, resulting in compiler errors.

Printing the ${CMAKE_JS_LIB} value is giving empty values when building as part of the regular CMake projects.

Question:

How to integrate the cmake-js sub-project to be part of the bigger regular CMake project correctly?

How are headers generated?

Not so much of an issue as a documentation request I guess...

I tried to find, how do you create the header/lib packages that are hosted?

Problem with line endings on Ubuntu and OSX in version 3.2.2

Hi, I noticed that in the last version of cmake-js (version 3.2.2 to this date) there is some problem with line endings. Specifically if I npm install this version and then try to run cmake-js I get

$> cmake-js 
: No such file or directory

on Linux (both Ubuntu 12.04 and 14.04), and

$> cmake-js
env: node\r: No such file or directory

on OSX (El Capitan)

I found a hint that this could be due to line endings thanks to [this StackOverflow post]((http://stackoverflow.com/questions/30344858/node-script-executable-not-working-on-mac-env-node-r-no-such-file-or-directo) and indeed by following the suggested procedure I was able to locally fix the cmake-js script.

Would it be possible to correct this in the Cmake.js project itself?

BTW, thanks for the great project : )

Building with Electron 0.32.1 failed with "incorrect header check" error

Building my addon with cmake-js throws "incorrect header check" error. This problem may caused by electron side though I'm not certain. So I opened an issue here.

$ cmake-js rebuild -r electron -v 0.32.1 -a ia32 -l=silly

...
info DIST Downloading distribution files.
http DIST   - http://atom.io/download/atom-shell/v0.32.1/node-v0.32.1.tar.gz
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: incorrect header check
    at Zlib._handle.onerror (zlib.js:366:17)

building on existing project

I am currently developing a website to visualize data coming from the particle collider (or similar data) for my last year of engineering school. To do that, I am looking at a way to create a module of the cern c++ code and integrate it to my nodeJS website.
Since the cern code (https://github.com/cbernet/albers-core based on https://root.cern.ch/drupal/content/downloading-root) is compiled with a CMakeLists.txt, I naturally found your cmake-js project really interesting. I tried your demo code and it worked flawlessly but I can't figure out how to make it work when the code used already have a CMakeLists.txt.

Here is the module project https://github.com/AmelieA/albers-core, I know it is not much but I don't know anything about cmake (apart from the doc I've read) and I am just trying to make the albers-core/examples/read.cc work with nodeJS without changing too much the architecture of the project (you can see that my code is almost only the files in the albers-core/javascript/ folder).

Here is the error code after an npm install :

[ 94%] Building CXX object javascript/CMakeFiles/albers-read-adapter.dir/readAdapter.cc.o
ERR! OMG In file included from /home/amelie/workspace/albers-core-module-noSRC/javascript/readAdapter.cc:1:
ERR! OMG In file included from /home/amelie/workspace/albers-core-module-noSRC/node_modules/nan/nan.h:24:
ERR! OMG In file included from /home/amelie/.cmake-js/node-x64/v0.10.38/src/node.h:62:
ERR! OMG /home/amelie/.cmake-js/node-x64/v0.10.38/deps/v8/include/v8.h:3005:5: warning: anonymous types declared in an anonymous union are an extension [-Wnested-anon-types]
ERR! OMG struct {
ERR! OMG ^
ERR! OMG 1 warning generated.
ERR! OMG Linking CXX executable albers-read-adapter
ERR! OMG CMakeFiles/albers-read-adapter.dir/readAdapter.cc.o: In function returnValue(v8::Arguments const&)': ERR! OMG /home/amelie/workspace/albers-core-module-noSRC/javascript/readAdapter.cc:(.text+0x55d): undefined reference tov8::HandleScope::HandleScope()'
ERR! OMG /home/amelie/workspace/albers-core-module-noSRC/javascript/readAdapter.cc:(.text+0x56e): undefined reference to v8::Undefined()' ERR! OMG /home/amelie/workspace/albers-core-module-noSRC/javascript/readAdapter.cc:(.text+0x576): undefined reference tov8::Value::Uint32Value() const'
ERR! OMG /home/amelie/workspace/albers-core-module-noSRC/javascript/readAdapter.cc:(.text+0x57f): undefined reference to v8::Number::New(double)' ERR! OMG /home/amelie/workspace/albers-core-module-noSRC/javascript/readAdapter.cc:(.text+0x58b): undefined reference tov8::HandleScope::RawClose(v8::internal::Object*)'
ERR! OMG /home/amelie/workspace/albers-core-module-noSRC/javascript/readAdapter.cc:(.text+0x597): undefined reference to v8::HandleScope::~HandleScope()' ERR! OMG /home/amelie/workspace/albers-core-module-noSRC/javascript/readAdapter.cc:(.text+0x5ac): undefined reference tov8::HandleScope::~HandleScope()'
ERR! OMG CMakeFiles/albers-read-adapter.dir/readAdapter.cc.o: In function InitAll(v8::Handle<v8::Object>)': ERR! OMG /home/amelie/workspace/albers-core-module-noSRC/javascript/readAdapter.cc:(.text+0x5d4): undefined reference tov8::String::New(char const
, int)'
ERR! OMG /home/amelie/workspace/albers-core-module-noSRC/javascript/readAdapter.cc:(.text+0x5e7): undefined reference to v8::FunctionTemplate::New(v8::Handle<v8::Value> (*)(v8::Arguments const&), v8::Handle<v8::Value>, v8::Handle<v8::Signature>)' ERR! OMG /home/amelie/workspace/albers-core-module-noSRC/javascript/readAdapter.cc:(.text+0x5ef): undefined reference tov8::FunctionTemplate::GetFunction()'
ERR! OMG /home/amelie/workspace/albers-core-module-noSRC/javascript/readAdapter.cc:(.text+0x606): undefined reference to `v8::Object::Set(v8::Handlev8::Value, v8::Handlev8::Value, v8::PropertyAttribute)'
ERR! OMG clang-3.6: error: linker command failed with exit code 1 (use -v to see invocation)
ERR! OMG make[2]: *** [javascript/albers-read-adapter] Error 1
ERR! OMG make[1]: *** [javascript/CMakeFiles/albers-read-adapter.dir/all] Error 2
ERR! OMG make: *** [all] Error 2
ERR! OMG

Any help is appreciated.
Amélie.

cmake-js v2.0.0 print-configure does not work

Hi,

After update cmake-js from v1.1.1 to v2.0.0, I'm getting the following output:

$ cmake-js print-configure
info CFG Applying CMake.js config from root package.json:
info CFG {"runtime":"node","runtimeVersion":"0.12.7","arch":"x64"}
undefined

Any idea?

[Enhancement] Defining a special CMake variable to indicate that CMake.js is being used

Hello,

I would like to suggest adding a new CMake variable (e.g. NPM_CMAKEJS) to the set of variables defined by CMake.js when configuring the project. (i.e. something like D.push({"NPM_CMAKEJS": "TRUE"}); in cMake.js)

This would indicate that CMake has been invoked by CMake.js. (as opposed to a call from the command line or by an IDE such as CLion)

Having such a variable allows more flexibility in the CMakeLists.txt. For instance, when working on a complex project, it can be used to switch between sub-projects:

if (NPM_CMAKEJS)
    add_subdirectory(node_addon)
else()
    add_subdirectory(other_subproject)
endif()

Thanks :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.