Skip to content

Commit 049615f

Browse files
committed
cmake build on Windows
at least with Ninja. Try to use V8 nuget packages in FindV8.cmake See pmed#138, pmed#171 (cherry picked from commit 5877afb)
1 parent f6fe558 commit 049615f

File tree

4 files changed

+53
-15
lines changed

4 files changed

+53
-15
lines changed

CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ set(V8PP_PLUGIN_INIT_PROC_NAME "v8pp_module_init" CACHE STRING "v8pp plugin init
2222
set(V8PP_PLUGIN_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX} CACHE STRING "v8pp plugin filename suffix")
2323
option(V8_COMPRESS_POINTERS "Use new V8 ABI with V8_COMPRESS_POINTERS and V8_31BIT_SMIS_ON_64BIT_ARCH" ON)
2424

25+
if(BUILD_SHARED_LIBS AND WIN32)
26+
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS true)
27+
endif()
28+
29+
# put all binaries into the output dir
30+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
31+
2532
add_subdirectory(v8pp)
2633

2734
if(BUILD_TESTING)

cmake/FindV8.cmake

+42-11
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,54 @@
77
# V8_LIBRARIES, the libraries needed to use v8.
88
# V8_FOUND, If false, do not try to use v8.
99

10-
find_path(V8_INCLUDE_DIRS PATH_SUFFIXES v8 NAMES v8.h)
10+
if(WIN32)
11+
set(ARCH ${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE})
12+
if(NOT ARCH)
13+
if(${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "AMD64")
14+
set(ARCH x64)
15+
else()
16+
set(ARCH x86)
17+
endif()
18+
endif()
19+
message(STATUS "v8-v${MSVC_TOOLSET_VERSION}-${ARCH}")
20+
file(GLOB V8_NUGET_DEV_DIR LIST_DIRECTORIES TRUE
21+
${CMAKE_BINARY_DIR}/v8-v${MSVC_TOOLSET_VERSION}-${ARCH}.*)
22+
string(REPLACE "v8-" "v8.redist-" V8_NUGET_BIN_DIR ${V8_NUGET_DEV_DIR})
1123

12-
find_library(V8_LIB NAMES v8)
13-
find_library(V8_LIBPLATFORM NAMES v8_libplatform)
14-
set(V8_LIBRARIES ${V8_LIB} ${V8_LIBPLATFORM})
24+
set(V8_NUGET_INCLUDE_DIR ${V8_NUGET_DEV_DIR}/include)
25+
set(V8_NUGET_LIB_DIR ${V8_NUGET_DEV_DIR}/lib/${CMAKE_BUILD_TYPE})
26+
set(V8_NUGET_BIN_DIR ${V8_NUGET_BIN_DIR}/lib/${CMAKE_BUILD_TYPE})
27+
find_file(V8_DLL v8.dll ${V8_NUGET_BIN_DIR})
28+
find_file(V8_LIBPLATFORMDLL v8_libplatform.dll ${V8_NUGET_BIN_DIR})
29+
30+
file(GLOB V8_BINARIES ${V8_NUGET_BIN_DIR}/*)
31+
message(STATUS "Copy ${V8_BINARIES} to the project output dir ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
32+
file(COPY ${V8_BINARIES} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
33+
else()
34+
endif()
35+
36+
find_path(V8_INCLUDE_DIRS PATHS ${V8_NUGET_INCLUDE_DIR} PATH_SUFFIXES v8 NAMES v8.h)
37+
find_library(V8_LIB PATHS ${V8_NUGET_LIB_DIR} NAMES v8 v8.dll.lib)
38+
find_library(V8_LIBPLATFORM PATHS ${V8_NUGET_LIB_DIR} NAMES v8_libplatform v8_libplatform.dll.lib)
1539

1640
# handle the QUIETLY and REQUIRED arguments and set V8_FOUND to TRUE
1741
# if all listed variables are TRUE, hide their existence from configuration view
1842
include(FindPackageHandleStandardArgs)
1943
find_package_handle_standard_args(V8 DEFAULT_MSG V8_INCLUDE_DIRS V8_LIB V8_LIBPLATFORM)
20-
mark_as_advanced(V8_INCLUDE_DIRS V8_LIBRARIES)
44+
mark_as_advanced(V8_INCLUDE_DIRS V8_LIB)
2145

2246
if(V8_FOUND)
23-
if(NOT TARGET V8::V8)
24-
add_library(V8::V8 SHARED IMPORTED)
25-
set_target_properties(V8::V8 PROPERTIES IMPORTED_LOCATION "${V8_LIB}")
26-
target_include_directories(V8::V8 INTERFACE "${V8_INCLUDE_DIRS}")
27-
target_link_libraries(V8::V8 INTERFACE "${V8_LIBRARIES}")
28-
endif()
47+
add_library(V8::v8 SHARED IMPORTED)
48+
add_library(V8::libplatform SHARED IMPORTED)
49+
if(WIN32)
50+
set_target_properties(V8::v8 PROPERTIES
51+
IMPORTED_IMPLIB ${V8_LIB} IMPORTED_LOCATION ${V8_DLL})
52+
set_target_properties(V8::libplatform PROPERTIES
53+
IMPORTED_IMPLIB ${V8_LIBPLATFORM} IMPORTED_LOCATION ${V8_LIBPLATFORMDLL})
54+
else()
55+
set_target_properties(V8::v8 PROPERTIES IMPORTED_LOCATION ${V8_LIB})
56+
set_target_properties(V8::libplatform PROPERTIES IMPORTED_LOCATION ${V8_LIBPLATFORM})
57+
endif()
58+
target_include_directories(V8::v8 INTERFACE ${V8_INCLUDE_DIRS})
59+
target_include_directories(V8::libplatform INTERFACE ${V8_INCLUDE_DIRS})
2960
endif()

test/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ endif()
2424

2525
target_link_libraries(v8pp_test v8pp ${CMAKE_DL_LIBS})
2626

27-
add_test(v8pp_test v8pp_test --version --run-tests)
27+
add_test(v8pp_test ${PROJECT_BINARY_DIR}/v8pp_test --version --run-tests)
2828

2929
if(BUILD_SHARED_LIBS)
3030
file(GLOB JS_TESTS *.js)
31-
add_test(v8pp_js_test v8pp_test --lib-path ${PROJECT_BINARY_DIR}/plugins ${JS_TESTS})
31+
add_test(v8pp_js_test ${PROJECT_BINARY_DIR}/v8pp_test --lib-path ${PROJECT_BINARY_DIR}/plugins ${JS_TESTS})
3232
endif()

v8pp/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ if(V8PP_HEADER_ONLY)
6464
target_include_directories(v8pp INTERFACE
6565
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
6666
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
67-
target_link_libraries(v8pp INTERFACE V8::V8)
67+
target_link_libraries(v8pp INTERFACE V8::v8 V8::libplatform)
6868
else()
6969
add_library(v8pp ${V8PP_HEADERS} ${V8PP_SOURCES})
7070
target_compile_definitions(v8pp PUBLIC ${V8PP_DEFINES})
7171
target_compile_options(v8pp PRIVATE ${V8PP_COMPILE_OPTIONS})
7272
target_include_directories(v8pp PUBLIC
7373
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
7474
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
75-
target_link_libraries(v8pp PUBLIC V8::V8)
75+
target_link_libraries(v8pp PUBLIC V8::v8 V8::libplatform)
7676
if(BUILD_SHARED_LIBS)
7777
target_link_libraries(v8pp PUBLIC ${CMAKE_DL_LIBS})
7878
endif()

0 commit comments

Comments
 (0)