зеркало из https://github.com/microsoft/napajs.git
resolve napajs_inc/napajs_lib by build.paths (#57)
* resolve napajs_inc/napajs_lib by build.paths
This commit is contained in:
Родитель
406a6f3d9d
Коммит
bcb87d368a
|
@ -5,18 +5,22 @@ The source codes can be organized as the structure below.
|
|||
+-- napa-module-example
|
||||
+-- inc
|
||||
| +-- example.h
|
||||
+-- src
|
||||
| +-- example.cpp
|
||||
| +-- addon.h
|
||||
| +-- addon.cpp
|
||||
+-- lib
|
||||
| +-- example.ts
|
||||
| +-- tsconfig.json
|
||||
+-- napa
|
||||
| +-- addon.cpp
|
||||
| +-- CMakeLists.txt (cmake specific)
|
||||
| +-- example-wrap.cpp
|
||||
| +-- example-wrap.h
|
||||
+-- src
|
||||
| +-- CMakeLists.txt (cmake specific)
|
||||
| +-- example.cpp
|
||||
+-- test
|
||||
| +-- test.ts
|
||||
| +-- tsconfig.json
|
||||
+-- binding.gyp (when build configuration is given in node-gyp)
|
||||
+-- CMakeLists.txt (when build configuration is given in cmake-js)
|
||||
+-- binding.gyp (gyp specific)
|
||||
+-- CMakeLists.txt (cmake specific)
|
||||
+-- package.json
|
||||
+-- README.md
|
||||
```
|
||||
|
|
|
@ -1,23 +1,7 @@
|
|||
{
|
||||
"variables": {
|
||||
"napajs_root": "<!(node -e \" \
|
||||
var path = require('path'); \
|
||||
process.stdout.write(path.resolve(path.dirname(require.resolve('napajs')), '..')); \
|
||||
\")",
|
||||
'conditions': [
|
||||
['OS=="win"', {
|
||||
"library_prefix": "",
|
||||
"library_suffix": ".lib"
|
||||
}],
|
||||
['OS=="linux"', {
|
||||
"library_prefix": "lib",
|
||||
"library_suffix": ".dylib"
|
||||
}],
|
||||
['OS=="max"', {
|
||||
"library_prefix": "lib",
|
||||
"library_suffix": ".so"
|
||||
}]
|
||||
]
|
||||
"napajs_lib": "<!(node -e \"require('napajs/build').paths.lib\")",
|
||||
"napajs_inc": "<!(node -e \"require('napajs/build').paths.inc\")"
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
|
@ -25,27 +9,24 @@
|
|||
"type": "<(library)",
|
||||
"product_extension": "",
|
||||
"product_dir": "<(PRODUCT_DIR)/../../bin",
|
||||
"sources": [ "src/addon.cpp"],
|
||||
"sources": [ "napa/addon.cpp"],
|
||||
"defines": [
|
||||
"NAPA_BINDING_EXPORTS",
|
||||
"BUILDING_NODE_EXTENSION"
|
||||
],
|
||||
"include_dirs": ["<(napajs_root)/inc"]
|
||||
"include_dirs": ["<(napajs_inc)"]
|
||||
},
|
||||
{
|
||||
"target_name": "addon.napa",
|
||||
"type": "<(library)",
|
||||
"product_extension": "",
|
||||
"product_dir": "<(PRODUCT_DIR)/../../bin",
|
||||
"sources": [ "src/addon.cpp" ],
|
||||
"sources": [ "napa/addon.cpp" ],
|
||||
"defines": [
|
||||
"NAPA_EXPORTS",
|
||||
"NAPA_BINDING_EXPORTS",
|
||||
"BUILDING_NAPA_EXTENSION"
|
||||
],
|
||||
"include_dirs": ["<(napajs_root)/inc"],
|
||||
"include_dirs": ["<(napajs_inc)"],
|
||||
"link_settings": {
|
||||
"libraries": ["<(napajs_root)/bin/<(library_prefix)napa<(library_suffix)"]
|
||||
"libraries": ["<(napajs_lib)"]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
"markdown-table": "1.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"napajs": ">= 0.1.0"
|
||||
"napajs": ">= 0.1.2"
|
||||
},
|
||||
"scripts": {
|
||||
"install": "node-gyp configure && node-gyp build",
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
// Licensed under the MIT license.
|
||||
|
||||
let assert = require('assert');
|
||||
import * as path from "path";
|
||||
let asyncNumberDir: string = path.resolve(__dirname, '..');
|
||||
let asyncNumber = require(asyncNumberDir);
|
||||
let asyncNumber = require('..');
|
||||
let napa = require('napajs');
|
||||
let zone = napa.zone.create('zone');
|
||||
|
||||
|
@ -46,9 +44,9 @@ describe('Test suite for async-number', function() {
|
|||
});
|
||||
|
||||
it('change number asynchronously on separate thread in napa zone', () => {
|
||||
return zone.execute((asyncNumberDir: string) => {
|
||||
return zone.execute(() => {
|
||||
let assert = require('assert');
|
||||
let asyncNumber = require(asyncNumberDir);
|
||||
let asyncNumber = require('..');
|
||||
let now = asyncNumber.now();
|
||||
assert.equal(now, 0);
|
||||
|
||||
|
@ -61,13 +59,13 @@ describe('Test suite for async-number', function() {
|
|||
});
|
||||
|
||||
asyncNumber.increaseSync(3, (value: number) => {} );
|
||||
}, [asyncNumberDir]);
|
||||
});
|
||||
});
|
||||
|
||||
it('change number synchronously on current thread in napa zone', () => {
|
||||
zone.execute((asyncNumberDir: string) => {
|
||||
zone.execute(() => {
|
||||
let assert = require('assert');
|
||||
let asyncNumber = require(asyncNumberDir);
|
||||
let asyncNumber = require('..');
|
||||
let now = asyncNumber.now();
|
||||
assert.equal(now, 0);
|
||||
|
||||
|
@ -84,6 +82,6 @@ describe('Test suite for async-number', function() {
|
|||
assert.equal(now, 3);
|
||||
asyncNumber.increaseSync(3, (value: number) => {} );
|
||||
return 1;
|
||||
}, [asyncNumberDir]);
|
||||
});
|
||||
});
|
||||
})
|
||||
|
|
|
@ -1,23 +1,7 @@
|
|||
{
|
||||
"variables": {
|
||||
"napajs_root": "<!(node -e \" \
|
||||
var path = require('path'); \
|
||||
process.stdout.write(path.resolve(path.dirname(require.resolve('napajs')), '..')); \
|
||||
\")",
|
||||
'conditions': [
|
||||
['OS=="win"', {
|
||||
"library_prefix": "",
|
||||
"library_suffix": ".lib"
|
||||
}],
|
||||
['OS=="linux"', {
|
||||
"library_prefix": "lib",
|
||||
"library_suffix": ".dylib"
|
||||
}],
|
||||
['OS=="max"', {
|
||||
"library_prefix": "lib",
|
||||
"library_suffix": ".so"
|
||||
}]
|
||||
]
|
||||
"napajs_lib": "<!(node -e \"require('napajs/build').paths.lib\")",
|
||||
"napajs_inc": "<!(node -e \"require('napajs/build').paths.inc\")"
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
|
@ -25,27 +9,24 @@
|
|||
"type": "<(library)",
|
||||
"product_extension": "",
|
||||
"product_dir": "<(PRODUCT_DIR)/../../bin",
|
||||
"sources": [ "src/addon.cpp"],
|
||||
"sources": [ "napa/addon.cpp"],
|
||||
"defines": [
|
||||
"NAPA_BINDING_EXPORTS",
|
||||
"BUILDING_NODE_EXTENSION"
|
||||
],
|
||||
"include_dirs": ["<(napajs_root)/inc"]
|
||||
"include_dirs": ["<(napajs_inc)"]
|
||||
},
|
||||
{
|
||||
"target_name": "addon.napa",
|
||||
"type": "<(library)",
|
||||
"product_extension": "",
|
||||
"product_dir": "<(PRODUCT_DIR)/../../bin",
|
||||
"sources": [ "src/addon.cpp" ],
|
||||
"sources": [ "napa/addon.cpp" ],
|
||||
"defines": [
|
||||
"NAPA_EXPORTS",
|
||||
"NAPA_BINDING_EXPORTS",
|
||||
"BUILDING_NAPA_EXTENSION"
|
||||
],
|
||||
"include_dirs": ["<(napajs_root)/inc"],
|
||||
"include_dirs": ["<(napajs_inc)"],
|
||||
"link_settings": {
|
||||
"libraries": ["<(napajs_root)/bin/<(library_prefix)napa<(library_suffix)"]
|
||||
"libraries": ["<(napajs_lib)"]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
"markdown-table": "1.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"napajs": ">= 0.1.0"
|
||||
"napajs": ">= 0.1.2"
|
||||
},
|
||||
"scripts": {
|
||||
"install": "node-gyp configure && node-gyp build",
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
// Licensed under the MIT license.
|
||||
|
||||
let assert = require('assert');
|
||||
import * as path from "path";
|
||||
let helloWorldDir: string = path.resolve(__dirname, '..');
|
||||
let helloWorld = require(helloWorldDir);
|
||||
let helloWorld = require('..');
|
||||
let napa = require('napajs');
|
||||
let zone = napa.zone.create('zone');
|
||||
|
||||
|
@ -17,11 +15,11 @@ describe('Test suite for hello-word', function() {
|
|||
});
|
||||
|
||||
it('prints the string "world" in napa zone', function() {
|
||||
return zone.execute((helloWorldDir: string) => {
|
||||
let helloWorld = require(helloWorldDir);
|
||||
return zone.execute(() => {
|
||||
let helloWorld = require('..');
|
||||
let result: string = helloWorld.hello();
|
||||
return result;
|
||||
}, [helloWorldDir]).then((result : any) => {
|
||||
}).then((result : any) => {
|
||||
assert.equal(result.value, 'world');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -19,89 +19,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||
set(CMAKE_VISIBILITY_INLINES_HIDDEN)
|
||||
|
||||
# Prefix an suffix of Library name for different OS.
|
||||
if (WIN32)
|
||||
set(LIBRARY_PREFIX "")
|
||||
set(LIBRARY_SUFFIX ".lib")
|
||||
elseif (APPLE)
|
||||
set(LIBRARY_PREFIX "lib")
|
||||
set(LIBRARY_SUFFIX ".dylib")
|
||||
else()
|
||||
set(LIBRARY_PREFIX "lib")
|
||||
set(LIBRARY_SUFFIX ".so")
|
||||
endif()
|
||||
# Build plus-number library
|
||||
add_subdirectory(src)
|
||||
|
||||
execute_process(COMMAND node -e
|
||||
"var path = require('path'); process.stdout.write(path.resolve(path.dirname(require.resolve('napajs')), '..'));"
|
||||
RESULT_VARIABLE ERR
|
||||
OUTPUT_VARIABLE NAPAJS_ROOT)
|
||||
if(ERR)
|
||||
message(FATAL_ERROR "Failed to get NAPAJS_ROOT")
|
||||
endif(ERR)
|
||||
|
||||
#######################################################################################
|
||||
# Build plus-number library.
|
||||
set(LIBRARY_TARGET_NAME "plus-number")
|
||||
|
||||
# The generated library
|
||||
add_library(${LIBRARY_TARGET_NAME} SHARED "src/plus-number.cpp")
|
||||
|
||||
# Include directories
|
||||
target_include_directories(${LIBRARY_TARGET_NAME} PRIVATE inc)
|
||||
|
||||
# Compiler definitions
|
||||
target_compile_definitions(${LIBRARY_TARGET_NAME} PRIVATE NAPA_EXAMPLE_API)
|
||||
|
||||
#######################################################################################
|
||||
# Build napa addon.
|
||||
set(NAPA_ADDON_TARGET_NAME "${PROJECT_NAME}.napa")
|
||||
|
||||
# The generated library
|
||||
add_library(${NAPA_ADDON_TARGET_NAME} SHARED "src/addon.cpp")
|
||||
|
||||
set_target_properties(${NAPA_ADDON_TARGET_NAME} PROPERTIES PREFIX "" SUFFIX "")
|
||||
|
||||
# Include directories
|
||||
target_include_directories(${NAPA_ADDON_TARGET_NAME} PRIVATE
|
||||
inc
|
||||
${CMAKE_JS_INC}
|
||||
${NAPAJS_ROOT}/inc)
|
||||
|
||||
# Compiler definitions
|
||||
target_compile_definitions(${NAPA_ADDON_TARGET_NAME} PRIVATE
|
||||
NAPA_EXPORTS
|
||||
NAPA_BINDING_EXPORTS
|
||||
BUILDING_NAPA_EXTENSION)
|
||||
|
||||
# Link libraries
|
||||
target_link_libraries(${NAPA_ADDON_TARGET_NAME} PRIVATE
|
||||
plus-number
|
||||
${CMAKE_JS_LIB}
|
||||
${NAPAJS_ROOT}/bin/${LIBRARY_PREFIX}napa${LIBRARY_SUFFIX})
|
||||
|
||||
#######################################################################################
|
||||
if (CMAKE_JS_VERSION)
|
||||
# Build napa addon for node.
|
||||
set(NODE_ADDON_TARGET_NAME "${PROJECT_NAME}.node")
|
||||
|
||||
# The generated library
|
||||
add_library(${NODE_ADDON_TARGET_NAME} SHARED "src/addon.cpp")
|
||||
|
||||
set_target_properties(${NODE_ADDON_TARGET_NAME} PROPERTIES PREFIX "" SUFFIX "")
|
||||
|
||||
# Include directories
|
||||
target_include_directories(${NODE_ADDON_TARGET_NAME} PRIVATE
|
||||
inc
|
||||
${CMAKE_JS_INC}
|
||||
${NAPAJS_ROOT}/inc)
|
||||
|
||||
# Compiler definitions
|
||||
target_compile_definitions(${NODE_ADDON_TARGET_NAME} PRIVATE
|
||||
NAPA_BINDING_EXPORTS
|
||||
BUILDING_NODE_EXTENSION)
|
||||
|
||||
# Link libraries
|
||||
target_link_libraries(${NODE_ADDON_TARGET_NAME} PRIVATE
|
||||
plus-number
|
||||
${CMAKE_JS_LIB})
|
||||
endif()
|
||||
# Build napa addon
|
||||
add_subdirectory(napa)
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace demo {
|
|||
|
||||
## Wrapper class
|
||||
|
||||
*addon.h* declares the wrapper class inherited from *NAPA_OBJECTWRAP* as follows,
|
||||
*plus-number-wrap.h* declares the wrapper class inherited from *NAPA_OBJECTWRAP* as follows,
|
||||
|
||||
```h
|
||||
#include <napa/module.h>
|
||||
|
@ -85,11 +85,10 @@ namespace demo {
|
|||
} // namespace napa
|
||||
```
|
||||
|
||||
*addon.cpp* implements each functions as follows,
|
||||
|
||||
*plus-number-wrap.cpp* implements each functions as follows,
|
||||
|
||||
```cpp
|
||||
#include "addon.h"
|
||||
#include "plus-number-wrap.h"
|
||||
|
||||
using namespace napa::demo;
|
||||
using namespace v8;
|
||||
|
@ -125,7 +124,7 @@ void PlusNumberWrap::NewInstance(const v8::FunctionCallbackInfo<v8::Value>& args
|
|||
const int argc = 1;
|
||||
Local<Value> argv[argc] = { args[0] };
|
||||
|
||||
auto constructor = NAPA_GET_PERSISTENT_CONSTRUCTOR(_exportName);
|
||||
auto constructor = NAPA_GET_PERSISTENT_CONSTRUCTOR(_exportName, PlusNumberWrap);
|
||||
auto context = isolate->GetCurrentContext();
|
||||
auto instance = constructor->NewInstance(context, argc, argv).ToLocalChecked();
|
||||
|
||||
|
@ -171,6 +170,15 @@ void PlusNumberWrap::Add(const FunctionCallbackInfo<Value>& args) {
|
|||
|
||||
args.GetReturnValue().Set(Number::New(isolate, value));
|
||||
}
|
||||
```
|
||||
|
||||
*addon.cpp* implements the addon as below,
|
||||
|
||||
```cpp
|
||||
#include "plus-number-wrap.h"
|
||||
|
||||
using namespace napa::demo;
|
||||
using namespace v8;
|
||||
|
||||
void CreatePlusNumber(const FunctionCallbackInfo<Value>& args) {
|
||||
PlusNumberWrap::NewInstance(args);
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
execute_process(COMMAND node -e "require('napajs/build').paths.inc" RESULT_VARIABLE ERR OUTPUT_VARIABLE NAPAJS_INC)
|
||||
if(ERR)
|
||||
message(FATAL_ERROR "Failed to resolve napa include directory")
|
||||
endif(ERR)
|
||||
|
||||
execute_process(COMMAND node -e "require('napajs/build').paths.lib" RESULT_VARIABLE ERR OUTPUT_VARIABLE NAPAJS_LIB)
|
||||
if(ERR)
|
||||
message(FATAL_ERROR "Failed to resolve napa library path")
|
||||
endif(ERR)
|
||||
|
||||
#######################################################################################
|
||||
# Build napa addon.
|
||||
set(NAPA_ADDON_TARGET_NAME "${PROJECT_NAME}.napa")
|
||||
|
||||
# The generated library
|
||||
add_library(${NAPA_ADDON_TARGET_NAME} SHARED "addon.cpp" "plus-number-wrap.cpp")
|
||||
|
||||
set_target_properties(${NAPA_ADDON_TARGET_NAME} PROPERTIES PREFIX "" SUFFIX "")
|
||||
|
||||
# Include directories
|
||||
target_include_directories(${NAPA_ADDON_TARGET_NAME} PRIVATE
|
||||
../inc
|
||||
${CMAKE_JS_INC}
|
||||
${NAPAJS_INC})
|
||||
|
||||
# Compiler definitions
|
||||
target_compile_definitions(${NAPA_ADDON_TARGET_NAME} PRIVATE
|
||||
BUILDING_NAPA_EXTENSION)
|
||||
|
||||
# Link libraries
|
||||
target_link_libraries(${NAPA_ADDON_TARGET_NAME} PRIVATE
|
||||
plus-number
|
||||
${CMAKE_JS_LIB}
|
||||
${NAPAJS_LIB})
|
||||
|
||||
#######################################################################################
|
||||
# Build napa addon for node.
|
||||
set(NODE_ADDON_TARGET_NAME "${PROJECT_NAME}.node")
|
||||
|
||||
# The generated library
|
||||
add_library(${NODE_ADDON_TARGET_NAME} SHARED "addon.cpp" "plus-number-wrap.cpp")
|
||||
|
||||
set_target_properties(${NODE_ADDON_TARGET_NAME} PROPERTIES PREFIX "" SUFFIX "")
|
||||
|
||||
# Include directories
|
||||
target_include_directories(${NODE_ADDON_TARGET_NAME} PRIVATE
|
||||
../inc
|
||||
${CMAKE_JS_INC}
|
||||
${NAPAJS_INC})
|
||||
|
||||
# Compiler definitions
|
||||
target_compile_definitions(${NODE_ADDON_TARGET_NAME} PRIVATE
|
||||
BUILDING_NODE_EXTENSION)
|
||||
|
||||
# Link libraries
|
||||
target_link_libraries(${NODE_ADDON_TARGET_NAME} PRIVATE
|
||||
plus-number
|
||||
${CMAKE_JS_LIB})
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
#include "plus-number-wrap.h"
|
||||
|
||||
using namespace napa::demo;
|
||||
using namespace v8;
|
||||
|
||||
void CreatePlusNumber(const FunctionCallbackInfo<Value>& args) {
|
||||
PlusNumberWrap::NewInstance(args);
|
||||
}
|
||||
|
||||
void InitAll(Local<Object> exports) {
|
||||
PlusNumberWrap::Init();
|
||||
|
||||
NAPA_SET_METHOD(exports, "createPlusNumber", CreatePlusNumber);
|
||||
}
|
||||
|
||||
NAPA_MODULE(addon, InitAll);
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
#include "addon.h"
|
||||
#include "plus-number-wrap.h"
|
||||
|
||||
using namespace napa::demo;
|
||||
using namespace v8;
|
||||
|
@ -83,15 +83,3 @@ void PlusNumberWrap::Add(const FunctionCallbackInfo<Value>& args) {
|
|||
|
||||
args.GetReturnValue().Set(Number::New(isolate, value));
|
||||
}
|
||||
|
||||
void CreatePlusNumber(const FunctionCallbackInfo<Value>& args) {
|
||||
PlusNumberWrap::NewInstance(args);
|
||||
}
|
||||
|
||||
void InitAll(Local<Object> exports) {
|
||||
PlusNumberWrap::Init();
|
||||
|
||||
NAPA_SET_METHOD(exports, "createPlusNumber", CreatePlusNumber);
|
||||
}
|
||||
|
||||
NAPA_MODULE(addon, InitAll);
|
|
@ -14,7 +14,7 @@
|
|||
"markdown-table": "1.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"napajs": ">= 0.1.0"
|
||||
"napajs": ">= 0.1.2"
|
||||
},
|
||||
"scripts": {
|
||||
"install": "cmake-js compile",
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
# Build plus-number library.
|
||||
set(TARGET_NAME "plus-number")
|
||||
|
||||
# The generated library
|
||||
add_library(${TARGET_NAME} SHARED "plus-number.cpp")
|
||||
|
||||
# Include directories
|
||||
target_include_directories(${TARGET_NAME} PRIVATE ../inc)
|
||||
|
||||
# Compiler definitions
|
||||
target_compile_definitions(${TARGET_NAME} PRIVATE NAPA_EXAMPLE_API)
|
|
@ -2,9 +2,7 @@
|
|||
// Licensed under the MIT license.
|
||||
|
||||
let assert = require('assert');
|
||||
import * as path from "path";
|
||||
let plusNumberDir: string = path.resolve(__dirname, '..');
|
||||
let plusNumber = require(plusNumberDir);
|
||||
let plusNumber = require('..');
|
||||
let napa = require('napajs');
|
||||
let zone = napa.zone.create('zone');
|
||||
|
||||
|
@ -28,24 +26,24 @@ describe('Test suite for plus-number', function() {
|
|||
});
|
||||
|
||||
it('adds a given value in napa zone', function() {
|
||||
return zone.execute((plusNumberDir: string) => {
|
||||
let plusNumber = require(plusNumberDir);
|
||||
return zone.execute(() => {
|
||||
let plusNumber = require('..');
|
||||
let po = plusNumber.createPlusNumber(3);
|
||||
let result: number = po.add(4);
|
||||
return result;
|
||||
}, [plusNumberDir])
|
||||
})
|
||||
.then((result: any) => {
|
||||
assert.equal(result.value, 7);
|
||||
});
|
||||
});
|
||||
|
||||
it('adds a given value in node zone', function() {
|
||||
return napa.zone.node.execute((plusNumberDir: string) => {
|
||||
let plusNumber = require(plusNumberDir);
|
||||
return napa.zone.node.execute(() => {
|
||||
let plusNumber = require('..');
|
||||
let po = plusNumber.createPlusNumber(3);
|
||||
let result: number = po.add(4);
|
||||
return result;
|
||||
}, [plusNumberDir])
|
||||
})
|
||||
.then((result: any) => {
|
||||
assert.equal(result.value, 7);
|
||||
});
|
||||
|
|
|
@ -19,32 +19,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||
set(CMAKE_VISIBILITY_INLINES_HIDDEN)
|
||||
|
||||
# Prefix an suffix of Library name for different OS.
|
||||
if (WIN32)
|
||||
set(LIBRARY_PREFIX "")
|
||||
set(LIBRARY_SUFFIX ".lib")
|
||||
elseif (APPLE)
|
||||
set(LIBRARY_PREFIX "lib")
|
||||
set(LIBRARY_SUFFIX ".dylib")
|
||||
else()
|
||||
set(LIBRARY_PREFIX "lib")
|
||||
set(LIBRARY_SUFFIX ".so")
|
||||
endif()
|
||||
|
||||
execute_process(COMMAND node -e
|
||||
"var path = require('path'); process.stdout.write(path.resolve(path.dirname(require.resolve('napajs')), '..'));"
|
||||
RESULT_VARIABLE ERR
|
||||
OUTPUT_VARIABLE NAPAJS_ROOT)
|
||||
if(ERR)
|
||||
message(FATAL_ERROR "Failed to get NAPAJS_ROOT")
|
||||
endif(ERR)
|
||||
|
||||
file(GLOB LIBRARY-FILES "../bin/*plus-number.*")
|
||||
file(COPY ${LIBRARY-FILES} DESTINATION ${PROJECT_SOURCE_DIR}/bin/)
|
||||
|
||||
# Files to compile
|
||||
file(GLOB SOURCE_FILES
|
||||
"main.cpp")
|
||||
file(GLOB SOURCE_FILES "main.cpp")
|
||||
|
||||
# The executable name
|
||||
set(TARGET_NAME "library-test")
|
||||
|
@ -55,6 +34,7 @@ add_executable(${TARGET_NAME} ${SOURCE_FILES})
|
|||
# Include directories
|
||||
target_include_directories(${TARGET_NAME} PRIVATE ../inc)
|
||||
|
||||
find_library(PLUS_NUMBER_LIBRARY NAMES plus-number PATHS ${PROJECT_SOURCE_DIR}/bin)
|
||||
|
||||
# Link libraries
|
||||
target_link_libraries(${TARGET_NAME} PRIVATE
|
||||
${PROJECT_SOURCE_DIR}/bin/${LIBRARY_PREFIX}plus-number${LIBRARY_SUFFIX})
|
||||
target_link_libraries(${TARGET_NAME} PRIVATE ${PLUS_NUMBER_LIBRARY})
|
||||
|
|
Загрузка…
Ссылка в новой задаче