diff --git a/cmake/modules/FindSHLWAPI.cmake b/cmake/modules/FindSHLWAPI.cmake --- a/cmake/modules/FindSHLWAPI.cmake +++ b/cmake/modules/FindSHLWAPI.cmake @@ -1,22 +1,41 @@ -# Try to find the SHLWAPI librairy -# SHLWAPI_FOUND - system has SHLWAPI lib -# SHLWAPI_INCLUDE_DIR - the SHLWAPI include directory -# SHLWAPI_LIBRARY - Libraries needed to use SHLWAPI +# Copyright (c) 2017-2020 The Bitcoin developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. -if(SHLWAPI_INCLUDE_DIR AND SHLWAPI_LIBRARY) - # Already in cache, be silent - set(SHLWAPI_FIND_QUIETLY TRUE) -endif() +# .rst: +# FindSHLWAPI +# -------------- +# +# Find the SHLWAPI library. The following conponents are +# available:: +# shlwapi +# +# This will define the following variables:: +# +# SHLWAPI_FOUND - True if the SHLWAPI library is found. +# SHLWAPI_INCLUDE_DIRS - List of the header include directories. +# SHLWAPI_LIBRARIES - List of the libraries. +# +# And the following imported targets:: +# +# SHLWAPI::shlwapi -find_path(SHLWAPI_INCLUDE_DIR NAMES shlwapi.h) -find_library(SHLWAPI_LIBRARY NAMES shlwapi) +find_path(SHLWAPI_INCLUDE_DIR + NAMES shlwapi.h +) -message(STATUS "SHLWAPI lib: " ${SHLWAPI_LIBRARY}) +set(SHLWAPI_INCLUDE_DIRS "${SHLWAPI_INCLUDE_DIR}") +mark_as_advanced(SHLWAPI_INCLUDE_DIR) -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(GMP DEFAULT_MSG SHLWAPI_INCLUDE_DIR SHLWAPI_LIBRARY) - -mark_as_advanced(SHLWAPI_INCLUDE_DIR SHLWAPI_LIBRARY) +include(ExternalLibraryHelper) +find_component(SHLWAPI shlwapi + NAMES shlwapi + INCLUDE_DIRS ${SHLWAPI_INCLUDE_DIRS} +) -set(SHLWAPI_LIBRARIES ${SHLWAPI_LIBRARY}) -set(SHLWAPI_INCLUDE_DIRS ${SHLWAPI_INCLUDE_DIR}) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SHLWAPI + REQUIRED_VARS + SHLWAPI_INCLUDE_DIR + HANDLE_COMPONENTS +) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -332,8 +332,16 @@ set(Boost_THREADAPI win32) find_package(SHLWAPI REQUIRED) - target_link_libraries(util ${SHLWAPI_LIBRARY}) - target_include_directories(util PUBLIC ${SHLWAPI_INCLUDE_DIR}) + # We cannot use the imported target here, because cmake will introduce an + # -isystem compilation directive and cause the build to fail with MinGw. + # This comes from a couple cmake bugs: + # - https://gitlab.kitware.com/cmake/cmake/issues/16291 + # - https://gitlab.kitware.com/cmake/cmake/issues/19095 + # These issues are solved from cmake 3.14.1. Once this version is enforced, + # the following can be used: + # target_link_libraries(util SHLWAPI::shlwapi) + target_link_libraries(util ${SHLWAPI_LIBRARIES}) + target_include_directories(util PUBLIC ${SHLWAPI_INCLUDE_DIRS}) find_library(WS2_32_LIBRARY NAMES ws2_32) target_link_libraries(util ${WS2_32_LIBRARY}) diff --git a/src/leveldb/CMakeLists.txt b/src/leveldb/CMakeLists.txt --- a/src/leveldb/CMakeLists.txt +++ b/src/leveldb/CMakeLists.txt @@ -82,8 +82,16 @@ ) find_package(SHLWAPI REQUIRED) - target_link_libraries(leveldb ${SHLWAPI_LIBRARY}) - target_include_directories(leveldb PUBLIC ${SHLWAPI_INCLUDE_DIR}) + # We cannot use the imported target here, because cmake will introduce an + # -isystem compilation directive and cause the build to fail with MinGw. + # This comes from a couple cmake bugs: + # - https://gitlab.kitware.com/cmake/cmake/issues/16291 + # - https://gitlab.kitware.com/cmake/cmake/issues/19095 + # These issues are solved from cmake 3.14.1. Once this version is enforced, + # the following can be used: + # target_link_libraries(leveldb SHLWAPI::shlwapi) + target_link_libraries(leveldb ${SHLWAPI_LIBRARIES}) + target_include_directories(leveldb PUBLIC ${SHLWAPI_INCLUDE_DIRS}) else() set(LEVELDB_PLATFORM POSIX) target_sources(leveldb PRIVATE port/port_posix.cc)