cmake-js / fastcall

fastcall - Fast, dyncall based foreign function interface library for Node.js
https://www.npmjs.com/package/fastcall
Other
202 stars 14 forks source link

Windows 10 npm install fix #40

Open kungfooman opened 6 years ago

kungfooman commented 6 years ago

Hi, thanks for this nice library. I just tried it, but the build process fails with some missing headers, so I had to fix two cmake files

1) npm install fastcall --force

--force is needed, because otherwise all files will be deleted in case of failed build (it will currently fail)

2) Fix your node_modules/fastcall/src/CMakeLists.txt to something like this:

# Copyright 2016 Gábor Mező (gabor.mezo@outlook.com)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

file(GLOB SRC *.h* *.c*)

add_library(${PROJECT_NAME} SHARED ${SRC})

target_include_directories(${PROJECT_NAME} PRIVATE
  "D:/BabylonCpp/node/node_modules/nan"
  "C:/Users/kung/.cmake-js/node-x64/v8.9.4/include/node")

target_link_libraries (${PROJECT_NAME}
  ${CMAKE_JS_LIB}
  ${DYNCALL_LIBRARIES}
  ${DYNCALLBACK_LIBRARIES}
  ${DYNLOAD_LIBRARIES}
  "C:/Users/kung/.cmake-js/node-x64/v8.9.4/win-x64/node.lib")

set_target_properties(
  ${PROJECT_NAME}
  PROPERTIES
  PREFIX "" 
  SUFFIX ".node")

The hardcoded paths of course need to be fixed, the apply to my current setup

3) Fix your node_modules/fastcall/deps/ref-cmake/CMakeLists.txt to something like this:

# Copyright 2016 Gábor Mező (gabor.mezo@outlook.com)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

file(GLOB SRC ../ref/src/*.h* ../ref/src/*.c*)

add_library(ref SHARED ${SRC})

target_include_directories(ref PRIVATE
  "D:/BabylonCpp/node/node_modules/nan")

target_link_libraries (ref ${CMAKE_JS_LIB})

set_target_properties(
  ref
  PROPERTIES
  PREFIX "" 
  SUFFIX ".node")

4) npm install nan (otherwise there was no nan.h IIRC)

5) Now the cmake files are fixed and nan.h should be available, so we just need to trigger a compilation with:

D:\BabylonCpp\node\node_modules\fastcall>..\..\node_modules\.bin\cmake-js.cmd compile

After all that, require("fastcall") should work, I might make a video later of the process, just wanted to put the info out first lol

unbornchikken commented 6 years ago

Since I'm tight on schedule nowadays because of other projects, it would be really appreciated if you could make a PR from your improvements. Thanks.

kungfooman commented 6 years ago

I figured this only fails with missing npm init (and press Enter like 10 times)

In case you want to prevent this pitfall: https://github.com/cmake-js/fastcall/pull/42