Skip to content

Commit

Permalink
Workaround LLVM hardcoded include directory (#513)
Browse files Browse the repository at this point in the history
These fixes are required for packaging a prebuilt remill that is relocatable/portable with respect to dependencies and their paths---in this case LLVM's include directory path.
  • Loading branch information
ekilmer authored May 13, 2021
1 parent 7311c6a commit 1caf764
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 364 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ cmake_minimum_required(VERSION 3.14)
include(GNUInstallDirs)

include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/settings.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils_vcpkg.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/ccache.cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
include(CTest)
Expand Down Expand Up @@ -51,7 +51,7 @@ list(GET LLVM_VERSION_LIST 1 LLVM_MINOR_VERSION)

add_library(thirdparty_llvm INTERFACE)
target_include_directories(thirdparty_llvm SYSTEM INTERFACE
${LLVM_INCLUDE_DIRS}
$<BUILD_INTERFACE:${LLVM_INCLUDE_DIRS}>
)
target_compile_definitions(thirdparty_llvm INTERFACE
${LLVM_DEFINITIONS}
Expand Down Expand Up @@ -293,7 +293,7 @@ list(REMOVE_DUPLICATES THIRDPARTY_LIBRARY_FILES)

# First do the basic substitutions.
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/remillConfig_vcpkg.cmake.in"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/remillConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/remillConfig.cmake"
@ONLY
)
Expand Down
115 changes: 48 additions & 67 deletions cmake/remillConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,79 +12,60 @@
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.2)
@PACKAGE_INIT@

if(NOT TARGET remill)
if(WIN32)
set(REMILL_LIBRARY_LOCATION "@CMAKE_INSTALL_PREFIX@/remill/lib/remill.lib")
set(REMILL_INCLUDE_LOCATION "@CMAKE_INSTALL_PREFIX@/remill/include")
else()
set(REMILL_LIBRARY_LOCATION "@CMAKE_INSTALL_PREFIX@/lib/libremill.a")
set(REMILL_INCLUDE_LOCATION "@CMAKE_INSTALL_PREFIX@/include")
foreach(_comp ${remill_FIND_COMPONENTS})
if (NOT "VCPKG_DEPS" STREQUAL _comp)
set(remill_FOUND False)
set(remill_NOT_FOUND_MESSAGE "Unsupported component: ${_comp}. Only VCPKG_DEPS")
endif()

# For Linux builds, group LLVM libraries into a single group
# that avoids frustrating library ordering issues.
if(UNIX AND NOT APPLE)
set(LINKER_START_GROUP "-Wl,--start-group")
set(LINKER_END_GROUP "-Wl,--end-group")
else()
set(LINKER_START_GROUP "")
set(LINKER_END_GROUP "")

if ("VCPKG_DEPS" STREQUAL _comp)
set(remill_setup_vcpkg True)
if(NOT "x@VCPKG_ROOT@x" STREQUAL "xx" AND NOT USE_SYSTEM_DEPENDENCIES)
if (EXISTS "@VCPKG_ROOT@")
set(VCPKG_ROOT "@VCPKG_ROOT@"
CACHE PATH "Location of dependency libraries"
)
include(${CMAKE_CURRENT_LIST_DIR}/vcpkg_helper.cmake)
message(STATUS "Found VCPKG_ROOT: ${VCPKG_ROOT}")
set(vcpkgdeps_FOUND)
endif()
endif()
endif()
endforeach()

if(NOT remill_setup_vcpkg AND NOT TARGET remill)
set(LLVM_MAJOR_VERSION @LLVM_MAJOR_VERSION@)
set(LLVM_MINOR_VERSION @LLVM_MINOR_VERSION@)
set(REMILL_LLVM_VERSION "@LLVM_MAJOR_VERSION@.@LLVM_MINOR_VERSION@")

add_library(remill_bc STATIC IMPORTED)
set_property(TARGET remill_bc PROPERTY IMPORTED_LOCATION "@REMILL_BC_LIBRARY_LOCATION@")

add_library(remill_os STATIC IMPORTED)
set_property(TARGET remill_os PROPERTY IMPORTED_LOCATION "@REMILL_OS_LIBRARY_LOCATION@")

add_library(remill_arch STATIC IMPORTED)
set_property(TARGET remill_arch PROPERTY IMPORTED_LOCATION "@REMILL_ARCH_LIBRARY_LOCATION@")

add_library(remill_arch_x86 STATIC IMPORTED)
set_property(TARGET remill_arch_x86 PROPERTY IMPORTED_LOCATION "@REMILL_ARCH_X86_LIBRARY_LOCATION@")

add_library(remill_arch_aarch32 STATIC IMPORTED)
set_property(TARGET remill_arch_aarch32 PROPERTY IMPORTED_LOCATION "@REMILL_ARCH_AARCH32_LIBRARY_LOCATION@")

add_library(remill_arch_aarch64 STATIC IMPORTED)
set_property(TARGET remill_arch_aarch64 PROPERTY IMPORTED_LOCATION "@REMILL_ARCH_AARCH64_LIBRARY_LOCATION@")

add_library(remill_arch_sparc32 STATIC IMPORTED)
set_property(TARGET remill_arch_sparc32 PROPERTY IMPORTED_LOCATION "@REMILL_ARCH_SPARC32_LIBRARY_LOCATION@")

add_library(remill_arch_sparc64 STATIC IMPORTED)
set_property(TARGET remill_arch_sparc64 PROPERTY IMPORTED_LOCATION "@REMILL_ARCH_SPARC64_LIBRARY_LOCATION@")

add_library(remill_version STATIC IMPORTED)
set_property(TARGET remill_version PROPERTY IMPORTED_LOCATION "@REMILL_VERSION_LIBRARY_LOCATION@")

add_library(remill INTERFACE)
target_link_libraries(remill INTERFACE
${LINKER_START_GROUP}
remill_bc
remill_os
remill_arch
remill_arch_x86
remill_arch_aarch32
remill_arch_aarch64
remill_arch_sparc32
remill_arch_sparc64
remill_version
@THIRDPARTY_LIBRARY_FILES@
${LINKER_END_GROUP}
)

target_include_directories(remill INTERFACE @THIRDPARTY_INCLUDE_DIRECTORIES@)
target_include_directories(remill INTERFACE @REMILL_INCLUDE_LOCATION@)
target_compile_options(remill INTERFACE @REMILL_COMPILE_OPTIONS@)
target_compile_definitions(remill INTERFACE @REMILL_COMPILE_DEFINITIONS@)

# Add a dummy 'semantics' target to satisfy the protobuf generator
add_custom_target(semantics)
# External libs
include(CMakeFindDependencyMacro)
find_dependency(XED)
find_dependency(glog)
find_dependency(LLVM)
# NOTE: If changing this, also replicate in CMakeLists.txt
if (LLVM_WITH_Z3)
find_dependency(Z3)
get_target_property(LLVMSupport_LIBS LLVMSupport INTERFACE_LINK_LIBRARIES)
list(REMOVE_ITEM LLVMSupport_LIBS Z3)
list(APPEND LLVMSupport_LIBS z3::libz3)
set_target_properties(LLVMSupport PROPERTIES
INTERFACE_LINK_LIBRARIES "${LLVMSupport_LIBS}")
endif()

# Exported Targets
include("${CMAKE_CURRENT_LIST_DIR}/remillTargets.cmake")

if(TARGET thirdparty_llvm)
# Need this so that LLVM doesn't hardcode it's include directories
set_target_properties(thirdparty_llvm PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LLVM_INCLUDE_DIRS}"
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${LLVM_INCLUDE_DIRS}"
)
endif()

endif()

set(remill_setup_vcpkg False)
63 changes: 0 additions & 63 deletions cmake/remillConfig_vcpkg.cmake.in

This file was deleted.

8 changes: 4 additions & 4 deletions cmake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function(GetPublicIncludeFolders output_variable)
set("${output_variable}" ${collected_include_dirs} PARENT_SCOPE)
endfunction()

function(InstallExternalTarget target_name target_path install_directory installed_file_name)
function(InstallExternalTarget target_name target_path install_type installed_file_name)
# Get the optional rpath parameter
set(additional_arguments ${ARGN})
list(LENGTH additional_arguments additional_argument_count)
Expand Down Expand Up @@ -195,8 +195,8 @@ function(InstallExternalTarget target_name target_path install_directory install
message(FATAL_ERROR "InstallExternalTarget: The following target already exists: ${target_name}")
endif()

if("${install_directory}" STREQUAL "")
message(FATAL_ERROR "InstallExternalTarget: Invalid install directory specified")
if("${install_type}" STREQUAL "")
message(FATAL_ERROR "InstallExternalTarget: Invalid install type specified")
endif()

# Generate the target
Expand All @@ -218,7 +218,7 @@ function(InstallExternalTarget target_name target_path install_directory install
add_custom_target("${target_name}" ALL DEPENDS "${output_file_path}")

install(FILES "${output_file_path}"
DESTINATION "${install_directory}"
TYPE ${install_type}
PERMISSIONS OWNER_READ OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
Expand Down
Loading

0 comments on commit 1caf764

Please sign in to comment.