diff --git a/.gitignore b/.gitignore index e49def36..e8ae8b32 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ cmake-build-debug/ # vs .vs/ out/ -CMakeFiles/ \ No newline at end of file +CMakeFiles/ +CMakeSettings.json \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index c911d03d..667b3eb4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,10 @@ if(MSVC) v8/src/heap/base/asm/ia32/push_registers_masm.asm v8/src/heap/base/asm/x64/push_registers_masm.asm PROPERTY LANGUAGE ASM_MASM) - + # The most important workaround is /utf-8, if you don't add this option, your complication will fail if you compile v8 in + # a non-english environment (for example, Simplified Chinese). + # The remaining options is aimed to let complier shut up. + set(msvc-workaround /utf-8 /wd4661 /wd4819 /wd4267 /wd4996 /wd4244 /wd4005 /wd4146 /wd4715 /wd4530 /wd4838 /wd4506 /wd4309 /wd4312 /wd4334) endif() add_definitions("-DV8_ENABLE_WEBASSEMBLY -DV8_ADVANCED_BIGINT_ALGORITHMS -DV8_ENABLE_WASM_SIMD256_REVEC") @@ -141,7 +144,7 @@ add_executable( v8/src/d8/d8-js.cc v8/src/d8/d8-test.cc v8/src/d8/d8-platforms.cc - v8/src/d8/d8.cc + v8/src/d8/d8.cc ) target_compile_definitions(d8 PRIVATE $<${is-msvc}:_HAS_EXCEPTIONS=0>) @@ -150,6 +153,10 @@ if(enable-fPIC) target_compile_options(d8 PRIVATE ${enable-fpic}) endif() +if (is-msvc) + target_compile_options(d8 PRIVATE ${msvc-workaround}) +endif() + target_include_directories(d8 PUBLIC $ @@ -187,6 +194,9 @@ target_link_libraries(shell v8_inspector v8_libplatform ) +if(is-msvc) + target_compile_options(shell PRIVATE ${msvc-workaround}) +endif() add_executable( hello-world @@ -207,6 +217,9 @@ target_link_libraries(hello-world v8_inspector v8_libplatform ) +if(is-msvc) + target_compile_options(hello-world PRIVATE ${msvc-workaround}) +endif() # more granular library support add_library(v8-i18n-support OBJECT) @@ -237,6 +250,10 @@ target_compile_definitions(v8-i18n-support PRIVATE $<${is-msvc}:_HAS_EXCEPTIONS= target_compile_options(v8-i18n-support PRIVATE ${disable-exceptions}) target_link_libraries(v8-i18n-support PRIVATE v8_torque_generated) +if (is-msvc) + target_compile_options(v8-i18n-support PRIVATE ${msvc-workaround}) +endif() + target_include_directories(v8-i18n-support PRIVATE ${PROJECT_SOURCE_DIR}/v8 @@ -331,7 +348,7 @@ list(REMOVE_ITEM strings-sources v8/src/strings/char-predicates.cc) list(APPEND snapshot-sources v8/src/snapshot/embedded/embedded-data.cc) list(APPEND wasm-sources ${wasm-baseline-sources}) -add_library(v8_base_without_compiler STATIC +list(APPEND v8_base_without_compiler_sources $<${is-posix}:v8/src/trap-handler/handler-inside-posix.cc> $<${is-posix}:v8/src/trap-handler/handler-outside-posix.cc> $<$:v8/src/diagnostics/unwinding-info-win64.cc> @@ -447,6 +464,10 @@ add_library(v8_base_without_compiler STATIC $ ) +add_library(v8_base_without_compiler STATIC + ${v8_base_without_compiler_sources} +) + if (WIN32) if (CMAKE_SYSTEM_VERSION VERSION_GREATER 10) # Windows 10 set(windows-version 0x0A00) @@ -474,6 +495,10 @@ if(enable-fPIC) target_compile_options(v8_base_without_compiler PRIVATE ${enable-fpic}) endif() +if(is-msvc) + target_compile_options(v8_base_without_compiler PRIVATE ${msvc-workaround}) +endif() + target_include_directories(v8_base_without_compiler PRIVATE $ @@ -510,6 +535,10 @@ if(enable-fPIC) target_compile_options(v8_compiler PRIVATE ${enable-fpic}) endif() +if(is-msvc) + target_compile_options(v8_compiler PRIVATE ${msvc-workaround}) +endif() + target_include_directories(v8_compiler PUBLIC ${PROJECT_BINARY_DIR} @@ -532,8 +561,7 @@ target_link_libraries(v8_compiler # v8_initializers # -add_library( - v8_initializers STATIC +list(APPEND v8_initializers_sources $<${is-arm64}:v8/src/builtins/arm64/builtins-arm64.cc> $<${is-arm}:v8/src/builtins/arm/builtins-arm.cc> $<${is-ia32}:v8/src/builtins/ia32/builtins-ia32.cc> @@ -585,12 +613,18 @@ add_library( v8/src/interpreter/interpreter-intrinsics-generator.cc ) +add_library(v8_initializers STATIC ${v8_initializers_sources}) + target_compile_definitions(v8_initializers PRIVATE ${v8_defines} $<${is-msvc}:_HAS_EXCEPTIONS=0>) target_compile_options(v8_initializers PRIVATE ${disable-exceptions}) if(enable-fPIC) target_compile_options(v8_initializers PRIVATE ${enable-fpic}) endif() +if(is-msvc) + target_compile_options(v8_initializers PRIVATE ${msvc-workaround}) +endif() + target_include_directories(v8_initializers PRIVATE ${PROJECT_SOURCE_DIR}/v8 @@ -603,13 +637,17 @@ target_link_libraries(v8_initializers PRIVATE v8_torque_generated v8-bytecodes-b # v8_snapshot # +list(APPEND v8_snapshot_sources + ${PROJECT_BINARY_DIR}/embedded.S + ${PROJECT_BINARY_DIR}/snapshot.cc + v8/src/init/setup-isolate-deserialize.cc +) + # Note: v8_use_external_startup_data not currently supported. # Note: v8_use_multi_snapshots not currently supported. add_library( v8_snapshot STATIC - ${PROJECT_BINARY_DIR}/embedded.S - ${PROJECT_BINARY_DIR}/snapshot.cc - v8/src/init/setup-isolate-deserialize.cc + ${v8_snapshot_sources} ) target_compile_definitions(v8_snapshot PRIVATE $<${is-msvc}:_HAS_EXCEPTIONS=0>) @@ -617,6 +655,11 @@ target_compile_options(v8_snapshot PRIVATE ${disable-exceptions}) if(enable-fPIC) target_compile_options(v8_snapshot PRIVATE ${enable-fpic}) endif() + +if(is-msvc) + target_compile_options(v8_snapshot PRIVATE ${msvc-workaround}) +endif() + target_include_directories(v8_snapshot PRIVATE ${PROJECT_SOURCE_DIR}/v8) target_link_libraries(v8_snapshot @@ -704,6 +747,11 @@ target_compile_options(v8_inspector PRIVATE ${disable-exceptions}) if(enable-fPIC) target_compile_options(v8_inspector PRIVATE ${enable-fpic}) endif() + +if(is-msvc) + target_compile_options(v8_inspector PRIVATE ${msvc-workaround}) +endif() + target_compile_definitions(v8_inspector PUBLIC $<${is-msvc}:_HAS_EXCEPTIONS=0>) target_include_directories(v8_inspector @@ -753,9 +801,7 @@ add_custom_command( # v8_libplatform # -add_library(v8_libplatform STATIC) -target_sources(v8_libplatform - PRIVATE +list(APPEND v8_libplatform_sources $<${is-win}:v8/src/libplatform/tracing/recorder-win.cc> v8/src/libplatform/default-foreground-task-runner.cc v8/src/libplatform/default-job.cc @@ -772,12 +818,19 @@ target_sources(v8_libplatform v8/src/libplatform/worker-thread.cc ) +add_library(v8_libplatform STATIC) +target_sources(v8_libplatform PRIVATE ${v8_libplatform_sources}) + target_compile_definitions(v8_libplatform PRIVATE $<${is-msvc}:_HAS_EXCEPTIONS=0>) target_compile_options(v8_libplatform PRIVATE ${disable-exceptions}) if(enable-fPIC) target_compile_options(v8_libplatform PRIVATE ${enable-fpic}) endif() +if(is-msvc) + target_compile_options(v8_libplatform PRIVATE ${msvc-workaround}) +endif() + target_include_directories(v8_libplatform PUBLIC ${PROJECT_SOURCE_DIR}/v8/include @@ -791,7 +844,9 @@ target_link_libraries(v8_libplatform PRIVATE v8_libbase) # v8_libsampler # -add_library(v8_libsampler STATIC v8/src/libsampler/sampler.cc) +list(APPEND v8_libsampler_sources v8/src/libsampler/sampler.cc) + +add_library(v8_libsampler STATIC ${v8_libsampler_sources}) target_include_directories(v8_libsampler PRIVATE @@ -804,6 +859,11 @@ target_compile_options(v8_libsampler PRIVATE ${disable-exceptions}) if(enable-fPIC) target_compile_options(v8_libsampler PRIVATE ${enable-fpic}) endif() + +if(is-msvc) + target_compile_options(v8_libsampler PRIVATE ${msvc-workaround}) +endif() + target_include_directories(v8_libsampler PRIVATE ${PROJECT_SOURCE_DIR}/v8) target_link_libraries(v8_libsampler PRIVATE v8_libbase) @@ -811,7 +871,7 @@ target_link_libraries(v8_libsampler PRIVATE v8_libbase) # v8_libbase # -add_library(v8_libbase STATIC +list(APPEND v8_libbase_sources v8/src/base/bits.cc v8/src/base/bounded-page-allocator.cc v8/src/base/cpu.cc @@ -846,6 +906,8 @@ add_library(v8_libbase STATIC $<${is-posix}:v8/src/base/platform/platform-posix.cc> ) +add_library(v8_libbase STATIC ${v8_libbase_sources}) + set_property(SOURCE v8/src/base/utils/random-number-generator.cc APPEND PROPERTY COMPILE_DEFINITIONS _CRT_RAND_S ) @@ -855,6 +917,11 @@ target_compile_options(v8_libbase PRIVATE ${disable-exceptions}) if(enable-fPIC) target_compile_options(v8_libbase PRIVATE ${enable-fpic}) endif() + +if(is-msvc) + target_compile_options(v8_libbase PRIVATE ${msvc-workaround}) +endif() + target_include_directories(v8_libbase PRIVATE ${PROJECT_SOURCE_DIR}/v8) target_link_libraries(v8_libbase PRIVATE @@ -889,6 +956,10 @@ target_include_directories(bytecode_builtins_list_generator target_link_libraries(bytecode_builtins_list_generator v8_libbase) +if(is-msvc) + target_compile_options(bytecode_builtins_list_generator PRIVATE ${msvc-workaround}) +endif() + # # v8_torque_generated # @@ -990,6 +1061,11 @@ target_compile_options(v8_torque_generated PRIVATE ${disable-exceptions}) if(enable-fPIC) target_compile_options(v8_torque_generated PRIVATE ${enable-fpic}) endif() + +if(is-msvc) + target_compile_options(v8_torque_generated PRIVATE ${msvc-workaround}) +endif() + target_link_libraries(v8_torque_generated PRIVATE v8-bytecodes-builtin-list) target_include_directories(v8_torque_generated @@ -1044,6 +1120,10 @@ target_compile_options(torque PRIVATE ${enable-exceptions}) target_include_directories(torque PRIVATE ${PROJECT_SOURCE_DIR}/v8) target_link_libraries(torque PRIVATE v8_libbase) +if(is-msvc) + target_compile_options(torque PRIVATE ${msvc-workaround}) +endif() + # # mksnapshot # @@ -1080,3 +1160,75 @@ target_include_directories(v8-adler32 PUBLIC $ ) + +if(is-msvc) + target_compile_options(mksnapshot PRIVATE ${msvc-workaround}) +endif() + +# +# v8_monolithic +# + +# HELP: Is there any idea for combining multiple static library into one single library? +# This solution is suck, but I don't really know how to do a cleaner implementation. +add_library(v8_monolithic STATIC + ${v8_base_without_compiler_sources} + ${v8_libplatform_sources} + ${compiler-sources} + ${v8_libbase_sources} + ${v8_libsampler_sources} +) +target_compile_definitions(v8_monolithic PRIVATE $<${is-win}:UNICODE> $<${is-msvc}:_HAS_EXCEPTIONS=0>) +target_compile_options(v8_monolithic PRIVATE ${disable-exceptions}) +if(enable-fPIC) + target_compile_options(v8_monolithic PRIVATE ${enable-fpic}) +endif() + +if(is-msvc) + target_compile_options(v8_monolithic PRIVATE ${msvc-workaround}) +endif() + +target_include_directories(v8_monolithic + PUBLIC + ${PROJECT_SOURCE_DIR}/v8/include + PRIVATE + $ + $> + ${PROJECT_SOURCE_DIR}/v8 + ${PROJECT_SOURCE_DIR}/v8/third_party/zlib + ${PROJECT_BINARY_DIR} +) +target_link_libraries(v8_monolithic + PRIVATE + Threads::Threads + $<${is-linux}:${CMAKE_DL_LIBS}> + $<${is-linux}:rt> + $<${is-win}:winmm> + $<${is-win}:dbghelp> + v8_torque_generated + v8-bytecodes-builtin-list +) + +# +# wee8 +# +add_library(wee8 STATIC + v8/src/wasm/c-api.cc +) +target_compile_definitions(wee8 PRIVATE $<${is-msvc}:_HAS_EXCEPTIONS=0>) +target_compile_options(wee8 PRIVATE ${disable-exceptions}) +if(enable-fPIC) + target_compile_options(wee8 PRIVATE ${enable-fpic}) +endif() + +if(is-msvc) + target_compile_options(wee8 PRIVATE ${msvc-workaround}) +endif() +target_include_directories(wee8 + PUBLIC + ${PROJECT_SOURCE_DIR}/v8/include + PRIVATE + ${PROJECT_SOURCE_DIR}/v8/third_party/wasm-api + ${PROJECT_SOURCE_DIR}/v8 +) +target_link_libraries(wee8 PRIVATE v8_base_without_compiler v8_compiler v8_libplatform v8_snapshot) \ No newline at end of file