Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 27 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@

## Setup

### Mac

* Set Environment Variables:
- CMAKE_PREFIX_PATH must point to your Qt directory (e.g. /Users/[USRNAME]/Qt/[QT-VERSION]/clang_64)

### Windows

Make sure you have Qt installed for the Visual Studio compiler.

### Linux (Ubuntu 17.04)

* download the Node.js headers:
```
mkdir externals
Expand All @@ -37,11 +26,35 @@ cd ../..
* then either just open CMakeLists.txt with QtCreator, configure it and press run
* or start from terminal with the following commands:


### Building the project

#### Windows

Make sure you have Qt 5.6 or later installed as well as the matching Visual Studio 2015/2017 build tools.
Adjust the generator and path to Qt cmake accordingly:

```
mkdir build
cd build
cmake .. -G "Visual Studio 15 2017 Win64" -DCMAKE_PREFIX_PATH='C:\Qt\Qt5.9.3\5.9.3\msvc2017_64\lib\cmake'
cmake --build .
```

#### Linux

```
# build project:
CMAKE_PREFIX_PATH=~/Qt/5.10.0/gcc_64/lib/cmake/Qt5 cmake .
make -j6
```

#### Mac

# run executable:
./node-embed source/demo-app/hello_world.js
* Set Environment Variables:
- CMAKE_PREFIX_PATH must point to your Qt directory (e.g. /Users/[USRNAME]/Qt/[QT-VERSION]/clang_64)

### Running the application

```
./node-embedd.exe ../source/demo-app/rss_feed.js
```
52 changes: 38 additions & 14 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
version: '{build}'
branches:
only:
- master
clone_folder: c:\projects\cmake-init
#branches:
# only:
# - master
clone_folder: c:\projects\node-embed
image:
- Visual Studio 2013
- Visual Studio 2015
- Visual Studio 2017
configuration:
- Release
Expand All @@ -18,9 +16,13 @@ environment:
# - arch: #does not work, Release|x64 not a valid target
matrix:
fast_finish: true
cache:
- C:\cache

# skip unsupported combinations
init:
# Print all env vars
- set
- set arch=
- if "%arch%"=="Win64" ( set arch= Win64)
- echo %arch%
Expand All @@ -30,23 +32,45 @@ init:
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2013" ( set generator="Visual Studio 12 2013%arch%" )
- echo %generator%

- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" ( set qt_cmake="C:\Qt\5.9.2\msvc2017_64\lib\cmake" )
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" ( set qt_cmake="C:\Qt\5.9.2\msvc2015_64\lib\cmake" )
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2013" ( set qt_cmake="C:\Qt\5.8\msvc2013_64\lib\cmake" )
- echo %qt_cmake%

before_build:
- cmd: >-
- cmd: |-
mkdir externals
cd externals
appveyor DownloadFile http://nodejs.org/dist/v9.0.0/node-v9.0.0-headers.tar.gz
7z e node-v9.0.0-headers.tar.gz
7z x node-v9.0.0-headers.tar

appveyor DownloadFile http://nodejs.org/dist/v9.0.0/node-v9.0.0.tar.gz
7z e node-v9.0.0.tar.gz
7z x node-v9.0.0.tar

cd node-v9.0.0
IF EXIST "C:\cache\binaries.7z" ( 7z x C:\cache\binaries.7z -aoa -y )
IF NOT EXIST "C:\cache\binaries.7z" ( appveyor DownloadFile https://owncloud.hpi.de/index.php/s/N6JqyFxbRJO2xtK/download -FileName node-windows.7z & 7z x node-windows.7z -aoa -y )
vcbuild.bat dll
IF NOT EXIST "C:\cache" ( mkdir C:\cache )
7z a -mx7 -t7z C:\cache\binaries.7z %Configuration%\
cd ..

cd ..

mkdir build

cd build

cmake --version
cmake .. -G %generator% -DCMAKE_PREFIX_PATH=%qt_cmake%

cmake .. -G %generator%

build:
project: c:\projects\cmake-init\build\template.sln
project: c:\projects\node-embed\build\Node-Embed.sln
verbosity: minimal
parallel: true
parallel: true
only_commits:
files:
- CMakeLists.txt
- appveyor.yml
- sources/
- source/
- cmake/
73 changes: 17 additions & 56 deletions cmake/Findnodejs.cmake
Original file line number Diff line number Diff line change
@@ -1,58 +1,19 @@

# NODEJS_FOUND
# NODEJS_INCLUDE_DIRS
# NODEJS_INCLUDE_DIR
# NODEJS_LIBUV_INCLUDE_DIR

# NODEJS_FOUND - system has the node.js library
# NODEJS_INCLUDE_DIR - the node.js include directory
# NODEJS_LIBRARY - the node.js library name
if(NODEJS_INCLUDE_DIR AND NODEJS_LIBRARY)
set(NODEJS_FIND_QUIETLY TRUE)
endif()
find_path(NODEJS_INCLUDE_DIR node.h PATHS
"${CMAKE_SOURCE_DIR}/externals/node-v9.0.0/include/node"
NO_DEFAULT_PATH
)
find_library(NODEJS_LIBRARY NAMES node libnode.lib
PATHS
"${CMAKE_SOURCE_DIR}/externals/node-v9.0.0/Release"
NO_DEFAULT_PATH
)
include(FindPackageHandleStandardArgs)

find_path(NODEJS_INCLUDE_DIR node.h
$ENV{NODEJS_HOME}
$ENV{NODEJSDIR}
$ENV{NODEJS_HOME}/src
$ENV{NODEJSDIR}/src
/usr/include/nodejs/src
/usr/local/include/nodejs/src
/usr/include
/usr/local/include
/sw/include
/usr/local/include/node
/opt/local/include
DOC "The directory where node.h resides.")

find_path(NODEJS_LIBUV_INCLUDE_DIR uv.h
$ENV{NODEJS_HOME}
$ENV{NODEJSDIR}
$ENV{NODEJS_HOME}/src
$ENV{NODEJSDIR}/src
$ENV{NODEJS_HOME}/deps/uv/include
$ENV{NODEJSDIR}/deps/uv/include
/usr/include/nodejs/deps/uv/include
/usr/local/include/nodejs/deps/uv/include
/usr/include
/usr/local/include
/sw/include
/opt/local/include
/usr/local/include/node
DOC "The directory where uv.h resides.")

find_path(NODEJS_LIBV8_INCLUDE_DIR v8.h
$ENV{NODEJS_HOME}
$ENV{NODEJSDIR}
$ENV{NODEJS_HOME}/src
$ENV{NODEJSDIR}/src
$ENV{NODEJS_HOME}/deps/v8/include
$ENV{NODEJSDIR}/deps/v8/include
/usr/include/nodejs/deps/uv/include
/usr/local/include/nodejs/deps/uv/include
/usr/include
/usr/local/include
/sw/include
/opt/local/include
/usr/local/include/node
DOC "The directory where v8.h resides.")

set(NODEJS_INCLUDE_DIRS ${NODEJS_INCLUDE_DIR} ${NODEJS_LIBUV_INCLUDE_DIR} ${NODEJS_LIBV8_INCLUDE_DIR})

find_package_handle_standard_args(NODEJS REQUIRED_VARS NODEJS_INCLUDE_DIRS)
mark_as_advanced(NODEJS_INCLUDE_DIRS)
find_package_handle_standard_args(Node DEFAULT_MSG NODEJS_INCLUDE_DIR NODEJS_LIBRARY)
mark_as_advanced(NODEJS_INCLUDE_DIR NODEJS_LIBRARY)
24 changes: 16 additions & 8 deletions source/demo-app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

find_package(Qt5 COMPONENTS Core Quick Concurrent REQUIRED)
find_package(Nodejs REQUIRED)


#
Expand Down Expand Up @@ -67,27 +68,21 @@ target_include_directories(${target}
PRIVATE
${DEFAULT_INCLUDE_DIRECTORIES}
${PROJECT_BINARY_DIR}/source/include
${PROJECT_BINARY_DIR}/externals/node-v9.0.0/include/node
${NODEJS_INCLUDE_DIR}
)


#
# Libraries
#

add_library( nodejs-lib SHARED IMPORTED)

set_target_properties( nodejs-lib
PROPERTIES IMPORTED_LOCATION
${PROJECT_BINARY_DIR}/externals/libnode.so.59 )

target_link_libraries(${target}
PRIVATE
${DEFAULT_LIBRARIES}
Qt5::Core
Qt5::Quick
Qt5::Concurrent
nodejs-lib
${NODEJS_LIBRARY}
)

#
Expand Down Expand Up @@ -139,3 +134,16 @@ install(TARGETS ${target}
RUNTIME DESTINATION ${INSTALL_BIN} COMPONENT runtime
BUNDLE DESTINATION ${INSTALL_BIN} COMPONENT runtime
)

if(WIN32)
# Copy node.dll
add_custom_command(TARGET ${target} POST_BUILD # Adds a post-build event to MyTest
COMMAND ${CMAKE_COMMAND} -E copy_if_different # which executes "cmake - E copy_if_different..."
${CMAKE_SOURCE_DIR}/externals/node-v9.0.0/Release/node.dll # <--this is in-file
$<TARGET_FILE_DIR:${target}>) # <--this is out-file path

# Copy Qt dependencies
find_program(WINDEPLOYQT_EXECUTABLE NAMES windeployqt HINTS ${Qt5_DIR}/../../../ ENV QTDIR PATH_SUFFIXES bin)
add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${WINDEPLOYQT_EXECUTABLE} --no-patchqt --qmldir ${CMAKE_SOURCE_DIR}/source/demo-app $<TARGET_FILE:${target}>)
endif()