diff options
author | Kefu Chai <tchaikov@gmail.com> | 2022-12-20 03:38:27 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-01-20 15:14:39 (GMT) |
commit | 3b1c19f00a0973d1d70e823cf54a9047d20cb80a (patch) | |
tree | a5bb5263dc7661d236a5adae878f1661ca458294 /Modules | |
parent | e2be23a2b39f4380f32fe65ba770addc154579c7 (diff) | |
download | CMake-3b1c19f00a0973d1d70e823cf54a9047d20cb80a.zip CMake-3b1c19f00a0973d1d70e823cf54a9047d20cb80a.tar.gz CMake-3b1c19f00a0973d1d70e823cf54a9047d20cb80a.tar.bz2 |
FindOpenSP: Use pkg-config only as hints for main code path
before this change, pkg_check_modules(.. IMPORTED_TARGET GLOBAL)
is used for creating an imported target from which another imported
interface library named OpenSP::OpenSP is created. but pkg-config
does not account for all of CMake's other search behavior controls,
such as CMAKE_FIND_ROOT_PATH. neither does it export the full path
with OpenSP_LIBRARY.
after this change, the paths found by pkg-config are only used
as hints for the find_*() commands. and some cleanup are included:
* be QUIET when calling find_package(PkgConfig ..) and
pkg_check_modules(..) as they are distracting from user's point of
view. what matters is the output of find_package_handle_standard_args()
* parse the version and check for the existance of symbol as long as
header path is found. because they only use header files.
* define OpenSP_LIBRARY as long as it exists. this just follows
the convention. as OpenSP_FOUND implies a valid OpenSP_LIBRARY.
* wrap and intent multi-line command calls for better readability
* check OpenSP_FOUND before adding OpenSP::OpenSP, it's more
idiomatic.
Fixes: #24313
Signed-off-by: Kefu Chai <tchaikov@gmail.com>
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/FindOpenSP.cmake | 73 |
1 files changed, 39 insertions, 34 deletions
diff --git a/Modules/FindOpenSP.cmake b/Modules/FindOpenSP.cmake index 655dd65..25d0e6f 100644 --- a/Modules/FindOpenSP.cmake +++ b/Modules/FindOpenSP.cmake @@ -63,24 +63,17 @@ The following cache variables may also be set: #]=======================================================================] -if (NOT OpenSP_INCLUDE_DIR AND NOT OpenSP_LIBRARY) - find_package(PkgConfig) - if (PkgConfig_FOUND) - pkg_check_modules(OpenSP IMPORTED_TARGET GLOBAL opensp) - - if (OpenSP_FOUND) - add_library(OpenSP::OpenSP INTERFACE IMPORTED) - target_link_libraries(OpenSP::OpenSP INTERFACE PkgConfig::OpenSP) - - set(OpenSP_INCLUDE_DIR ${OpenSP_INCLUDE_DIRS}) - set(OpenSP_LIBRARY ${OpenSP_LIBRARIES}) - endif () - endif () +find_package(PkgConfig QUIET) +if (PkgConfig_FOUND) + pkg_check_modules(PC_OpenSP QUIET opensp) endif () if (NOT OpenSP_INCLUDE_DIR) find_path(OpenSP_INCLUDE_DIR NAMES ParserEventGeneratorKit.h + HINTS + ${PC_OpenSP_INCLUDEDIRS} + ${PC_OpenSP_INCLUDE_DIRS} PATH_SUFFIXES OpenSP opensp DOC "The OpenSP include directory" ) @@ -89,17 +82,23 @@ endif () if (NOT OpenSP_LIBRARY) find_library(OpenSP_LIBRARY_RELEASE NAMES osp libosp opensp libopensp sp133 libsp + HINTS + ${PC_OpenSP_LIBDIR} + ${PC_OpenSP_LIBRARY_DIRS} ) find_library(OpenSP_LIBRARY_DEBUG NAMES ospd libospd openspd libopenspd sp133d libspd + HINTS + ${PC_OpenSP_LIBDIR} + ${PC_OpenSP_LIBRARY_DIRS} ) include(SelectLibraryConfigurations) select_library_configurations(OpenSP) endif () -if (OpenSP_INCLUDE_DIR AND OpenSP_LIBRARY) +if (OpenSP_INCLUDE_DIR) if (EXISTS "${OpenSP_INCLUDE_DIR}/config.h") if (NOT OpenSP_VERSION) file(STRINGS "${OpenSP_INCLUDE_DIR}/config.h" opensp_version_str REGEX "^#define[\t ]+SP_VERSION[\t ]+\".*\"") @@ -116,38 +115,44 @@ if (OpenSP_INCLUDE_DIR AND OpenSP_LIBRARY) include(CheckCXXSymbolExists) check_cxx_symbol_exists(SP_MULTI_BYTE "${OpenSP_INCLUDE_DIR}/config.h" OpenSP_MULTI_BYTE) endif () +endif () - if (NOT TARGET OpenSP::OpenSP) - set(OpenSP_INCLUDE_DIRS ${OpenSP_INCLUDE_DIR}) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(OpenSP + FOUND_VAR OpenSP_FOUND + REQUIRED_VARS OpenSP_LIBRARY OpenSP_INCLUDE_DIR + VERSION_VAR OpenSP_VERSION + ) + +mark_as_advanced(OpenSP_INCLUDE_DIR OpenSP_LIBRARY OpenSP_MULTI_BYTE) +if (OpenSP_FOUND) + set(OpenSP_INCLUDE_DIRS ${OpenSP_INCLUDE_DIR}) + if (NOT TARGET OpenSP::OpenSP) add_library(OpenSP::OpenSP UNKNOWN IMPORTED) - set_target_properties(OpenSP::OpenSP PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${OpenSP_INCLUDE_DIRS}") + if (EXISTS "${OpenSP_LIBRARY}") + set_target_properties(OpenSP::OpenSP PROPERTIES + IMPORTED_LOCATION "${OpenSP_LIBRARY}") + endif () + set_target_properties(OpenSP::OpenSP PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${OpenSP_INCLUDE_DIRS}") if (OpenSP_LIBRARY_RELEASE) - set_target_properties(OpenSP::OpenSP PROPERTIES IMPORTED_LOCATION_RELEASE "${OpenSP_LIBRARY_RELEASE}") - set_property(TARGET OpenSP::OpenSP APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(OpenSP::OpenSP PROPERTIES + IMPORTED_LOCATION_RELEASE "${OpenSP_LIBRARY_RELEASE}") + set_property(TARGET OpenSP::OpenSP APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) endif () if (OpenSP_LIBRARY_DEBUG) - set_target_properties(OpenSP::OpenSP PROPERTIES IMPORTED_LOCATION_DEBUG "${OpenSP_LIBRARY_DEBUG}") - set_property(TARGET OpenSP::OpenSP APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) - endif () - - if (NOT OpenSP_LIBRARY_RELEASE AND NOT OpenSP_LIBRARY_DEBUG) - set_property(TARGET OpenSP::OpenSP APPEND PROPERTY IMPORTED_LOCATION "${OpenSP_LIBRARY}") + set_target_properties(OpenSP::OpenSP PROPERTIES + IMPORTED_LOCATION_DEBUG "${OpenSP_LIBRARY_DEBUG}") + set_property(TARGET OpenSP::OpenSP APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) endif () endif () endif () -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(OpenSP - FOUND_VAR OpenSP_FOUND - REQUIRED_VARS OpenSP_LIBRARY OpenSP_INCLUDE_DIR - VERSION_VAR OpenSP_VERSION - ) - -mark_as_advanced(OpenSP_INCLUDE_DIR OpenSP_LIBRARY OpenSP_MULTI_BYTE) - include(FeatureSummary) set_package_properties(OpenSP PROPERTIES URL "http://openjade.sourceforge.net/doc/index.htm" |