From b31281527a6d3b156b742d03917d82a61cbd99ad Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 13 Apr 2018 19:32:11 -0400 Subject: [PATCH] CMakeLists: Define an OProfile target and use it Allows us to bring includes and relevant libraries into scope by explicitly declaring linkage against the target as opposed to using a variable. Also removes the dumping of OProfile includes into the top-level directory. --- CMake/FindOProfile.cmake | 16 ++++++++++++++-- CMakeLists.txt | 1 - Source/Core/Common/CMakeLists.txt | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CMake/FindOProfile.cmake b/CMake/FindOProfile.cmake index b82e47307d..7f349307f0 100644 --- a/CMake/FindOProfile.cmake +++ b/CMake/FindOProfile.cmake @@ -7,13 +7,25 @@ find_path(OPROFILE_INCLUDE_DIR opagent.h) find_library(OPROFILE_LIBRARY opagent - PATH_SUFFIXES oprofile) + PATH_SUFFIXES oprofile +) set(OPROFILE_INCLUDE_DIRS ${OPROFILE_INCLUDE_DIR}) set(OPROFILE_LIBRARIES ${OPROFILE_LIBRARY}) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(OProfile DEFAULT_MSG - OPROFILE_LIBRARY OPROFILE_INCLUDE_DIR) + OPROFILE_LIBRARY OPROFILE_INCLUDE_DIR +) + +if (OPROFILE_FOUND) + if (NOT TARGET OProfile::OProfile) + add_library(OProfile::OProfile UNKNOWN IMPORTED) + set_target_properties(OProfile::OProfile PROPERTIES + IMPORTED_LOCATION ${OPROFILE_LIBRARIES} + INTERFACE_INCLUDE_DIRECTORIES ${OPROFILE_INCLUDE_DIRS} + ) + endif() +endif() mark_as_advanced(OPROFILE_INCLUDE_DIR OPROFILE_LIBRARY) diff --git a/CMakeLists.txt b/CMakeLists.txt index eae9557eac..d8f280f534 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -473,7 +473,6 @@ if(OPROFILING) if(OPROFILE_FOUND) message(STATUS "OProfile found, enabling profiling support") add_definitions(-DUSE_OPROFILE=1) - include_directories(${OPROFILE_INCLUDE_DIRS}) else() message(FATAL_ERROR "OProfile not found. Can't build profiling support.") endif() diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index 4ef3af3ac5..15c79c3d3b 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -146,7 +146,7 @@ if(USE_UPNP) endif() if(OPROFILE_FOUND) - target_link_libraries(common PRIVATE ${OPROFILE_LIBRARIES}) + target_link_libraries(common PRIVATE OProfile::OProfile) endif() if(UNIX)