From 1ad68ada48c3c9c94f2e99a4828b39c61201d9e2 Mon Sep 17 00:00:00 2001 From: Andrew Young Date: Mon, 16 Sep 2019 11:52:32 -0400 Subject: [PATCH 1/5] Add import library target for libz Signed-off-by: Andrew Young --- cmake/modules/FindLibZ.cmake | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/cmake/modules/FindLibZ.cmake b/cmake/modules/FindLibZ.cmake index 7c21116f292..83277365fce 100644 --- a/cmake/modules/FindLibZ.cmake +++ b/cmake/modules/FindLibZ.cmake @@ -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() From 5b75da3dd5d6d01a8f40f7241641945d5d8d4700 Mon Sep 17 00:00:00 2001 From: Andrew Young Date: Mon, 16 Sep 2019 11:52:51 -0400 Subject: [PATCH 2/5] Add imported library target for libdwarf Signed-off-by: Andrew Young --- cmake/modules/FindLibDwarf.cmake | 93 +++++++++++++++++++------------- 1 file changed, 57 insertions(+), 36 deletions(-) diff --git a/cmake/modules/FindLibDwarf.cmake b/cmake/modules/FindLibDwarf.cmake index 3ddb7043bfe..fe5fce74d6f 100644 --- a/cmake/modules/FindLibDwarf.cmake +++ b/cmake/modules/FindLibDwarf.cmake @@ -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 @@ -20,37 +20,33 @@ ############################################################################# # 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() @@ -58,7 +54,7 @@ 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() @@ -70,19 +66,19 @@ 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() @@ -90,7 +86,7 @@ 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() @@ -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() From 1e601128a1e7208b9a262ef2f7da9299b8f79931 Mon Sep 17 00:00:00 2001 From: Andrew Young Date: Mon, 16 Sep 2019 15:50:07 -0400 Subject: [PATCH 3/5] Add imported library for libelf Signed-off-by: Andrew Young --- cmake/modules/FindLibElf.cmake | 50 +++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/cmake/modules/FindLibElf.cmake b/cmake/modules/FindLibElf.cmake index a4e2dc99f22..2ebe3f197b1 100644 --- a/cmake/modules/FindLibElf.cmake +++ b/cmake/modules/FindLibElf.cmake @@ -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 @@ -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) @@ -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() From ed395bad5296e771278889cc70722b6ac5dfb645 Mon Sep 17 00:00:00 2001 From: Andrew Young Date: Mon, 16 Sep 2019 15:50:58 -0400 Subject: [PATCH 4/5] Add imported library for diasdk Signed-off-by: Andrew Young --- cmake/modules/FindDiaSDK.cmake | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/cmake/modules/FindDiaSDK.cmake b/cmake/modules/FindDiaSDK.cmake index 44be6f771e7..6d48340e017 100644 --- a/cmake/modules/FindDiaSDK.cmake +++ b/cmake/modules/FindDiaSDK.cmake @@ -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 @@ -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() From 47a1d1d9ca22fe3eb644a2aceb02b9e7de1d3e80 Mon Sep 17 00:00:00 2001 From: Andrew Young Date: Mon, 16 Sep 2019 16:18:24 -0400 Subject: [PATCH 5/5] Use imported libraries in ddr-scanner Signed-off-by: Andrew Young --- ddr/lib/ddr-scanner/CMakeLists.txt | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/ddr/lib/ddr-scanner/CMakeLists.txt b/ddr/lib/ddr-scanner/CMakeLists.txt index 778c2cffc82..a7d6894b69b 100644 --- a/ddr/lib/ddr-scanner/CMakeLists.txt +++ b/ddr/lib/ddr-scanner/CMakeLists.txt @@ -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 @@ -33,33 +33,22 @@ 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 @@ -67,7 +56,6 @@ elseif(OMR_HOST_OS STREQUAL "linux") dwarf/DwarfFunctions.cpp dwarf/DwarfScanner.cpp ) - elseif(OMR_HOST_OS STREQUAL "osx") target_sources(omr_ddr_scanner PRIVATE @@ -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}