From 0542a5df3b53e7fce3c9d0f12c9f236d92c8b2a1 Mon Sep 17 00:00:00 2001 From: Neil Carlson Date: Sat, 24 Mar 2018 17:40:38 -0600 Subject: [PATCH] Improvements to FindYAJL.cmake --- CMakeLists.txt | 5 +++++ cmake/FindYAJL.cmake | 25 ++++++++++++++----------- src/CMakeLists.txt | 2 +- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0534650..4d18594 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,11 @@ if(CMAKE_Fortran_COMPILER_ID MATCHES GNU) add_definitions(-DNO_2008_LHS_POLY_REALLOC) endif() +# RPATH handling for installed shared libraries and dynamically-linked +# executables. See http://www.cmake.org/Wiki/CMake_RPATH_handling +set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) + add_subdirectory(src) option(BUILD_TESTS "Build test programs" ON) diff --git a/cmake/FindYAJL.cmake b/cmake/FindYAJL.cmake index 06b83d0..c7d51d6 100644 --- a/cmake/FindYAJL.cmake +++ b/cmake/FindYAJL.cmake @@ -6,17 +6,20 @@ # YAJL_LIBRARIES # YAJL_VERSION # -# This module also defines the imported library target "yajl". It is -# generally enough to include "yajl" as a target link library; cmake +# This module defines the imported library target YAJL::YAJL. It is +# generally enough to include YAJL::YAJL as a target link library; cmake # will automatically handle adding the appropriate compile include flags # and collection of link libraries. # -# Set the variable CMAKE_PREFIX_PATH to provide a hint to the module for -# where to find the library and header file. This is searched before the -# standard system locations. +# Set the variable CMAKE_PREFIX_PATH or environment variable YAJL_ROOT to +# provide a hint to the module for where to find the library and header file. +# This is searched before the standard system locations. -find_path(YAJL_INCLUDE_DIR yajl/yajl_common.h) -find_library(YAJL_LIBRARY NAMES yajl yajl_s) +set(yajl_search_paths ENV YAJL_ROOT) +find_path(YAJL_INCLUDE_DIR NAMES yajl/yajl_common.h + HINTS ${yajl_search_paths} PATH_SUFFIXES include) +find_library(YAJL_LIBRARY NAMES yajl yajl_s + HINTS ${yajl_search_paths} PATH_SUFFIXES lib) if(NOT YAJL_VERSION) if(YAJL_INCLUDE_DIR AND YAJL_LIBRARY) @@ -37,16 +40,16 @@ endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(YAJL - REQUIRED_VARS YAJL_LIBRARY YAJL_INCLUDE_DIR + REQUIRED_VARS YAJL_LIBRARY YAJL_INCLUDE_DIR VERSION_VAR YAJL_VERSION) if(YAJL_FOUND) set(YAJL_INCLUDE_DIRS ${YAJL_INCLUDE_DIR}) set(YAJL_LIBRARIES ${YAJL_LIBRARY}) mark_as_advanced(YAJL_INCLUDE_DIR YAJL_LIBRARY) - if(NOT TARGET yajl) - add_library(yajl UNKNOWN IMPORTED) - set_target_properties(yajl PROPERTIES + if(NOT TARGET YAJL::YAJL) + add_library(YAJL::YAJL UNKNOWN IMPORTED) + set_target_properties(YAJL::YAJL PROPERTIES IMPORTED_LOCATION "${YAJL_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${YAJL_INCLUDE_DIRS}" INTERFACE_LINK_LIBRARIES "${YAJL_LIBRARIES}") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ee1d116..a70e905 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,7 +15,7 @@ target_include_directories(yajl_fort PUBLIC $ ) -target_link_libraries(yajl_fort yajl) +target_link_libraries(yajl_fort YAJL::YAJL) install(TARGETS yajl_fort EXPORT yajl_fort