|
1 | 1 | cmake_minimum_required(VERSION 3.21) |
2 | 2 |
|
3 | | -# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24 |
4 | | -if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") |
| 3 | +if(POLICY CMP0135) |
5 | 4 | cmake_policy(SET CMP0135 NEW) |
6 | 5 | endif() |
7 | 6 |
|
8 | 7 | include(FetchContent) |
9 | 8 |
|
10 | | -# Modules declaration |
11 | | -FetchContent_Declare(CMakeExtensions |
12 | | - GIT_REPOSITORY https://github.com/BabylonJS/CMakeExtensions.git |
13 | | - GIT_TAG ea28b7689530bfdc4905806f27ecf7e8ed4b5419) |
14 | | -FetchContent_Declare(ios-cmake |
15 | | - GIT_REPOSITORY https://github.com/leetal/ios-cmake.git |
16 | | - GIT_TAG 4.4.1) |
| 9 | +# -------------------------------------------------- |
| 10 | +# Declarations |
| 11 | +# -------------------------------------------------- |
17 | 12 | FetchContent_Declare(arcana.cpp |
18 | 13 | GIT_REPOSITORY https://github.com/microsoft/arcana.cpp.git |
19 | 14 | GIT_TAG f2757396e80bc4169f2ddb938ce25367a98ffdd0) |
20 | | -FetchContent_Declare(UrlLib |
21 | | - GIT_REPOSITORY https://github.com/BabylonJS/UrlLib.git |
22 | | - GIT_TAG 59917f32f6ddfa26af07dd981842c51ce02dafcd) |
23 | 15 | FetchContent_Declare(asio |
24 | 16 | GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git |
25 | 17 | GIT_TAG f693a3eb7fe72a5f19b975289afc4f437d373d9c) |
26 | | -FetchContent_Declare(llhttp |
27 | | - URL "https://github.com/nodejs/llhttp/archive/refs/tags/release/v8.1.0.tar.gz") |
| 18 | +FetchContent_Declare(CMakeExtensions |
| 19 | + GIT_REPOSITORY https://github.com/BabylonJS/CMakeExtensions.git |
| 20 | + GIT_TAG ea28b7689530bfdc4905806f27ecf7e8ed4b5419) |
28 | 21 | FetchContent_Declare(googletest |
29 | 22 | URL "https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz") |
| 23 | +FetchContent_Declare(ios-cmake |
| 24 | + GIT_REPOSITORY https://github.com/leetal/ios-cmake.git |
| 25 | + GIT_TAG 4.4.1) |
| 26 | +FetchContent_Declare(llhttp |
| 27 | + URL "https://github.com/nodejs/llhttp/archive/refs/tags/release/v8.1.0.tar.gz") |
| 28 | +FetchContent_Declare(UrlLib |
| 29 | + GIT_REPOSITORY https://github.com/bghgary/UrlLib.git |
| 30 | + GIT_TAG 59917f32f6ddfa26af07dd981842c51ce02dafcd) |
| 31 | +# -------------------------------------------------- |
30 | 32 |
|
31 | | -set(CONTENT_TO_FETCH CMakeExtensions googletest) |
| 33 | +FetchContent_MakeAvailable(CMakeExtensions) |
32 | 34 |
|
33 | 35 | if(IOS) |
34 | | - FetchContent_MakeAvailable(ios-cmake) |
| 36 | + FetchContent_MakeAvailable_With_Message(ios-cmake) |
35 | 37 | set(CMAKE_TOOLCHAIN_FILE "${ios-cmake_SOURCE_DIR}/ios.toolchain.cmake" CACHE PATH "") |
36 | 38 | set(PLATFORM "OS64COMBINED" CACHE STRING "") |
37 | 39 | set(DEPLOYMENT_TARGET "12" CACHE STRING "") |
38 | 40 | endif() |
39 | 41 |
|
40 | | -# Project |
41 | 42 | project(JsRuntimeHost) |
42 | 43 |
|
43 | 44 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
44 | 45 |
|
45 | 46 | set(CMAKE_CXX_STANDARD 17) |
46 | 47 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
47 | 48 |
|
| 49 | +# -------------------------------------------------- |
48 | 50 | # Options |
| 51 | +# -------------------------------------------------- |
| 52 | + |
| 53 | +# General |
| 54 | +option(JSRUNTIMEHOST_TESTS "Include JsRuntimeHost Tests." ${PROJECT_IS_TOP_LEVEL}) |
| 55 | +option(NAPI_BUILD_ABI "Build the ABI layer." ON) |
49 | 56 |
|
50 | | -## Core |
| 57 | +# Core |
51 | 58 | option(JSRUNTIMEHOST_CORE_APPRUNTIME "Include JsRuntimeHost Core AppRuntime" ON) |
52 | 59 | option(JSRUNTIMEHOST_CORE_APPRUNTIME_V8_INSPECTOR "Include the V8 inspector protocol required to debug JavaScript with a V8 debugger." ON) |
53 | 60 | option(JSRUNTIMEHOST_CORE_SCRIPTLOADER "Include JsRuntimeHost Core ScriptLoader" ON) |
54 | 61 |
|
55 | | -## Polyfills |
| 62 | +# Polyfills |
56 | 63 | option(JSRUNTIMEHOST_POLYFILL_CONSOLE "Include JsRuntimeHost Polyfill Console." ON) |
57 | 64 | option(JSRUNTIMEHOST_POLYFILL_SCHEDULING "Include JsRuntimeHost Polyfill Scheduling." ON) |
58 | 65 | option(JSRUNTIMEHOST_POLYFILL_XMLHTTPREQUEST "Include JsRuntimeHost Polyfill XMLHttpRequest." ON) |
59 | 66 | option(JSRUNTIMEHOST_POLYFILL_URL "Include JsRuntimeHost Polyfill URL and URLSearchParams." ON) |
60 | 67 | option(JSRUNTIMEHOST_POLYFILL_ABORT_CONTROLLER "Include JsRuntimeHost Polyfills AbortController and AbortSignal." ON) |
61 | 68 | option(JSRUNTIMEHOST_POLYFILL_WEBSOCKET "Include JsRuntimeHost Polyfill WebSocket." ON) |
62 | 69 |
|
63 | | -## Tests |
64 | | -option(JSRUNTIMEHOST_TESTS "Include JsRuntimeHost Tests." ${PROJECT_IS_TOP_LEVEL}) |
65 | | - |
66 | | -## Node-API |
67 | | -option(NAPI_BUILD_ABI "Build the ABI layer." ON) |
| 70 | +# -------------------------------------------------- |
68 | 71 |
|
69 | | -# Dependencies |
| 72 | +FetchContent_MakeAvailable_With_Message(arcana.cpp) |
| 73 | +set_property(TARGET arcana PROPERTY FOLDER Dependencies) |
70 | 74 |
|
71 | | -if(NOT TARGET arcana) |
72 | | - set(CONTENT_TO_FETCH ${CONTENT_TO_FETCH} arcana.cpp) |
73 | | -endif() |
74 | | - |
75 | | -if(NOT TARGET UrlLib AND JSRUNTIMEHOST_POLYFILL_XMLHTTPREQUEST) |
76 | | - set(CONTENT_TO_FETCH ${CONTENT_TO_FETCH} UrlLib) |
| 75 | +if(JSRUNTIMEHOST_POLYFILL_XMLHTTPREQUEST) |
| 76 | + FetchContent_MakeAvailable_With_Message(UrlLib) |
| 77 | + set_property(TARGET UrlLib PROPERTY FOLDER Dependencies) |
77 | 78 | endif() |
78 | 79 |
|
79 | 80 | if(NAPI_JAVASCRIPT_ENGINE STREQUAL "V8" AND JSRUNTIMEHOST_CORE_APPRUNTIME_V8_INSPECTOR) |
80 | | - if(NOT TARGET asio) |
81 | | - set(CONTENT_TO_FETCH ${CONTENT_TO_FETCH} asio) |
82 | | - endif() |
83 | | - |
84 | | - if(NOT TARGET llhttp_static) |
85 | | - set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "") |
86 | | - set(BUILD_STATIC_LIBS ON CACHE INTERNAL "") |
87 | | - set(CONTENT_TO_FETCH ${CONTENT_TO_FETCH} llhttp) |
88 | | - endif() |
| 81 | + FetchContent_MakeAvailable_With_Message(asio) |
| 82 | + add_library(asio INTERFACE) |
| 83 | + target_include_directories(asio INTERFACE "${asio_SOURCE_DIR}/asio/include") |
| 84 | + set_property(TARGET asio PROPERTY FOLDER Dependencies) |
| 85 | + |
| 86 | + set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "") |
| 87 | + set(BUILD_STATIC_LIBS ON CACHE INTERNAL "") |
| 88 | + FetchContent_MakeAvailable_With_Message(llhttp) |
| 89 | + set_property(TARGET llhttp_static PROPERTY FOLDER Dependencies) |
89 | 90 | endif() |
90 | 91 |
|
91 | | -# Fetching content |
92 | | -message(STATUS "Fetching dependencies for ${PROJECT_NAME} (${CONTENT_TO_FETCH})") |
93 | | -FetchContent_MakeAvailable(${CONTENT_TO_FETCH}) |
94 | | -message(STATUS "Fetching dependencies for ${PROJECT_NAME} - done") |
95 | | - |
96 | | -# Set properties after fetching content |
97 | | -if(TARGET arcana) |
98 | | - set_property(TARGET arcana PROPERTY FOLDER Dependencies) |
99 | | -endif() |
| 92 | +if(JSRUNTIMEHOST_TESTS) |
| 93 | + if(WIN32) |
| 94 | + # For Windows: Prevent overriding the parent project's compiler/linker settings |
| 95 | + # Default build type for my test projects are /MDd (MultiThreaded DLL) but GTests default to /MTd (MultiThreaded) |
| 96 | + # see https://github.com/google/googletest/blob/main/googletest/README.md |
| 97 | + # "Enabling this option will make gtest link the runtimes dynamically too, and match the project in which it is included." |
| 98 | + set(gtest_force_shared_crt OFF CACHE BOOL "" FORCE) |
| 99 | + endif() |
100 | 100 |
|
101 | | -if(TARGET UrlLib AND JSRUNTIMEHOST_POLYFILL_XMLHTTPREQUEST) |
102 | | - set_property(TARGET UrlLib PROPERTY FOLDER Dependencies) |
103 | | -endif() |
| 101 | + FetchContent_MakeAvailable_With_Message(googletest) |
104 | 102 |
|
105 | | -if(NAPI_JAVASCRIPT_ENGINE STREQUAL "V8" AND JSRUNTIMEHOST_CORE_APPRUNTIME_V8_INSPECTOR) |
106 | | - if(NOT TARGET asio) |
107 | | - add_library(asio INTERFACE) |
108 | | - target_include_directories(asio INTERFACE "${asio_SOURCE_DIR}/asio/include") |
109 | | - set_property(TARGET asio PROPERTY FOLDER Dependencies) |
110 | | - endif() |
111 | | - if(NOT TARGET llhttp_static) |
112 | | - set_property(TARGET llhttp_static PROPERTY FOLDER Dependencies) |
113 | | - endif() |
| 103 | + set_property(TARGET gmock PROPERTY FOLDER Dependencies/GoogleTest) |
| 104 | + set_property(TARGET gmock_main PROPERTY FOLDER Dependencies/GoogleTest) |
| 105 | + set_property(TARGET gtest PROPERTY FOLDER Dependencies/GoogleTest) |
| 106 | + set_property(TARGET gtest_main PROPERTY FOLDER Dependencies/GoogleTest) |
114 | 107 | endif() |
115 | 108 |
|
116 | | -# Subdirectories |
117 | | - |
118 | 109 | if(ANDROID) |
119 | 110 | set(JSRUNTIMEHOST_PLATFORM "Android") |
120 | 111 | elseif(IOS) |
|
0 commit comments