-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
100 lines (75 loc) · 3.15 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
cmake_minimum_required(VERSION 3.1.3)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
#------------------- Core --------------------
project(Interpreter-Core)
set(INTERPRETER_COVERAGE FALSE CACHE BOOL "Enable/Disable test coverage reporting")
add_subdirectory(src/core)
add_library(${PROJECT_NAME} ${core_src})
target_include_directories(${PROJECT_NAME} PUBLIC src/core)
if (INTERPRETER_COVERAGE)
target_compile_options(${PROJECT_NAME} PRIVATE --coverage -O0 -g)
target_link_libraries(${PROJECT_NAME} PRIVATE --coverage)
endif()
if(${CMAKE_VERSION} VERSION_GREATER "3.8.0")
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src/core
PREFIX "core"
FILES ${core_src})
endif()
#---------------- custom build types -------------
set(CMAKE_CXX_FLAGS_ADDRESSSANITIZER
"${CMAKE_CXX_FLAGS_DEBUG} -Wall -fsanitize=address -fno-omit-frame-pointer"
CACHE STRING
"Compiler Flags used when running a build with the adress sanitizer"
FORCE)
set(CMAKE_EXE_LINKER_FLAGS_MYRELEASE
"${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fsanitize=address"
CACHE STRING
"Linker Flags used when running a build with the address sanitizer"
FORCE)
set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel AddressSanitizer"
FORCE)
message("Generated with build type: ${CMAKE_BUILD_TYPE}")
#------------------- Tests -------------------
set(INTERPRETER_TESTS FALSE CACHE BOOL "Enable/Disable build of test executable")
if(INTERPRETER_TESTS)
message(STATUS "------------- Building tests.... ------------")
include(googletest-download.CMakeLists.txt)
project(Interpreter-Tests)
add_subdirectory(src/tests)
add_executable(${PROJECT_NAME} ${tests_src})
target_include_directories(${PROJECT_NAME} PUBLIC src/tests)
target_link_libraries(${PROJECT_NAME} PUBLIC gtest_main Interpreter-Core)
if (INTERPRETER_COVERAGE)
target_compile_options(${PROJECT_NAME} PRIVATE --coverage -O0 -g)
target_link_libraries(${PROJECT_NAME} PRIVATE --coverage)
endif()
if(${CMAKE_VERSION} VERSION_GREATER "3.8.0")
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src/tests
PREFIX "tests"
FILES ${tests_src})
endif()
endif()
#----------------- nan Adapter -------------
set(INTERPRETER_NAN FALSE CACHE BOOL "Only enable, if built via cmake-js")
if(INTERPRETER_NAN)
message(STATUS "------------ Building nan adapter... ---------")
project(InterpreterNan)
add_subdirectory(src/nan)
add_library(${PROJECT_NAME} SHARED ${nan_src})
target_include_directories(${PROJECT_NAME} PUBLIC src/nan)
if(${CMAKE_VERSION} VERSION_GREATER "3.8.0")
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src/nan
PREFIX "nan"
FILES ${nan_src})
endif()
# Gives our library file a .node extension without any "lib" prefix
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})
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})
target_link_libraries(${PROJECT_NAME} Interpreter-Core)
endif()