Skip to content

Commit

Permalink
Merge pull request #4313 from youngar/import_libs
Browse files Browse the repository at this point in the history
Use importlibs for libdwarf and libz
  • Loading branch information
rwy7 authored Sep 17, 2019
2 parents baf7c30 + 47a1d1d commit 54fb162
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 77 deletions.
29 changes: 23 additions & 6 deletions cmake/modules/FindDiaSDK.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2017, 2018 IBM Corp. and others
# Copyright (c) 2017, 2019 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -56,8 +56,25 @@ find_package_handle_standard_args(DiaSDK
DIA2_H_DIR
)

if(DIASDK_FOUND)
set(DIASDK_DEFINITIONS -DHAVE_DIA)
set(DIASDK_INCLUDE_DIRS ${DIA2_H_DIR})
set(DIASDK_LIBRARIES ${DIAGUIDS_LIBRARY})
endif(DIASDK_FOUND)
if(NOT DIASDK_FOUND)
set(DIASDK_DEFINITIONS NOTFOUND)
set(DIASDK_INCLUDE_DIRS NOTFOUND)
set(DIASDK_LIBRARIES NOTFOUND)
return()
endif()

# Everything below is only set if the library is found

set(DIASDK_DEFINITIONS -DHAVE_DIA)
set(DIASDK_INCLUDE_DIRS ${DIA2_H_DIR})
set(DIASDK_LIBRARIES ${DIAGUIDS_LIBRARY})

if(NOT TARGET DiaSDK::dia)
add_library(DiaSDK::diasdk UNKNOWN IMPORTED)
set_target_properties(DiaSDK::diasdk
PROPERTIES
IMPORTED_LOCATION "${DIAGUIDS_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${DIASDK_INCLUDE_DIRS}"
INTERFACE_COMPILE_DEFINITIONS "${DIASDK_DEFINITIONS}"
)
endif()
93 changes: 57 additions & 36 deletions cmake/modules/FindLibDwarf.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2017, 2017 IBM Corp. and others
# Copyright (c) 2017, 2019 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
Expand All @@ -20,45 +20,41 @@
#############################################################################

# Find libdwarf.
# Requires:
# Optional dependencies:
# LibElf
# LibZ
# Will set:
# LIBDWARF_FOUND
# LIBDWARF_INCLUDE_DIRS
# LIBDWARF_LIBRARIES
# LIBDWARF_DEFINITIONS

if(DEFINED LibDwarf_REQUIRED)
set(LibElf_REQUIRED)
endif()

find_package(LibElf)

find_package(LibZ)

# Find dwarf.h
# Will set:
# DWARF_H_DEFINITIONS
# DWARF_H_FOUND
# DWARF_H_INCLUDE_DIRS
# DWARF_H_DEFINITIONS

set(DWARF_H_DEFINITIONS)
set(DWARF_H_INCLUDE_DIRS)
set(DWARF_H_FOUND false)
set(DWARF_H_INCLUDE_DIRS)

find_path(DWARF_H_INCLUDE_DIR "dwarf.h")

if(DWARF_H_INCLUDE_DIR)
list(APPEND DWARF_H_INCLUDE_DIRS "${DWARF_H_INCLUDE_DIR}")
list(APPEND DWARF_H_DEFINITIONS -DHAVE_DWARF_H)
list(APPEND DWARF_H_DEFINITIONS HAVE_DWARF_H)
set(DWARF_H_FOUND true)
endif()

find_path(LIBDWARF_DWARF_H_INCLUDE_DIR "libdwarf/dwarf.h")

if(LIBDWARF_DWARF_H_INCLUDE_DIR)
list(APPEND DWARF_H_INCLUDE_DIRS "${LIBDWARF_DWARF_H_INCLUDE_DIR}")
list(APPEND DWARF_H_DEFINITIONS -DHAVE_LIBDWARF_DWARF_H)
list(APPEND DWARF_H_DEFINITIONS HAVE_LIBDWARF_DWARF_H)
set(DWARF_H_FOUND true)
endif()

Expand All @@ -70,27 +66,27 @@ endif()

# Find libdwarf.h
# Will set:
# LIBDWARF_H_DEFINITIONS
# LIBDWARF_H_FOUND
# LIBDWARF_H_INCLUDE_DIRS
# LIBDWARF_H_DEFINITIONS

set(LIBDWARF_H_DEFINITIONS)
set(LIBDWARF_H_INCLUDE_DIRS)
set(LIBDWARF_H_FOUND false)
set(LIBDWARF_H_INCLUDE_DIRS)

find_path(LIBDWARF_H_INCLUDE_DIR "libdwarf.h")

if(LIBDWARF_H_INCLUDE_DIR)
list(APPEND LIBDWARF_H_INCLUDE_DIRS "${LIBDWARF_H_INCLUDE_DIR}")
list(APPEND LIBDWARF_H_DEFINITIONS -DHAVE_LIBDWARF_H)
list(APPEND LIBDWARF_H_DEFINITIONS HAVE_LIBDWARF_H)
set(LIBDWARF_H_FOUND true)
endif()

find_path(LIBDWARF_LIBDWARF_H_INCLUDE_DIR "libdwarf/libdwarf.h")

if(LIBDWARF_LIBDWARF_H_INCLUDE_DIR)
list(APPEND LIBDWARF_H_INCLUDE_DIRS "${LIBDWARF_LIBDWARF_H_INCLUDE_DIR}")
list(APPEND LIBDWARF_H_DEFINITIONS -DHAVE_LIBDWARF_LIBDWARF_H)
list(APPEND LIBDWARF_H_DEFINITIONS HAVE_LIBDWARF_LIBDWARF_H)
set(LIBDWARF_H_FOUND true)
endif()

Expand All @@ -113,29 +109,54 @@ find_package_handle_standard_args(LibDwarf
LIBDWARF_LIBRARY
DWARF_H_FOUND
LIBDWARF_H_FOUND
LIBELF_FOUND
)

if(LIBDWARF_FOUND)
set(LIBDWARF_INCLUDE_DIRS
${DWARF_H_INCLUDE_DIRS}
${LIBDWARF_H_INCLUDE_DIRS}
${LIBELF_INCLUDE_DIRS}
${LIBZ_INCLUDE_DIRS}
)
set(LIBDWARF_LIBRARIES
${LIBDWARF_LIBRARY}
${LIBELF_LIBRARIES}
${LIBZ_LIBRARIES}
)
set(LIBDWARF_DEFINITIONS
${DWARF_H_DEFINITIONS}
${LIBDWARF_H_DEFINITIONS}
${LIBELF_DEFINITIONS}
${LIBZ_DEFINITIONS}
)
else(LIBDWARF_FOUND)
if(NOT LIBDWARF_FOUND)
set(LIBDWARF_INCLUDE_DIRS NOTFOUND)
set(LIBDWARF_LIBRARIES NOTFOUND)
set(LIBDWARF_DEFINITIONS NOTFOUND)
endif(LIBDWARF_FOUND)
return()
endif()

# Everything below is only set if the library is found

set(LIBDWARF_INCLUDE_DIRS ${DWARF_H_INCLUDE_DIRS} ${LIBDWARF_H_INCLUDE_DIRS})
set(LIBDWARF_LIBRARIES ${LIBDWARF_LIBRARY})
set(LIBDWARF_DEFINITIONS ${DWARF_H_DEFINITIONS} ${LIBDWARF_H_DEFINITIONS})

if(LibZ_FOUND)
list(APPEND LIBDWARF_INCLUDE_DIRS ${LIBZ_INCLUDE_DIRS})
list(APPEND LIBDWARF_LIBRARIES ${LIBZ_LIBRARIES})
list(APPEND LIBDWARF_DEFINITIONS ${LIBZ_DEFINITIONS})
endif(LibZ_FOUND)

if(LibElf_FOUND)
list(APPEND LIBDWARF_INCLUDE_DIRS ${LIBELF_INCLUDE_DIRS})
list(APPEND LIBDWARF_LIBRARIES ${LIBELF_LIBRARIES})
list(APPEND LIBDWARF_DEFINITIONS ${LIBELF_DEFINITIONS})
endif(LibElf_FOUND)

if(NOT TARGET LibDwarf::dwarf)
add_library(LibDwarf::dwarf UNKNOWN IMPORTED)

set_target_properties(LibDwarf::dwarf
PROPERTIES
IMPORTED_LOCATION "${LIBDWARF_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${DWARF_H_INCLUDE_DIRS};${LIBDWARF_H_INCLUDE_DIRS}"
INTERFACE_COMPILE_DEFINITIONS "${DWARF_H_DEFINITIONS};${LIBDWARF_H_DEFINITIONS}"
)

if(LibZ_FOUND)
set_property(
TARGET LibDwarf::dwarf APPEND
PROPERTY INTERFACE_LINK_LIBRARIES LibZ::z
)
endif(LibZ_FOUND)

if(LibElf_FOUND)
set_property(
TARGET LibDwarf::dwarf APPEND
PROPERTY INTERFACE_LINK_LIBRARIES LibElf::elf
)
endif(LibElf_FOUND)
endif()
50 changes: 40 additions & 10 deletions cmake/modules/FindLibElf.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2017, 2017 IBM Corp. and others
# Copyright (c) 2017, 2019 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
Expand All @@ -20,12 +20,16 @@
#############################################################################

# Find libelf
# Optional dependencies:
# LibZ
# Will set:
# LIBELF_FOUND
# LIBELF_INCLUDE_DIRS
# LIBELF_LIBRARIES
# LIBELF_DEFINITIONS

find_package(LibZ)

find_path(ELF_H_INCLUDE_DIR elf.h)

find_path(LIBELF_H_INCLUDE_DIR libelf.h)
Expand All @@ -41,13 +45,39 @@ find_package_handle_standard_args(LibElf
LIBELF_H_INCLUDE_DIR
)

if(LIBELF_FOUND)
set(LIBELF_INCLUDE_DIRS
${ELF_H_INCLUDE_DIR}
${LIBELF_H_INCLUDE_DIR}
)
set(LIBELF_LIBRARIES
${LIBELF_LIBRARY}
if(NOT LIBELF_FOUND)
set(LIBELF_INCLUDE_DIRS NOTFOUND)
set(LIBELF_LIBRARIES NOTFOUND)
set(LIBELF_DEFINITIONS NOTFOUND)
return()
endif()

# Everything below is only set if the library is found

set(LIBELF_INCLUDE_DIRS ${ELF_H_INCLUDE_DIR} ${LIBELF_H_INCLUDE_DIR})
set(LIBELF_LIBRARIES ${LIBELF_LIBRARY})
set(LIBELF_DEFINITIONS "")

if(LibZ_FOUND)
list(APPEND LIBELF_INCLUDE_DIRS ${LIBZ_INCLUDE_DIRS})
list(APPEND LIBELF_LIBRARIES ${LIBZ_LIBRARIES})
list(APPEND LIBELF_DEFINITIONS ${LIBZ_DEFINITIONS})
endif(LibZ_FOUND)

if(NOT TARGET LibElf::elf)
add_library(LibElf::elf UNKNOWN IMPORTED)

set_target_properties(LibElf::elf
PROPERTIES
IMPORTED_LOCATION "${LIBELF_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${ELF_H_INCLUDE_DIR};${LIBELF_H_INCLUDE_DIR}"
INTERFACE_COMPILE_DEFINITIONS ""
)
set (LIBELF_DEFINITIONS "")
endif(LIBELF_FOUND)

if(LibZ_FOUND)
set_property(
TARGET LibElf::elf APPEND
PROPERTY INTERFACE_LINK_LIBRARIES LibZ::z
)
endif(LibZ_FOUND)
endif()
30 changes: 22 additions & 8 deletions cmake/modules/FindLibZ.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,26 @@ find_package_handle_standard_args(LibZ
ZLIB_H_INCLUDE_DIR
)

if(LIBZ_FOUND)
set(LIBZ_INCLUDE_DIRS
${ZLIB_H_INCLUDE_DIR}
)
set(LIBZ_LIBRARIES
${LIBZ_LIBRARY}
if(NOT LIBZ_FOUND)
set(LIBZ_INCLUDE_DIRS NOTFOUND)
set(LIBZ_LIBRARIES NOTFOUND)
set(LIBZ_DEFINITIONS NOTFOUND)
return()
endif()

# Everything below is only set if the library is found

set(LIBZ_INCLUDE_DIRS ${ZLIB_H_INCLUDE_DIR})
set(LIBZ_LIBRARIES ${LIBZ_LIBRARY})
set(LIBZ_DEFINITIONS "")

if(NOT TARGET LibZ::z)
add_library(LibZ::z UNKNOWN IMPORTED)

set_target_properties(LibZ::z
PROPERTIES
IMPORTED_LOCATION "${LIBZ_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${LIBZ_INCLUDE_DIRS}"
INTERFACE_COMPILE_DEFINITIONS "${LIBZ_DEFINITIONS}"
)
set (LIBZ_DEFINITIONS "")
endif(LIBZ_FOUND)
endif()
23 changes: 6 additions & 17 deletions ddr/lib/ddr-scanner/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2017, 2017 IBM Corp. and others
# Copyright (c) 2017, 2019 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -33,41 +33,29 @@ target_link_libraries(omr_ddr_scanner

if(OMR_HOST_OS STREQUAL "win")
find_package(DiaSDK REQUIRED)

target_sources(omr_ddr_scanner
PRIVATE
pdb/PdbScanner.cpp
)

target_link_libraries(omr_ddr_scanner
PUBLIC
${DIASDK_LIBRARIES}
)
target_include_directories(omr_ddr_scanner
PUBLIC
${DIASDK_INCLUDE_DIRS}
DiaSDK::diasdk
)
elseif(OMR_HOST_OS STREQUAL "linux")

find_package(LibDwarf REQUIRED)

target_link_libraries(omr_ddr_scanner
PUBLIC
${LIBDWARF_LIBRARIES}
)
target_include_directories(omr_ddr_scanner
PUBLIC
${LIBDWARF_INCLUDE_DIRS}
)
target_compile_definitions(omr_ddr_scanner
PUBLIC
${LIBDWARF_DEFINITIONS}
LibDwarf::dwarf
)

target_sources(omr_ddr_scanner
PRIVATE
dwarf/DwarfFunctions.cpp
dwarf/DwarfScanner.cpp
)

elseif(OMR_HOST_OS STREQUAL "osx")
target_sources(omr_ddr_scanner
PRIVATE
Expand All @@ -82,6 +70,7 @@ elseif(OMR_HOST_OS STREQUAL "aix")
dwarf/DwarfFunctions.cpp
dwarf/DwarfScanner.cpp
)

target_link_libraries(omr_ddr_scanner
PUBLIC
${LIBDWARF_LIBRARIES}
Expand Down

0 comments on commit 54fb162

Please sign in to comment.