From 5b10a804016e07e705d76e87824f4f6506a3adad Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Sun, 16 Apr 2023 00:57:34 -0500 Subject: [PATCH] CMake: Use targets for all optionally-external dependencies --- CMake/FindCUBEB.cmake | 2 +- CMake/FindLZO.cmake | 15 ++++ CMake/FindLibUSB.cmake | 7 ++ CMake/FindMBEDTLS.cmake | 59 ++++++++++--- CMake/FindMINIUPNPC.cmake | 11 ++- CMake/FindSFML.cmake | 16 ++++ CMakeLists.txt | 100 +++++------------------ Externals/LZO/CMakeLists.txt | 1 + Externals/SDL/CMakeLists.txt | 17 ++++ Externals/SFML/CMakeLists.txt | 10 ++- Externals/cubeb/CMakeLists.txt | 1 + Externals/curl/lib/CMakeLists.txt | 6 +- Externals/enet/CMakeLists.txt | 4 +- Externals/libspng/CMakeLists.txt | 5 +- Externals/libusb/CMakeLists.txt | 1 + Externals/mbedtls/library/CMakeLists.txt | 1 + Externals/minizip/CMakeLists.txt | 2 +- Source/Core/AudioCommon/CMakeLists.txt | 2 +- Source/Core/Common/CMakeLists.txt | 11 +-- Source/Core/Core/CMakeLists.txt | 14 ++-- Source/Core/DiscIO/CMakeLists.txt | 2 +- Source/Core/InputCommon/CMakeLists.txt | 8 +- Source/Core/UICommon/CMakeLists.txt | 6 +- Source/Core/UpdaterCommon/CMakeLists.txt | 2 +- Source/Core/VideoCommon/CMakeLists.txt | 2 +- 25 files changed, 172 insertions(+), 133 deletions(-) create mode 100644 CMake/FindLZO.cmake create mode 100644 Externals/SDL/CMakeLists.txt diff --git a/CMake/FindCUBEB.cmake b/CMake/FindCUBEB.cmake index c0a730c7ab..94ed431a9b 100644 --- a/CMake/FindCUBEB.cmake +++ b/CMake/FindCUBEB.cmake @@ -6,7 +6,7 @@ include(FindPackageHandleStandardArgs) find_package_handle_standard_args(CUBEB DEFAULT_MSG CUBEB_INCLUDE_DIR CUBEB_LIBRARY) -if(CUBEB_FOUND AND NOT TARGET CUBEB) +if(CUBEB_FOUND AND NOT TARGET cubeb::cubeb) add_library(cubeb::cubeb UNKNOWN IMPORTED) set_target_properties(cubeb::cubeb PROPERTIES IMPORTED_LOCATION "${CUBEB_LIBRARY}" diff --git a/CMake/FindLZO.cmake b/CMake/FindLZO.cmake new file mode 100644 index 0000000000..2a146b37c8 --- /dev/null +++ b/CMake/FindLZO.cmake @@ -0,0 +1,15 @@ +find_path(LZO_INCLUDE_DIR lzo/lzo1x.h) +find_library(LZO_LIBRARY lzo2) +mark_as_advanced(LZO_INCLUDE_DIR LZO_LIBRARY) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(LZO DEFAULT_MSG + LZO_INCLUDE_DIR LZO_LIBRARY) + +if(LZO_FOUND AND NOT TARGET LZO::LZO) + add_library(LZO::LZO UNKNOWN IMPORTED) + set_target_properties(LZO::LZO PROPERTIES + IMPORTED_LOCATION "${LZO_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${LZO_INCLUDE_DIR}" + ) +endif() diff --git a/CMake/FindLibUSB.cmake b/CMake/FindLibUSB.cmake index dec0b98b07..c087edfcb8 100644 --- a/CMake/FindLibUSB.cmake +++ b/CMake/FindLibUSB.cmake @@ -40,4 +40,11 @@ elseif (NOT LIBUSB_FOUND) mark_as_advanced(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARIES) endif () +if(LIBUSB_FOUND AND NOT TARGET LibUSB::LibUSB) + add_library(LibUSB::LibUSB UNKNOWN IMPORTED) + set_target_properties(LibUSB::LibUSB PROPERTIES + IMPORTED_LOCATION "${LIBUSB_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${LIBUSB_INCLUDE_DIR}" + ) +endif() diff --git a/CMake/FindMBEDTLS.cmake b/CMake/FindMBEDTLS.cmake index 6059dc9639..6512cc92f6 100644 --- a/CMake/FindMBEDTLS.cmake +++ b/CMake/FindMBEDTLS.cmake @@ -7,18 +7,53 @@ find_library(MBEDCRYPTO_LIBRARY mbedcrypto PATH_SUFFIXES mbedtls2) set(MBEDTLS_INCLUDE_DIRS ${MBEDTLS_INCLUDE_DIR}) set(MBEDTLS_LIBRARIES ${MBEDTLS_LIBRARY} ${MBEDX509_LIBRARY} ${MBEDCRYPTO_LIBRARY}) -set(CMAKE_REQUIRED_INCLUDES ${MBEDTLS_INCLUDE_DIRS}) -check_cxx_source_compiles(" - #include - #if MBEDTLS_VERSION_NUMBER < 0x021C0000 - #error \"Your mbed TLS version is too old.\" - #endif - int main() {}" - MBEDTLS_VERSION_OK) -unset(CMAKE_REQUIRED_INCLUDES) +if(NOT MBEDTLS_INCLUDE_DIR STREQUAL "MBEDTLS_INCLUDE_DIR-NOTFOUND") + if(EXISTS ${MBEDTLS_INCLUDE_DIR}/mbedtls/build_info.h) + file(STRINGS ${MBEDTLS_INCLUDE_DIR}/mbedtls/build_info.h MBEDTLS_VERSION_STR REGEX "^#define[ \t]+MBEDTLS_VERSION_STRING[\t ].*") + else() + file(STRINGS ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLS_VERSION_STR REGEX "^#define[ \t]+MBEDTLS_VERSION_STRING[\t ].*") + endif() + string(REGEX REPLACE "^#define[\t ]+MBEDTLS_VERSION_STRING[\t ]+\"([.0-9]+)\".*" "\\1" MBEDTLS_VERSION ${MBEDTLS_VERSION_STR}) +endif() -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(MBEDTLS DEFAULT_MSG - MBEDTLS_INCLUDE_DIR MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY MBEDTLS_VERSION_OK) +if(NOT MBEDTLS_INCLUDE_DIR STREQUAL "MBEDTLS_INCLUDE_DIR-NOTFOUND" AND MBEDTLS_VERSION VERSION_GREATER_EQUAL 3) + # Once CMake 3.19 is required, we can enable HANDLE_VERSION_RANGE and use that + if(MBEDTLS_FIND_REQUIRED) + set(type FATAL_ERROR) + else() + set(type STATUS) + endif() + if(MBEDTLS_FIND_REQUIRED OR NOT MBEDTLS_FIND_QUIETLY) + message(${type} "Could NOT find MBEDTLS: Found unsuitable version \"${MBEDTLS_VERSION}\", but a 2.x version is required (found ${MBEDTLS_INCLUDE_DIR})") + endif() + set(MBEDTLS_FOUND FALSE) +else() + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(MBEDTLS + REQUIRED_VARS MBEDTLS_INCLUDE_DIR MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY + VERSION_VAR MBEDTLS_VERSION) +endif() mark_as_advanced(MBEDTLS_INCLUDE_DIR MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY) + +if(MBEDTLS_FOUND) + add_library(MbedTLS::mbedcrypto UNKNOWN IMPORTED) + set_target_properties(MbedTLS::mbedcrypto PROPERTIES + IMPORTED_LOCATION "${MBEDCRYPTO_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${MBEDTLS_INCLUDE_DIR}" + ) + + add_library(MbedTLS::mbedx509 UNKNOWN IMPORTED) + set_target_properties(MbedTLS::mbedx509 PROPERTIES + IMPORTED_LOCATION "${MBEDX509_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${MBEDTLS_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES MbedTLS::mbedcrypto + ) + + add_library(MbedTLS::mbedtls UNKNOWN IMPORTED) + set_target_properties(MbedTLS::mbedtls PROPERTIES + IMPORTED_LOCATION "${MBEDTLS_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${MBEDTLS_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES MbedTLS::mbedx509 + ) +endif() diff --git a/CMake/FindMINIUPNPC.cmake b/CMake/FindMINIUPNPC.cmake index f9a14e2a89..edfc5b2b9d 100644 --- a/CMake/FindMINIUPNPC.cmake +++ b/CMake/FindMINIUPNPC.cmake @@ -5,14 +5,17 @@ find_path(MINIUPNPC_INCLUDE_DIR miniupnpc.h PATH_SUFFIXES miniupnpc) find_library(MINIUPNPC_LIBRARY miniupnpc) if(MINIUPNPC_INCLUDE_DIR) - file(STRINGS "${MINIUPNPC_INCLUDE_DIR}/miniupnpc.h" MINIUPNPC_API_VERSION_STR REGEX "^#define[\t ]+MINIUPNPC_API_VERSION[\t ]+[0-9]+") - if(MINIUPNPC_API_VERSION_STR) - string(REGEX REPLACE "^#define[\t ]+MINIUPNPC_API_VERSION[\t ]+([0-9]+)" "\\1" MINIUPNPC_API_VERSION ${MINIUPNPC_API_VERSION_STR}) + file(STRINGS "${MINIUPNPC_INCLUDE_DIR}/miniupnpc.h" MINIUPNPC_VERSION_STR REGEX "^#define[\t ]+MINIUPNPC_VERSION[\t ]+.*") + if(MINIUPNPC_VERSION_STR) + string(REGEX REPLACE "^#define[\t ]+MINIUPNPC_VERSION[\t ]+\"([.0-9]+)\"" "\\1" MINIUPNPC_VERSION ${MINIUPNPC_VERSION_STR}) endif() endif() include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(MINIUPNPC DEFAULT_MSG MINIUPNPC_INCLUDE_DIR MINIUPNPC_LIBRARY MINIUPNPC_API_VERSION) +find_package_handle_standard_args(MINIUPNPC + REQUIRED_VARS MINIUPNPC_INCLUDE_DIR MINIUPNPC_LIBRARY + VERSION_VAR MINIUPNPC_VERSION +) set(MINIUPNPC_LIBRARIES ${MINIUPNPC_LIBRARY}) set(MINIUPNPC_INCLUDE_DIRS ${MINIUPNPC_INCLUDE_DIR}) diff --git a/CMake/FindSFML.cmake b/CMake/FindSFML.cmake index d6acdfb6d6..b5b26a5f00 100644 --- a/CMake/FindSFML.cmake +++ b/CMake/FindSFML.cmake @@ -206,4 +206,20 @@ endif() # handle success if(SFML_FOUND) message(STATUS "Found SFML ${SFML_VERSION_MAJOR}.${SFML_VERSION_MINOR} in ${SFML_INCLUDE_DIR}") + foreach(FIND_SFML_COMPONENT ${SFML_FIND_COMPONENTS}) + string(TOLOWER ${FIND_SFML_COMPONENT} FIND_SFML_COMPONENT_LOWER) + string(TOUPPER ${FIND_SFML_COMPONENT} FIND_SFML_COMPONENT_UPPER) + if(NOT TARGET sfml-${FIND_SFML_COMPONENT_LOWER}) + add_library(sfml-${FIND_SFML_COMPONENT_LOWER} UNKNOWN IMPORTED) + set_target_properties(sfml-${FIND_SFML_COMPONENT_LOWER} PROPERTIES + IMPORTED_LOCATION "${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${SFML_INCLUDE_DIR}" + ) + if(NOT ${FIND_SFML_COMPONENT_LOWER} STREQUAL system) + set_target_properties(sfml-${FIND_SFML_COMPONENT_LOWER} PROPERTIES + INTERFACE_LINK_LIBRARIES sfml-system + ) + endif() + endif() + endforeach() endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d72091752..f973dc7ae2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,7 +85,6 @@ if(NOT ANDROID) option(ENABLE_CLI_TOOL "Enable dolphin-tool, a CLI-based utility for functions such as managing disc images" ON) endif() -option(USE_SHARED_ENET "Use shared libenet if found rather than Dolphin's soon-to-compatibly-diverge version" OFF) option(USE_UPNP "Enables UPnP port mapping support" ON) option(ENABLE_NOGUI "Enable NoGUI frontend" ON) option(ENABLE_QT "Enable Qt (Default)" ON) @@ -645,26 +644,8 @@ if(ENABLE_SDL) message(STATUS "Using system SDL2") else() message(STATUS "Using static SDL2 from Externals") - option(SDL2_DISABLE_SDL2MAIN "" ON) - option(SDL2_DISABLE_INSTALL "" ON) - option(SDL2_DISABLE_UNINSTALL "" ON) - set(SDL_SHARED OFF) - set(SDL_SHARED_ENABLED_BY_DEFAULT OFF) - set(SDL_STATIC ON) - set(SDL_STATIC_ENABLED_BY_DEFAULT ON) - set(SDL_TEST OFF) - set(SDL_TEST_ENABLED_BY_DEFAULT OFF) - set(OPT_DEF_LIBC ON) - add_subdirectory(Externals/SDL/SDL) - if (TARGET SDL2) - dolphin_disable_warnings_msvc(SDL2) - endif() - if (TARGET SDL2-static) - dolphin_disable_warnings_msvc(SDL2-static) - endif() - set(SDL2_FOUND TRUE) + add_subdirectory(Externals/SDL) endif() - add_definitions(-DHAVE_SDL2=1) endif() if(ENABLE_ANALYTICS) @@ -747,31 +728,13 @@ if(NOT pugixml_FOUND) add_subdirectory(Externals/pugixml) endif() -if(USE_SHARED_ENET) - check_lib(ENET libenet enet enet/enet.h QUIET) - include(CheckSymbolExists) - if (ENET_FOUND) - set(CMAKE_REQUIRED_INCLUDES ${ENET_INCLUDE_DIRS}) - # hack: LDFLAGS already contains -lenet but all flags but the first are - # dropped; ugh, cmake - set(CMAKE_REQUIRED_FLAGS ${ENET_LDFLAGS}) - set(CMAKE_REQUIRED_LIBRARIES ${ENET_LIBRARIES}) - check_symbol_exists(enet_socket_get_address enet/enet.h ENET_HAVE_SGA) - set(CMAKE_REQUIRED_INCLUDES) - set(CMAKE_REQUIRED_FLAGS) - set(CMAKE_REQUIRED_LIBRARIES) - if (NOT ENET_HAVE_SGA) - # enet is too old - set(ENET_FOUND FALSE) - endif() - endif() -endif() -if (ENET_FOUND) +pkg_check_modules(ENET libenet>=1.3.8 IMPORTED_TARGET) +if(ENET_FOUND) message(STATUS "Using shared enet") + dolphin_alias_library(enet::enet PkgConfig::ENET) else() check_vendoring_approved(enet) message(STATUS "Using static enet from Externals") - include_directories(Externals/enet/include) add_subdirectory(Externals/enet) endif() @@ -813,37 +776,32 @@ endif() add_subdirectory(Externals/zlib-ng) -pkg_check_modules(MINIZIP minizip>=3.0.0) +pkg_check_modules(MINIZIP minizip>=3.0.0 IMPORTED_TARGET) if(MINIZIP_FOUND) message(STATUS "Using shared minizip") - include_directories(${MINIZIP_INCLUDE_DIRS}) + dolphin_alias_library(minizip::minizip PkgConfig::MINIZIP) else() check_vendoring_approved(minizip) message(STATUS "Shared minizip not found, falling back to the static library") add_subdirectory(Externals/minizip) - include_directories(External/minizip) endif() -if(NOT APPLE) - check_lib(LZO "(no .pc for lzo2)" lzo2 lzo/lzo1x.h QUIET) -endif() +find_package(LZO) if(LZO_FOUND) message(STATUS "Using shared lzo") else() check_vendoring_approved(lzo) message(STATUS "Using static lzo from Externals") - add_subdirectory(Externals/LZO) - set(LZO lzo2) + add_subdirectory(Externals/LZO EXCLUDE_FROM_ALL) endif() pkg_check_modules(pc_spng IMPORTED_TARGET spng) if (pc_spng_FOUND AND TARGET PkgConfig::pc_spng) message(STATUS "Using the system libspng") - set(spng_target PkgConfig::pc_spng) + dolphin_alias_library(spng::spng PkgConfig::pc_spng) else() message(STATUS "Using static libspng from Externals") add_subdirectory(Externals/libspng) - set(spng_target spng) endif() # Using static FreeSurround from Externals @@ -873,40 +831,28 @@ endif() if(NOT ANDROID) add_definitions(-D__LIBUSB__) - if(NOT APPLE) - find_package(LibUSB) - endif() - if(LIBUSB_FOUND AND NOT APPLE) + find_package(LibUSB) + if(LIBUSB_FOUND) message(STATUS "Using shared LibUSB") - include_directories(${LIBUSB_INCLUDE_DIR}) else() check_vendoring_approved(libusb) message(STATUS "Using static LibUSB from Externals") - add_subdirectory(Externals/libusb) - set(LIBUSB_LIBRARIES usb) + add_subdirectory(Externals/libusb EXCLUDE_FROM_ALL) endif() - set(LIBUSB_FOUND true) endif() -set(SFML_REQD_VERSION 2.1) -if(NOT APPLE) - find_package(SFML ${SFML_REQD_VERSION} COMPONENTS network system) -endif() +find_package(SFML 2.1 COMPONENTS network system) if(SFML_FOUND) message(STATUS "Using shared SFML") else() check_vendoring_approved(sfml) - message(STATUS "Using static SFML ${SFML_REQD_VERSION} from Externals") - add_definitions(-DSFML_STATIC) + message(STATUS "Using static SFML from Externals") add_subdirectory(Externals/SFML) - include_directories(BEFORE Externals/SFML/include) endif() if(USE_UPNP) - if(NOT APPLE) - find_package(MINIUPNPC) - endif() - if(MINIUPNPC_FOUND AND MINIUPNPC_API_VERSION GREATER 8) + find_package(MINIUPNPC 1.6) + if(MINIUPNPC_FOUND) message(STATUS "Using shared miniupnpc") else() check_vendoring_approved(miniupnpc) @@ -916,30 +862,22 @@ if(USE_UPNP) add_definitions(-DUSE_UPNP) endif() -if(NOT APPLE) - find_package(MBEDTLS) -endif() +find_package(MBEDTLS 2.28) if(MBEDTLS_FOUND) message(STATUS "Using shared mbed TLS") - include_directories(${MBEDTLS_INCLUDE_DIRS}) else() check_vendoring_approved(mbedtls) message(STATUS "Using static mbed TLS from Externals") - set(MBEDTLS_LIBRARIES mbedtls mbedcrypto mbedx509) add_subdirectory(Externals/mbedtls/ EXCLUDE_FROM_ALL) - include_directories(Externals/mbedtls/include) endif() find_package(CURL) if(CURL_FOUND) message(STATUS "Using shared libcurl") - include_directories(${CURL_INCLUDE_DIRS}) else() check_vendoring_approved(curl) message(STATUS "Using static libcurl from Externals") - add_subdirectory(Externals/curl) - set(CURL_LIBRARIES curl) - include_directories(BEFORE Externals/curl/include) + add_subdirectory(Externals/curl EXCLUDE_FROM_ALL) endif() if(NOT ANDROID) @@ -951,7 +889,7 @@ if(TARGET Iconv::Iconv) else() check_vendoring_approved(iconv) message(STATUS "Using static iconv from Externals") - add_subdirectory(Externals/libiconv-1.14) + add_subdirectory(Externals/libiconv-1.14 EXCLUDE_FROM_ALL) endif() if(NOT ANDROID) diff --git a/Externals/LZO/CMakeLists.txt b/Externals/LZO/CMakeLists.txt index 3bb91ee5c5..44b59bd496 100644 --- a/Externals/LZO/CMakeLists.txt +++ b/Externals/LZO/CMakeLists.txt @@ -7,3 +7,4 @@ target_include_directories(lzo2 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) +add_library(LZO::LZO ALIAS lzo2) diff --git a/Externals/SDL/CMakeLists.txt b/Externals/SDL/CMakeLists.txt new file mode 100644 index 0000000000..15d3ffe4ce --- /dev/null +++ b/Externals/SDL/CMakeLists.txt @@ -0,0 +1,17 @@ +option(SDL2_DISABLE_SDL2MAIN "" ON) +option(SDL2_DISABLE_INSTALL "" ON) +option(SDL2_DISABLE_UNINSTALL "" ON) +set(SDL_SHARED OFF) +set(SDL_SHARED_ENABLED_BY_DEFAULT OFF) +set(SDL_STATIC ON) +set(SDL_STATIC_ENABLED_BY_DEFAULT ON) +set(SDL_TEST OFF) +set(SDL_TEST_ENABLED_BY_DEFAULT OFF) +set(OPT_DEF_LIBC ON) +add_subdirectory(SDL) +if (TARGET SDL2) + dolphin_disable_warnings_msvc(SDL2) +endif() +if (TARGET SDL2-static) + dolphin_disable_warnings_msvc(SDL2-static) +endif() diff --git a/Externals/SFML/CMakeLists.txt b/Externals/SFML/CMakeLists.txt index aac2192cad..1b7060ef95 100644 --- a/Externals/SFML/CMakeLists.txt +++ b/Externals/SFML/CMakeLists.txt @@ -1,5 +1,3 @@ -include_directories(BEFORE include src) - set(SRC_NETWORK src/SFML/Network/Http.cpp src/SFML/Network/IPAddress.cpp @@ -23,7 +21,11 @@ set(SRC_SYSTEM src/SFML/System/Time.cpp ) -add_library(sfml-network ${SRC_NETWORK}) -add_library(sfml-system ${SRC_SYSTEM}) +add_library(sfml-network STATIC ${SRC_NETWORK}) +add_library(sfml-system STATIC ${SRC_SYSTEM}) +target_compile_definitions(sfml-system PUBLIC SFML_STATIC) +target_include_directories(sfml-system PUBLIC include PRIVATE src) +target_include_directories(sfml-network PUBLIC include PRIVATE src) +target_link_libraries(sfml-network PUBLIC sfml-system) dolphin_disable_warnings_msvc(sfml-network) dolphin_disable_warnings_msvc(sfml-system) diff --git a/Externals/cubeb/CMakeLists.txt b/Externals/cubeb/CMakeLists.txt index a9f904a093..07f4493dd9 100644 --- a/Externals/cubeb/CMakeLists.txt +++ b/Externals/cubeb/CMakeLists.txt @@ -352,3 +352,4 @@ if(USE_AUDIOUNIT AND USE_AUDIOUNIT_RUST) debug "${PROJECT_SOURCE_DIR}/cubeb/src/cubeb-coreaudio-rs/target/debug/libcubeb_coreaudio.a" optimized "${PROJECT_SOURCE_DIR}/cubeb/src/cubeb-coreaudio-rs/target/release/libcubeb_coreaudio.a") endif() +add_library(cubeb::cubeb ALIAS cubeb) diff --git a/Externals/curl/lib/CMakeLists.txt b/Externals/curl/lib/CMakeLists.txt index dff7a63171..3679575463 100644 --- a/Externals/curl/lib/CMakeLists.txt +++ b/Externals/curl/lib/CMakeLists.txt @@ -4,8 +4,6 @@ else() add_definitions(-DHAVE_CONFIG_H) endif() -include_directories(.) - file(GLOB SRCS *.c vauth/*.c vtls/*.c) add_library( curl @@ -14,5 +12,7 @@ add_library( ) dolphin_disable_warnings_msvc(curl) -target_link_libraries(curl ${MBEDTLS_LIBRARIES} zlibstatic) +target_include_directories(curl PRIVATE . INTERFACE ../include) +target_link_libraries(curl MbedTLS::mbedtls zlibstatic) target_compile_definitions(curl PUBLIC CURL_STATICLIB PRIVATE CURL_DISABLE_LDAP) +add_library(CURL::libcurl ALIAS curl) diff --git a/Externals/enet/CMakeLists.txt b/Externals/enet/CMakeLists.txt index 7088bf3291..f6244a7f4e 100644 --- a/Externals/enet/CMakeLists.txt +++ b/Externals/enet/CMakeLists.txt @@ -59,8 +59,6 @@ if(HAS_SOCKLEN_T) add_definitions(-DHAS_SOCKLEN_T=1) endif() -include_directories(${PROJECT_SOURCE_DIR}/include) - set(INCLUDE_FILES_PREFIX include/enet) set(INCLUDE_FILES ${INCLUDE_FILES_PREFIX}/callbacks.h @@ -92,8 +90,10 @@ add_library(enet STATIC ${INCLUDE_FILES} ${SOURCE_FILES} ) +target_include_directories(enet PUBLIC include) dolphin_disable_warnings_msvc(enet) +add_library(enet::enet ALIAS enet) if (MINGW) target_link_libraries(enet winmm ws2_32) diff --git a/Externals/libspng/CMakeLists.txt b/Externals/libspng/CMakeLists.txt index 7576534a67..315997a45a 100644 --- a/Externals/libspng/CMakeLists.txt +++ b/Externals/libspng/CMakeLists.txt @@ -2,8 +2,9 @@ cmake_minimum_required(VERSION 3.0) project(spng C) -add_library(spng STATIC ${CMAKE_CURRENT_LIST_DIR}/libspng/spng/spng.c) +add_library(spng STATIC libspng/spng/spng.c) target_compile_definitions(spng PUBLIC SPNG_STATIC) target_link_libraries(spng PUBLIC ZLIB::ZLIB) -target_include_directories(spng PUBLIC ${CMAKE_CURRENT_LIST_DIR}/libspng/spng/) +target_include_directories(spng PUBLIC libspng/spng) dolphin_disable_warnings_msvc(spng) +add_library(spng::spng ALIAS spng) diff --git a/Externals/libusb/CMakeLists.txt b/Externals/libusb/CMakeLists.txt index f3bed0d1f0..47ff1d8e0d 100644 --- a/Externals/libusb/CMakeLists.txt +++ b/Externals/libusb/CMakeLists.txt @@ -125,3 +125,4 @@ check_include_files(sys/timerfd.h HAVE_TIMERFD) check_include_files(unistd.h HAVE_UNISTD_H) configure_file(config.h.in config.h) +add_library(LibUSB::LibUSB ALIAS usb) diff --git a/Externals/mbedtls/library/CMakeLists.txt b/Externals/mbedtls/library/CMakeLists.txt index ba0b337ea1..fc2786c7f2 100644 --- a/Externals/mbedtls/library/CMakeLists.txt +++ b/Externals/mbedtls/library/CMakeLists.txt @@ -222,6 +222,7 @@ if(USE_SHARED_MBEDTLS_LIBRARY) endif(USE_SHARED_MBEDTLS_LIBRARY) foreach(target IN LISTS target_libraries) + add_library(MbedTLS::${target} ALIAS ${target}) # add_subdirectory support # Include public header files from /include and other directories # declared by /3rdparty/**/CMakeLists.txt. Include private header files # from /library and others declared by /3rdparty/**/CMakeLists.txt. diff --git a/Externals/minizip/CMakeLists.txt b/Externals/minizip/CMakeLists.txt index c3d7c5512e..09aba92e57 100644 --- a/Externals/minizip/CMakeLists.txt +++ b/Externals/minizip/CMakeLists.txt @@ -67,4 +67,4 @@ endif() target_link_libraries(minizip PUBLIC ZLIB::ZLIB) -add_library(minizip-ng ALIAS minizip) +add_library(minizip::minizip ALIAS minizip) diff --git a/Source/Core/AudioCommon/CMakeLists.txt b/Source/Core/AudioCommon/CMakeLists.txt index 18cc67470b..26dc443d90 100644 --- a/Source/Core/AudioCommon/CMakeLists.txt +++ b/Source/Core/AudioCommon/CMakeLists.txt @@ -83,7 +83,7 @@ PUBLIC common PRIVATE - cubeb + cubeb::cubeb SoundTouch FreeSurround) diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index d3a756e6e2..6233f847a0 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -144,16 +144,17 @@ endif() target_link_libraries(common PUBLIC ${CMAKE_THREAD_LIBS_INIT} - enet + enet::enet fmt::fmt - ${MBEDTLS_LIBRARIES} - minizip-ng + MbedTLS::mbedtls + minizip::minizip + sfml-network PRIVATE - ${CURL_LIBRARIES} + CURL::libcurl FatFs Iconv::Iconv - ${spng_target} + spng::spng ${VTUNE_LIBRARIES} ) diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index f6fb444118..b3eb8dac64 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -603,24 +603,23 @@ target_link_libraries(core PUBLIC audiocommon common - cubeb discio - enet + enet::enet expr inputcommon - ${MBEDTLS_LIBRARIES} + MbedTLS::mbedtls pugixml RangeSet::RangeSet sfml-network - sfml-system videonull videoogl videosoftware PRIVATE + cubeb::cubeb FatFs fmt::fmt - ${LZO} + LZO::LZO ZLIB::ZLIB ) @@ -644,9 +643,8 @@ elseif (ANDROID) ) endif() -if(LIBUSB_FOUND) - # Using shared LibUSB - target_link_libraries(core PUBLIC ${LIBUSB_LIBRARIES}) +if(TARGET LibUSB::LibUSB) + target_link_libraries(core PUBLIC LibUSB::LibUSB) target_sources(core PRIVATE IOS/USB/LibusbDevice.cpp IOS/USB/LibusbDevice.h diff --git a/Source/Core/DiscIO/CMakeLists.txt b/Source/Core/DiscIO/CMakeLists.txt index 44d4af95b8..11fb5cf52a 100644 --- a/Source/Core/DiscIO/CMakeLists.txt +++ b/Source/Core/DiscIO/CMakeLists.txt @@ -75,7 +75,7 @@ PUBLIC PRIVATE fmt::fmt - minizip-ng + minizip::minizip pugixml ZLIB::ZLIB ) diff --git a/Source/Core/InputCommon/CMakeLists.txt b/Source/Core/InputCommon/CMakeLists.txt index 0343717a34..ed19e12b74 100644 --- a/Source/Core/InputCommon/CMakeLists.txt +++ b/Source/Core/InputCommon/CMakeLists.txt @@ -81,7 +81,8 @@ PUBLIC PRIVATE fmt::fmt - ${spng_target} + sfml-network + spng::spng ) if(WIN32) @@ -146,7 +147,7 @@ elseif(ANDROID) endif() if(NOT ANDROID) - target_link_libraries(inputcommon PUBLIC ${LIBUSB_LIBRARIES}) + target_link_libraries(inputcommon PUBLIC LibUSB::LibUSB) endif() if(LIBEVDEV_FOUND AND LIBUDEV_FOUND) @@ -174,12 +175,13 @@ if(UNIX) ) endif() -if(SDL2_FOUND) +if(ENABLE_SDL) target_sources(inputcommon PRIVATE ControllerInterface/SDL/SDL.cpp ControllerInterface/SDL/SDL.h ) target_link_libraries(inputcommon PRIVATE SDL2::SDL2) + target_compile_definitions(inputcommon PUBLIC HAVE_SDL2=1) endif() if(MSVC) diff --git a/Source/Core/UICommon/CMakeLists.txt b/Source/Core/UICommon/CMakeLists.txt index 947aeae346..7505f9c9f5 100644 --- a/Source/Core/UICommon/CMakeLists.txt +++ b/Source/Core/UICommon/CMakeLists.txt @@ -29,7 +29,7 @@ target_link_libraries(uicommon PUBLIC common cpp-optparse - minizip-ng + minizip::minizip pugixml PRIVATE @@ -48,8 +48,8 @@ if(ENABLE_X11 AND X11_FOUND) target_link_libraries(uicommon PUBLIC ${XRANDR_LIBRARIES}) endif() -if(LIBUSB_FOUND) - target_link_libraries(uicommon PRIVATE ${LIBUSB_LIBRARIES}) +if(TARGET LibUSB::LibUSB) + target_link_libraries(uicommon PRIVATE LibUSB::LibUSB) endif() if(ENABLE_LLVM) diff --git a/Source/Core/UpdaterCommon/CMakeLists.txt b/Source/Core/UpdaterCommon/CMakeLists.txt index c026cd577d..9bc1f9ab45 100644 --- a/Source/Core/UpdaterCommon/CMakeLists.txt +++ b/Source/Core/UpdaterCommon/CMakeLists.txt @@ -6,7 +6,7 @@ add_library(updatercommon target_link_libraries(updatercommon PRIVATE uicommon - mbedtls + MbedTLS::mbedtls ZLIB::ZLIB ed25519 cpp-optparse diff --git a/Source/Core/VideoCommon/CMakeLists.txt b/Source/Core/VideoCommon/CMakeLists.txt index ed8642fb1e..acb011cbb1 100644 --- a/Source/Core/VideoCommon/CMakeLists.txt +++ b/Source/Core/VideoCommon/CMakeLists.txt @@ -195,7 +195,7 @@ PUBLIC core PRIVATE fmt::fmt - ${spng_target} + spng::spng xxhash imgui implot