Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a Find module for V8 #8373

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README_webassembly.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ v8](https://v8.dev/docs/embed). The process for Halide is summarized below.

With V8 built, we can pass the CMake options:

- `V8_INCLUDE_PATH`, path to V8 includes, e.g. `$HOME/v8/v8/include`
- `V8_LIB_PATH`, path to V8 static library, e.g. `$HOME/v8/v8/out.gn/x64.release.sample/obj/libv8_monolith.a`
- `V8_INCLUDE_DIR`, path to V8 includes, e.g. `$HOME/v8/v8/include`
- `V8_LIBRARY`, path to V8 static library, e.g. `$HOME/v8/v8/out.gn/x64.release.sample/obj/libv8_monolith.a`

An example to configure Halide with V8 support, build and run an example test:

Expand All @@ -121,8 +121,8 @@ $ export HL_JIT_TARGET=${HL_TARGET}
$ cmake -G Ninja \
-DWITH_WABT=OFF \
-DWITH_V8=ON \
-DV8_INCLUDE_PATH=$HOME/v8/v8/include \
-DV8_LIB_PATH=$HOME/v8/v8/out.gn/x64.release.sample/obj/libv8_monolith.a \
-DV8_INCLUDE_DIR=$HOME/v8/v8/include \
-DV8_LIBRARY=$HOME/v8/v8/out.gn/x64.release.sample/obj/libv8_monolith.a \
-DHalide_TARGET=${HL_TARGET} \
/* other cmake settings here as appropriate */

Expand Down
33 changes: 33 additions & 0 deletions cmake/FindV8.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
if (EXISTS "${V8_INCLUDE_PATH}")
message(DEPRECATION "V8_INCLUDE_PATH has been renamed to V8_INCLUDE_DIR")
set(V8_INCLUDE_DIR "${V8_INCLUDE_PATH}")
set(V8_INCLUDE_DIR "${V8_INCLUDE_PATH}" CACHE PATH "")
endif ()

find_path(V8_INCLUDE_DIR v8.h)

if (EXISTS "${V8_LIB_PATH}")
message(DEPRECATION "V8_LIB_PATH has been renamed to V8_LIBRARY")
set(V8_LIBRARY "${V8_LIB_PATH}")
set(V8_LIBRARY "${V8_LIB_PATH}" CACHE FILEPATH "")
endif ()

find_library(
V8_LIBRARY
NAMES v8_monolith
PATH_SUFFIXES
out.gn/x64.release.sample/obj
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
V8
REQUIRED_VARS V8_LIBRARY V8_INCLUDE_DIR
HANDLE_COMPONENTS
)

if (V8_FOUND AND NOT TARGET V8::V8)
add_library(V8::V8 UNKNOWN IMPORTED)
set_target_properties(V8::V8 PROPERTIES IMPORTED_LOCATION "${V8_LIBRARY}")
target_include_directories(V8::V8 INTERFACE "${V8_INCLUDE_DIR}")
endif ()
16 changes: 3 additions & 13 deletions dependencies/wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,9 @@ if (WITH_WABT)
endif ()

if (WITH_V8)
# Instructions to build V8 can be found in README_webassembly.md.
if (NOT V8_INCLUDE_PATH)
message(FATAL_ERROR "Please set V8_INCLUDE_PATH on the CMake command line.")
endif()
if (NOT V8_LIB_PATH)
message(FATAL_ERROR "Please set V8_LIB_PATH on the CMake command line.")
endif()

message(STATUS "Using V8")
add_library(Halide_V8 STATIC IMPORTED GLOBAL)
set_target_properties(Halide_V8 PROPERTIES IMPORTED_LOCATION "${V8_LIB_PATH}")
target_include_directories(Halide_V8 INTERFACE "${V8_INCLUDE_PATH}")
endif()
find_package(V8 REQUIRED)
set_target_properties(V8::V8 PROPERTIES IMPORTED_GLOBAL TRUE)
endif ()

function(add_wasm_executable TARGET)
set(options)
Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,8 @@ if (TARGET Halide_wabt)
target_compile_definitions(Halide PRIVATE WITH_WABT)
endif ()

if (TARGET Halide_V8)
target_link_libraries(Halide PRIVATE Halide_V8)
if (TARGET V8::V8)
target_link_libraries(Halide PRIVATE V8::V8)
target_compile_definitions(Halide PRIVATE WITH_V8)
endif ()

Expand Down