1
- cmake_minimum_required (VERSION 3.1 )
1
+ cmake_minimum_required (VERSION 3.12 )
2
2
3
- project (v8pp VERSION 1.7.0 LANGUAGES CXX)
4
-
5
- find_package (V8 CONFIG REQUIRED)
3
+ project (v8pp
4
+ VERSION 1.7.0
5
+ DESCRIPTION "Bind C++ functions and classes into V8 JavaScript engine"
6
+ HOMEPAGE_URL https://github.com/pmed/v8pp
7
+ LANGUAGES CXX
8
+ )
6
9
7
10
set (CMAKE_CXX_STANDARD 14)
8
11
set (CMAKE_CXX_EXTENSIONS OFF )
@@ -15,163 +18,10 @@ set(V8PP_HEADER_ONLY 0 CACHE BOOL "Header-only library")
15
18
set (V8PP_ISOLATE_DATA_SLOT 0 CACHE STRING "v8::Isolate data slot number, used in v8pp for shared data" )
16
19
set (V8PP_PLUGIN_INIT_PROC_NAME "v8pp_module_init" CACHE STRING "v8pp plugin initialization procedure name" )
17
20
set (V8PP_PLUGIN_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX} CACHE STRING "v8pp plugin filename suffix" )
18
- set (V8PP_WITH_TESTS 1 CACHE BOOL "build with tests" )
19
-
20
- configure_file (v8pp/config.hpp.in v8pp/config.hpp)
21
-
22
- set (V8PP_HEADERS
23
- ${CMAKE_SOURCE_DIR} /v8pp/call_from_v8.hpp
24
- ${CMAKE_SOURCE_DIR} /v8pp/call_v8.hpp
25
- ${CMAKE_SOURCE_DIR} /v8pp/class.hpp
26
- ${CMAKE_BINARY_DIR} /v8pp/config.hpp
27
- ${CMAKE_SOURCE_DIR} /v8pp/context.hpp
28
- ${CMAKE_SOURCE_DIR} /v8pp/convert.hpp
29
- ${CMAKE_SOURCE_DIR} /v8pp/function.hpp
30
- ${CMAKE_SOURCE_DIR} /v8pp/json.hpp
31
- ${CMAKE_SOURCE_DIR} /v8pp/module.hpp
32
- ${CMAKE_SOURCE_DIR} /v8pp/object.hpp
33
- ${CMAKE_SOURCE_DIR} /v8pp/property.hpp
34
- ${CMAKE_SOURCE_DIR} /v8pp/ptr_traits.hpp
35
- ${CMAKE_SOURCE_DIR} /v8pp/throw_ex.hpp
36
- ${CMAKE_SOURCE_DIR} /v8pp/utility.hpp
37
- ${CMAKE_SOURCE_DIR} /v8pp/version .hpp
38
- )
39
-
40
- if (V8PP_HEADER_ONLY)
41
- set (V8PP_SOURCES
42
- ${CMAKE_SOURCE_DIR} /v8pp/class.ipp
43
- ${CMAKE_SOURCE_DIR} /v8pp/json.ipp
44
- ${CMAKE_SOURCE_DIR} /v8pp/throw_ex.ipp
45
- ${CMAKE_SOURCE_DIR} /v8pp/version .ipp
46
- )
47
- else ()
48
- set (V8PP_SOURCES
49
- ${CMAKE_SOURCE_DIR} /v8pp/class.cpp
50
- ${CMAKE_SOURCE_DIR} /v8pp/context.cpp
51
- ${CMAKE_SOURCE_DIR} /v8pp/convert.cpp
52
- ${CMAKE_SOURCE_DIR} /v8pp/json.cpp
53
- ${CMAKE_SOURCE_DIR} /v8pp/throw_ex.cpp
54
- ${CMAKE_SOURCE_DIR} /v8pp/version .cpp
55
- )
56
- endif ()
57
-
58
- #set(CMAKE_CXX_RTTI OFF)
59
- if (MSVC )
60
- set (V8PP_COMPILE_OPTIONS /GR- /EHsc /permissive- /W4)
61
- # disable specific warnings
62
- list (APPEND V8PP_COMPILE_OPTIONS /wd4190)
63
- # set warning level 3 for system headers
64
- list (APPEND V8PP_COMPILE_OPTIONS /experimental:external /external:anglebrackets /external:W3)
65
- else ()
66
- set (V8PP_COMPILE_OPTIONS -fno-rtti -Wall -Wextra -Wpedantic)
67
- endif ()
68
-
69
- if (V8PP_HEADER_ONLY)
70
- add_library (v8pp INTERFACE )
71
- target_sources (v8pp INTERFACE ${V8PP_HEADERS} ${V8PP_SOURCES} )
72
- target_compile_options (v8pp INTERFACE ${V8PP_COMPILE_OPTIONS} )
73
- target_include_directories (v8pp INTERFACE ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR} )
74
- target_include_directories (v8pp SYSTEM INTERFACE ${V8_INCLUDE_DIR} )
75
- target_link_libraries (v8pp INTERFACE V8::V8)
76
- else ()
77
- add_library (v8pp ${V8PP_HEADERS} ${V8PP_SOURCES} )
78
- target_compile_options (v8pp PRIVATE ${V8PP_COMPILE_OPTIONS} )
79
- target_include_directories (v8pp PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR} )
80
- target_include_directories (v8pp SYSTEM PUBLIC ${V8_INCLUDE_DIR} )
81
- target_link_libraries (v8pp PUBLIC V8::V8)
82
- endif ()
83
-
84
- #source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${V8PP_HEADERS} ${V8PP_SOURCES})
85
-
86
- if (BUILD_SHARED_LIBS )
87
- if (NOT V8PP_HEADER_ONLY)
88
- target_link_libraries (v8pp PUBLIC ${CMAKE_DL_LIBS} )
89
- endif ()
90
21
91
- add_library (console MODULE plugins/console.cpp)
92
- set_target_properties (console PROPERTIES PREFIX "" )
93
- target_link_libraries (console v8pp)
94
-
95
- add_library (file MODULE plugins/file.cpp)
96
- set_target_properties (file PROPERTIES PREFIX "" )
97
- target_link_libraries (file v8pp)
98
- endif ()
99
-
100
-
101
- if (V8PP_WITH_TESTS)
22
+ add_subdirectory (v8pp)
23
+ add_subdirectory (plugins)
24
+ if (BUILD_TESTING)
102
25
enable_testing ()
103
- add_executable (v8pp_test
104
- test /main.cpp
105
- test /test .hpp
106
- test /test_call_from_v8.cpp
107
- test /test_call_v8.cpp
108
- test /test_class.cpp
109
- test /test_context.cpp
110
- test /test_convert.cpp
111
- test /test_factory.cpp
112
- test /test_function.cpp
113
- test /test_json.cpp
114
- test /test_module.cpp
115
- test /test_object.cpp
116
- test /test_property.cpp
117
- test /test_ptr_traits.cpp
118
- test /test_throw_ex.cpp
119
- test /test_utility.cpp
120
- )
121
- if (V8PP_HEADER_ONLY)
122
- target_sources (v8pp_test PRIVATE v8pp/context.cpp)
123
- endif ()
124
-
125
- target_link_libraries (v8pp_test v8pp)
126
- if (BUILD_SHARED_LIBS )
127
- target_link_libraries (v8pp_test ${CMAKE_DL_LIBS} )
128
- endif ()
129
-
130
- add_test (v8pp_test v8pp_test --version --run-tests)
131
- set_tests_properties (v8pp_test PROPERTIES ENVIRONMENT LD_LIBRARY_PATH=${V8_LIB_DIR} :$ENV{LD_LIBRARY_PATH} )
132
-
133
- if (BUILD_SHARED_LIBS )
134
- file (GLOB JS_TESTS test /*.js)
135
- add_test (v8pp_js_test v8pp_test --lib-path ${CMAKE_BINARY_DIR} ${JS_TESTS} )
136
- set_tests_properties (v8pp_js_test PROPERTIES ENVIRONMENT LD_LIBRARY_PATH=${V8_LIB_DIR} :$ENV{LD_LIBRARY_PATH} )
137
- endif ()
26
+ add_subdirectory (test )
138
27
endif ()
139
-
140
- # Install
141
- #include(GNUInstallDirs)
142
- #include(CMakePackageConfigHelpers)
143
-
144
- #write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" COMPATIBILITY SameMajorVersion)
145
- #export(TARGETS ${PROJECT_NAME} NAMESPACE ${PROJECT_NAME}:: FILE "${PROJECT_NAME}Config.cmake")
146
- #install(DIRECTORY "include" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
147
- #install(TARGETS ${PROJECT_NAME} EXPORT "${PROJECT_NAME}Config" INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
148
- #install(EXPORT "${PROJECT_NAME}Config" NAMESPACE ${PROJECT_NAME}:: DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
149
- #install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
150
-
151
- macro (find_v8_dev)
152
- if (NOT DEFINED V8_INCLUDE_DIR)
153
- set (V8_INCLUDE_DIR ${V8_DIR} /include )
154
- endif ()
155
- message (STATUS "V8 include dir: ${V8_INCLUDE_DIR} " )
156
- if (NOT EXISTS "${V8_INCLUDE_DIR} " )
157
- message (FATAL_ERROR "No V8 include dir found" )
158
- endif ()
159
-
160
- if (NOT DEFINED V8_LIB_DIR)
161
- set (V8_LIB_DIR ${V8_DIR} /lib)
162
- endif ()
163
- message (STATUS "V8 lib dir: ${V8_LIB_DIR} " )
164
- if (NOT EXISTS "${V8_LIB_DIR} " )
165
- message (FATAL_ERROR "No V8 lib dir found" )
166
- endif ()
167
-
168
- if (BUILD_SHARED_LIBS )
169
- file (GLOB V8_LIBRARIES ${V8_LIB_DIR} /*${CMAKE_SHARED_LIBRARY_SUFFIX} )
170
- else ()
171
- file (GLOB V8_LIBRARIES ${V8_LIB_DIR} /*${CMAKE_STATIC_LIBRARY_SUFFIX} )
172
- endif ()
173
- message (STATUS "V8 libraries: ${V8_LIBRARIES} " )
174
- if (NOT V8_LIBRARIES)
175
- message (FATAL_ERROR "No V8 libraries found" )
176
- endif ()
177
- endmacro ()
0 commit comments