-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
69 lines (54 loc) · 2.09 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
cmake_minimum_required(VERSION 3.1)
project(audioworklet)
IF (WIN32)
# Change runtime library to MD
set(CMAKE_CXX_FLAGS_RELEASE "/MD")
set(CMAKE_CXX_FLAGS_DEBUG "/MDd")
# Ignore all C++17 deprecation warnings on windows and unsafe warnings
add_definitions(-D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
ENDIF()
# Use install RPATH
IF (UNIX)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
set(CMAKE_INSTALL_NAME_DIR "@rpath/")
ENDIF()
# Set RPATH as origin in Linux
IF (UNIX AND NOT APPLE)
set(CMAKE_INSTALL_RPATH "$ORIGIN")
ENDIF()
# Use @loader_path as RPATH in macOS
IF (APPLE)
set(CMAKE_MACOSX_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "@loader_path")
ENDIF()
set(BUILD_TESTS OFF CACHE BOOL "test")
set(BUILD_TOOLS OFF CACHE BOOL "test")
set(BUILD_SHARED_LIBS ON CACHE BOOL "test")
# set(BUILD_RUST_LIBS ON CACHE BOOL "test")
add_subdirectory(vendor/cubeb cubeb)
include_directories(vendor/cubeb)
# Set C++14 standard
set (CMAKE_CXX_STANDARD 14)
# Get all the cpp files for audioworklet
file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.c" "src/*.h")
# Add audioworklet as a library
add_library(${PROJECT_NAME} SHARED ${SOURCES} ${CMAKE_JS_SRC})
# Remove lib prefix + add node suffix
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
# Essential include files to build a node addon,
# You should add this line in every CMake.js based project
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC})
add_definitions(-DNAPI_VERSION=4)
# Include N-API wrappers
execute_process(COMMAND node -p "require('node-addon-api').include"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE NODE_ADDON_API_DIR
)
string(REPLACE "\n" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
string(REPLACE "\"" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
target_include_directories(${PROJECT_NAME} PRIVATE ${NODE_ADDON_API_DIR})
# Compile the library
target_link_libraries(${PROJECT_NAME} ${OPENSSL_LIBS} ${CMAKE_JS_LIB} cubeb)