Skip to content

Commit

Permalink
Library Forwarding: Allow building guest libs in isolation
Browse files Browse the repository at this point in the history
  • Loading branch information
neobrain committed Apr 25, 2024
1 parent 9c3309d commit 1d18c64
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ CHECK_INCLUDE_FILES ("gdb/jit-reader.h" HAVE_GDB_JIT_READER_H)
option(BUILD_TESTS "Build unit tests to ensure sanity" TRUE)
option(BUILD_FEX_LINUX_TESTS "Build FEXLinuxTests, requires x86 compiler" FALSE)
option(BUILD_THUNKS "Build thunks" FALSE)
option(BUILD_FEXCONFIG "Build FEXConfig, requires SDL2 and X11" TRUE)
option(ENABLE_CLANG_THUNKS "Build thunks with clang" FALSE)
option(BUILD_GUEST_LIBS "Build guest library wrappers as part of the main project" TRUE)
option(BUILD_FEXCONFIG "Build FEXConfig, requires SDL2 and X11" TRUE)
option(ENABLE_IWYU "Enables include what you use program" FALSE)
option(ENABLE_LTO "Enable LTO with compilation" TRUE)
option(ENABLE_XRAY "Enable building with LLVM X-Ray" FALSE)
Expand Down
64 changes: 46 additions & 18 deletions ThunkLibs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@
include(ExternalProject)
cmake_minimum_required(VERSION 3.14)
project(FEXLibWrappers)

set(CMAKE_CXX_STANDARD 20)
set(FEX_PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)

add_subdirectory(Generator)

set (FEX_PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
add_subdirectory(Generator)
# Two methods of building guest library wrappers are supported:
# - build as part of the main project (recommended)
# - build in isolation from a dedicated build folder
# The second method is useful when it's difficult to set up a full
# cross-compiling environment targeting x86. In those cases, guest library
# compilation can be moved to a different machine / VM.
if (NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
# When included during a regular FEX build, build both guest and host libs
# unless requested otherwise
set(BUILD_HOST_LIBS TRUE)
set(BUILD_GUEST_LIBS ${BUILD_GUEST_LIBS})

# Thunk targets for IDE integration of guest code, only
# However, include targets for IDE integration of guest libs
add_subdirectory(GuestLibs)
else()
# When included on our own, only build guest libraries
set(BUILD_HOST_LIBS FALSE)
set(BUILD_GUEST_LIBS TRUE)
endif()

# Thunk targets for both host libraries and IDE integration
if (BUILD_HOST_LIBS)
# Targets for building host libraries and for IDE integration
add_subdirectory(HostLibs)
endif()

if (BUILD_GUEST_LIBS)
# Targets for building guest libraries
include(ExternalProject)

# Thunk targets for guest libraries
ExternalProject_Add(guest-libs
PREFIX Guest/guest-libs
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/GuestLibs"
BINARY_DIR "Guest"
BINARY_DIR "../Guest"
CMAKE_ARGS
"-DBITNESS=64"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
Expand All @@ -31,7 +56,7 @@
ExternalProject_Add(guest-libs-32
PREFIX Guest_32/guest-libs-32
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/GuestLibs"
BINARY_DIR "Guest_32"
BINARY_DIR "../Guest_32"
CMAKE_ARGS
"-DBITNESS=32"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
Expand Down Expand Up @@ -64,15 +89,18 @@
DEPENDS guest-libs-32
)

add_custom_target(uninstall_guest-libs
COMMAND ${CMAKE_COMMAND} "--build" "." "--target" "uninstall"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/Guest
)
if (TARGET uninstall)
add_custom_target(uninstall_guest-libs
COMMAND ${CMAKE_COMMAND} "--build" "." "--target" "uninstall"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/Guest
)

add_custom_target(uninstall_guest-libs-32
COMMAND ${CMAKE_COMMAND} "--build" "." "--target" "uninstall"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/Guest_32
)
add_custom_target(uninstall_guest-libs-32
COMMAND ${CMAKE_COMMAND} "--build" "." "--target" "uninstall"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/Guest_32
)

add_dependencies(uninstall uninstall_guest-libs)
add_dependencies(uninstall uninstall_guest-libs-32)
add_dependencies(uninstall uninstall_guest-libs)
add_dependencies(uninstall uninstall_guest-libs-32)
endif ()
endif()
5 changes: 5 additions & 0 deletions ThunkLibs/Generator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
if (NOT TARGET fmt)
set(FMT_INSTALL OFF)
add_subdirectory(../../External/fmt/ fmt)
endif ()

find_package(Clang REQUIRED CONFIG)
find_package(OpenSSL REQUIRED COMPONENTS Crypto)

Expand Down

0 comments on commit 1d18c64

Please sign in to comment.