From 837e5388eaa1923a24321419561743ca05a2579b Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Tue, 27 Aug 2024 19:39:53 +0200 Subject: [PATCH] CMake: Use target_link_directories --- 3rdparty/kdsingleapplication/CMakeLists.txt | 2 +- CMakeLists.txt | 2 +- ext/gstmoodbar/CMakeLists.txt | 20 ++-- ext/libstrawberry-common/CMakeLists.txt | 6 +- ext/libstrawberry-tagreader/CMakeLists.txt | 22 ++-- ext/macdeploycheck/CMakeLists.txt | 5 +- ext/strawberry-tagreader/CMakeLists.txt | 16 +-- src/CMakeLists.txt | 109 ++++++-------------- tests/CMakeLists.txt | 32 +----- 9 files changed, 67 insertions(+), 147 deletions(-) diff --git a/3rdparty/kdsingleapplication/CMakeLists.txt b/3rdparty/kdsingleapplication/CMakeLists.txt index 547ba1a1..5f282830 100644 --- a/3rdparty/kdsingleapplication/CMakeLists.txt +++ b/3rdparty/kdsingleapplication/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.7) +cmake_minimum_required(VERSION 3.13) set(SOURCES KDSingleApplication/src/kdsingleapplication.cpp KDSingleApplication/src/kdsingleapplication_localsocket.cpp) set(HEADERS KDSingleApplication/src/kdsingleapplication.h KDSingleApplication/src/kdsingleapplication_localsocket_p.h) qt_wrap_cpp(MOC ${HEADERS}) diff --git a/CMakeLists.txt b/CMakeLists.txt index bc1acd82..f464c5c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.7) +cmake_minimum_required(VERSION 3.13) project(strawberry) diff --git a/ext/gstmoodbar/CMakeLists.txt b/ext/gstmoodbar/CMakeLists.txt index 43179382..e44f4e23 100644 --- a/ext/gstmoodbar/CMakeLists.txt +++ b/ext/gstmoodbar/CMakeLists.txt @@ -1,16 +1,7 @@ -cmake_minimum_required(VERSION 3.7) +cmake_minimum_required(VERSION 3.13) set(SOURCES gstfastspectrum.cpp gstmoodbarplugin.cpp) -link_directories( - ${GLIB_LIBRARY_DIRS} - ${GOBJECT_LIBRARY_DIRS} - ${GSTREAMER_LIBRARY_DIRS} - ${GSTREAMER_BASE_LIBRARY_DIRS} - ${GSTREAMER_AUDIO_LIBRARY_DIRS} - ${FFTW3_LIBRARY_DIRS} -) - add_library(gstmoodbar STATIC ${SOURCES}) target_include_directories(gstmoodbar SYSTEM PRIVATE @@ -24,6 +15,15 @@ target_include_directories(gstmoodbar SYSTEM PRIVATE target_include_directories(gstmoodbar PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_directories(gstmoodbar PRIVATE + ${GLIB_LIBRARY_DIRS} + ${GOBJECT_LIBRARY_DIRS} + ${GSTREAMER_LIBRARY_DIRS} + ${GSTREAMER_BASE_LIBRARY_DIRS} + ${GSTREAMER_AUDIO_LIBRARY_DIRS} + ${FFTW3_LIBRARY_DIRS} +) + target_link_libraries(gstmoodbar PRIVATE ${GLIB_LIBRARIES} ${GOBJECT_LIBRARIES} diff --git a/ext/libstrawberry-common/CMakeLists.txt b/ext/libstrawberry-common/CMakeLists.txt index 30084840..97914517 100644 --- a/ext/libstrawberry-common/CMakeLists.txt +++ b/ext/libstrawberry-common/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.7) +cmake_minimum_required(VERSION 3.13) set(SOURCES core/logging.cpp @@ -16,8 +16,6 @@ set(HEADERS qt_wrap_cpp(MOC ${HEADERS}) -link_directories(${GLIB_LIBRARY_DIRS}) - add_library(libstrawberry-common STATIC ${SOURCES} ${MOC}) target_include_directories(libstrawberry-common SYSTEM PRIVATE ${GLIB_INCLUDE_DIRS}) @@ -31,6 +29,8 @@ if(Backtrace_FOUND) target_include_directories(libstrawberry-common SYSTEM PRIVATE ${Backtrace_INCLUDE_DIRS}) endif() +target_link_directories(libstrawberry-common PRIVATE ${GLIB_LIBRARY_DIRS}) + target_link_libraries(libstrawberry-common PRIVATE ${CMAKE_THREAD_LIBS_INIT} ${GLIB_LIBRARIES} diff --git a/ext/libstrawberry-tagreader/CMakeLists.txt b/ext/libstrawberry-tagreader/CMakeLists.txt index 3dbd8ad5..c8113ae2 100644 --- a/ext/libstrawberry-tagreader/CMakeLists.txt +++ b/ext/libstrawberry-tagreader/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.7) +cmake_minimum_required(VERSION 3.13) # Workaround a bug in protobuf-generate.cmake (https://github.com/protocolbuffers/protobuf/issues/12450) if(NOT protobuf_PROTOC_EXE) @@ -19,19 +19,6 @@ if(HAVE_TAGPARSER) list(APPEND SOURCES tagreadertagparser.cpp) endif() -link_directories( - ${GLIB_LIBRARY_DIRS} - ${PROTOBUF_LIBRARY_DIRS} -) - -if(HAVE_TAGLIB) - link_directories(${TAGLIB_LIBRARY_DIRS}) -endif() - -if(HAVE_TAGPARSER) - link_directories(${TAGPARSER_LIBRARY_DIRS}) -endif() - add_library(libstrawberry-tagreader STATIC ${PROTO_SOURCES} ${SOURCES}) target_include_directories(libstrawberry-tagreader SYSTEM PRIVATE @@ -47,6 +34,11 @@ target_include_directories(libstrawberry-tagreader PRIVATE ${CMAKE_BINARY_DIR}/src ) +target_link_directories(libstrawberry-tagreader PRIVATE + ${GLIB_LIBRARY_DIRS} + ${PROTOBUF_LIBRARY_DIRS} +) + target_link_libraries(libstrawberry-tagreader PRIVATE ${GLIB_LIBRARIES} ${Protobuf_LIBRARIES} @@ -58,11 +50,13 @@ target_link_libraries(libstrawberry-tagreader PRIVATE if(HAVE_TAGLIB) target_include_directories(libstrawberry-tagreader SYSTEM PRIVATE ${TAGLIB_INCLUDE_DIRS}) + target_link_directories(libstrawberry-tagreader PRIVATE ${TAGLIB_LIBRARY_DIRS}) target_link_libraries(libstrawberry-tagreader PRIVATE ${TAGLIB_LIBRARIES}) endif() if(HAVE_TAGPARSER) target_include_directories(libstrawberry-tagreader SYSTEM PRIVATE ${TAGPARSER_INCLUDE_DIRS}) + target_link_directories(libstrawberry-tagreader PRIVATE ${TAGPARSER_LIBRARY_DIRS}) target_link_libraries(libstrawberry-tagreader PRIVATE ${TAGPARSER_LIBRARIES}) endif() diff --git a/ext/macdeploycheck/CMakeLists.txt b/ext/macdeploycheck/CMakeLists.txt index cea78561..5fc3c3b2 100644 --- a/ext/macdeploycheck/CMakeLists.txt +++ b/ext/macdeploycheck/CMakeLists.txt @@ -1,5 +1,7 @@ +cmake_minimum_required(VERSION 3.13) + qt_wrap_cpp(MACDEPLOYCHECK_MOC ${CMAKE_SOURCE_DIR}/ext/libstrawberry-common/core/logging.h) -link_directories(${GLIB_LIBRARY_DIRS}) + add_executable(macdeploycheck macdeploycheck.cpp ${CMAKE_SOURCE_DIR}/ext/libstrawberry-common/core/logging.cpp ${MACDEPLOYCHECK_MOC}) target_include_directories(macdeploycheck PUBLIC SYSTEM ${GLIB_INCLUDE_DIRS} @@ -8,6 +10,7 @@ target_include_directories(macdeploycheck PUBLIC ${CMAKE_SOURCE_DIR}/ext/libstrawberry-common ${CMAKE_BINARY_DIR}/src ) +target_link_directories(macdeploycheck PUBLIC ${GLIB_LIBRARY_DIRS}) target_link_libraries(macdeploycheck PUBLIC "-framework AppKit" ${GLIB_LIBRARIES} diff --git a/ext/strawberry-tagreader/CMakeLists.txt b/ext/strawberry-tagreader/CMakeLists.txt index cdb5e091..8ee5d615 100644 --- a/ext/strawberry-tagreader/CMakeLists.txt +++ b/ext/strawberry-tagreader/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.7) +cmake_minimum_required(VERSION 3.13) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) @@ -7,16 +7,6 @@ set(HEADERS tagreaderworker.h) qt_wrap_cpp(MOC ${HEADERS}) -link_directories(${GLIB_LIBRARY_DIRS}) - -if(HAVE_TAGLIB) - link_directories(${TAGLIB_LIBRARY_DIRS}) -endif() - -if(HAVE_TAGPARSER) - link_directories(${TAGPARSER_LIBRARY_DIRS}) -endif() - add_executable(strawberry-tagreader ${SOURCES} ${MOC} ${QRC}) target_include_directories(strawberry-tagreader SYSTEM PRIVATE @@ -31,6 +21,8 @@ target_include_directories(strawberry-tagreader PRIVATE ${CMAKE_BINARY_DIR}/src ) +target_link_directories(strawberry-tagreader PRIVATE ${GLIB_LIBRARY_DIRS}) + target_link_libraries(strawberry-tagreader PRIVATE ${GLIB_LIBRARIES} Qt${QT_VERSION_MAJOR}::Core @@ -41,11 +33,13 @@ target_link_libraries(strawberry-tagreader PRIVATE if(HAVE_TAGLIB) target_include_directories(strawberry-tagreader SYSTEM PRIVATE ${TAGLIB_INCLUDE_DIRS}) + target_link_directories(strawberry-tagreader PRIVATE ${TAGLIB_LIBRARY_DIRS}) target_link_libraries(strawberry-tagreader PRIVATE ${TAGLIB_LIBRARIES}) endif() if(HAVE_TAGPARSER) target_include_directories(strawberry-tagreader SYSTEM PRIVATE ${TAGPARSER_INCLUDE_DIRS}) + target_link_directories(strawberry-tagreader PRIVATE ${TAGPARSER_LIBRARY_DIRS}) target_link_libraries(strawberry-tagreader PRIVATE ${TAGPARSER_LIBRARIES}) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dbf4c448..0b1faef0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.7) +cmake_minimum_required(VERSION 3.13) if(HAVE_TRANSLATIONS) include(../cmake/Translations.cmake) @@ -1044,83 +1044,6 @@ if(HAVE_TRANSLATIONS) endif(HAVE_TRANSLATIONS) -link_directories( - ${Boost_LIBRARY_DIRS} - ${GLIB_LIBRARY_DIRS} - ${GOBJECT_LIBRARY_DIRS} - ${SQLITE_LIBRARY_DIRS} - ${PROTOBUF_LIBRARY_DIRS} - ${SINGLEAPPLICATION_LIBRARY_DIRS} - ${ICU_LIBRARY_DIRS} -) - -if(HAVE_ALSA) - link_directories(${ALSA_LIBRARY_DIRS}) -endif() - -if(HAVE_LIBPULSE) - link_directories(${LIBPULSE_LIBRARY_DIRS}) -endif() - -if(HAVE_GSTREAMER) - link_directories( - ${GSTREAMER_LIBRARY_DIRS} - ${GSTREAMER_BASE_LIBRARY_DIRS} - ${GSTREAMER_APP_LIBRARY_DIRS} - ${GSTREAMER_AUDIO_LIBRARY_DIRS} - ${GSTREAMER_TAG_LIBRARY_DIRS} - ${GSTREAMER_PBUTILS_LIBRARY_DIRS} - ) -endif() - -if(HAVE_VLC) - link_directories(${LIBVLC_LIBRARY_DIRS}) -endif() - -if(HAVE_SONGFINGERPRINTING OR HAVE_MUSICBRAINZ) - link_directories(${CHROMAPRINT_LIBRARY_DIRS}) -endif() - -if(X11_FOUND) - link_directories(${X11_LIBRARY_DIRS}) -endif() - -if(XCB_FOUND) - link_directories(${XCB_LIBRARY_DIRS}) -endif() - -if(HAVE_GIO) - link_directories(${GIO_LIBRARY_DIRS}) -endif() - -if(HAVE_GIO_UNIX) - link_directories(${GIO_UNIX_LIBRARY_DIRS}) -endif() - -if(HAVE_AUDIOCD) - link_directories(${LIBCDIO_LIBRARY_DIRS}) -endif() - -if(HAVE_LIBGPOD) - link_directories(${LIBGPOD_LIBRARY_DIRS} ${GDK_PIXBUF_LIBRARY_DIRS}) -endif() - -if(HAVE_LIBMTP) - link_directories(${LIBMTP_LIBRARY_DIRS}) -endif() - -if(HAVE_TAGLIB) - link_directories(${TAGLIB_LIBRARY_DIRS}) -endif() - -if(HAVE_TAGPARSER) - link_directories(${TAGPARSER_LIBRARY_DIRS}) -endif() - -if(HAVE_QTSPARKLE) - link_directories(${QTSPARKLE_LIBRARY_DIRS}) -endif() - add_library(strawberry_lib STATIC ${SOURCES} ${MOC} @@ -1155,6 +1078,16 @@ target_include_directories(strawberry_lib PUBLIC ${SINGLEAPPLICATION_INCLUDE_DIRS} ) +target_link_directories(strawberry_lib PUBLIC + ${Boost_LIBRARY_DIRS} + ${GLIB_LIBRARY_DIRS} + ${GOBJECT_LIBRARY_DIRS} + ${SQLITE_LIBRARY_DIRS} + ${PROTOBUF_LIBRARY_DIRS} + ${SINGLEAPPLICATION_LIBRARY_DIRS} + ${ICU_LIBRARY_DIRS} +) + target_link_libraries(strawberry_lib PUBLIC ${CMAKE_THREAD_LIBS_INIT} ${GLIB_LIBRARIES} @@ -1183,11 +1116,13 @@ endif() if(HAVE_ALSA) target_include_directories(strawberry_lib SYSTEM PRIVATE ${ALSA_INCLUDE_DIRS}) + target_link_directories(strawberry_lib PRIVATE ${ALSA_LIBRARY_DIRS}) target_link_libraries(strawberry_lib PRIVATE ${ALSA_LIBRARIES}) endif() if(HAVE_LIBPULSE) target_include_directories(strawberry_lib SYSTEM PRIVATE ${LIBPULSE_INCLUDE_DIRS}) + target_link_directories(strawberry_lib PRIVATE ${LIBPULSE_LIBRARY_DIRS}) target_link_libraries(strawberry_lib PRIVATE ${LIBPULSE_LIBRARIES}) endif() @@ -1200,6 +1135,14 @@ if(HAVE_GSTREAMER) ${GSTREAMER_TAG_INCLUDE_DIRS} ${GSTREAMER_PBUTILS_INCLUDE_DIRS} ) + target_link_directories(strawberry_lib PRIVATE + ${GSTREAMER_LIBRARY_DIRS} + ${GSTREAMER_BASE_LIBRARY_DIRS} + ${GSTREAMER_APP_LIBRARY_DIRS} + ${GSTREAMER_AUDIO_LIBRARY_DIRS} + ${GSTREAMER_TAG_LIBRARY_DIRS} + ${GSTREAMER_PBUTILS_LIBRARY_DIRS} + ) target_link_libraries(strawberry_lib PRIVATE ${GSTREAMER_LIBRARIES} ${GSTREAMER_BASE_LIBRARIES} @@ -1216,11 +1159,13 @@ endif() if(HAVE_VLC) target_include_directories(strawberry_lib SYSTEM PRIVATE ${LIBVLC_INCLUDE_DIRS}) + target_link_directories(strawberry_lib PRIVATE ${LIBVLC_LIBRARY_DIRS}) target_link_libraries(strawberry_lib PRIVATE ${LIBVLC_LIBRARIES}) endif() if(HAVE_SONGFINGERPRINTING OR HAVE_MUSICBRAINZ) target_include_directories(strawberry_lib SYSTEM PRIVATE ${CHROMAPRINT_INCLUDE_DIRS}) + target_link_directories(strawberry_lib PRIVATE ${CHROMAPRINT_LIBRARY_DIRS}) target_link_libraries(strawberry_lib PRIVATE ${CHROMAPRINT_LIBRARIES}) endif() @@ -1230,36 +1175,43 @@ endif() if(X11_FOUND) target_include_directories(strawberry_lib SYSTEM PRIVATE ${X11_INCLUDE_DIR}) + target_link_directories(strawberry_lib PRIVATE ${X11_LIBRARY_DIRS}) target_link_libraries(strawberry_lib PRIVATE ${X11_LIBRARIES}) endif() if(XCB_FOUND) target_include_directories(strawberry_lib SYSTEM PRIVATE ${XCB_INCLUDE_DIR}) + target_link_directories(strawberry_lib PRIVATE ${XCB_LIBRARY_DIRS}) target_link_libraries(strawberry_lib PRIVATE ${XCB_LIBRARIES}) endif() if(HAVE_GIO) target_include_directories(strawberry_lib SYSTEM PRIVATE ${GIO_INCLUDE_DIRS}) + target_link_directories(strawberry_lib PRIVATE ${GIO_LIBRARY_DIRS}) target_link_libraries(strawberry_lib PRIVATE ${GIO_LIBRARIES}) endif() if(HAVE_GIO_UNIX) target_include_directories(strawberry_lib SYSTEM PRIVATE ${GIO_UNIX_INCLUDE_DIRS}) + target_link_directories(strawberry_lib PRIVATE ${GIO_UNIX_LIBRARY_DIRS}) target_link_libraries(strawberry_lib PRIVATE ${GIO_UNIX_LIBRARIES}) endif() if(HAVE_AUDIOCD) target_include_directories(strawberry_lib SYSTEM PRIVATE ${LIBCDIO_INCLUDE_DIRS}) + target_link_directories(strawberry_lib PRIVATE ${LIBCDIO_LIBRARY_DIRS}) target_link_libraries(strawberry_lib PRIVATE ${LIBCDIO_LIBRARIES}) endif() if(HAVE_LIBGPOD) target_include_directories(strawberry_lib SYSTEM PRIVATE ${LIBGPOD_INCLUDE_DIRS} ${GDK_PIXBUF_INCLUDE_DIRS}) + target_link_directories(strawberry_lib PRIVATE ${LIBGPOD_LIBRARY_DIRS} ${GDK_PIXBUF_LIBRARY_DIRS}) target_link_libraries(strawberry_lib PRIVATE ${LIBGPOD_LIBRARIES} ${GDK_PIXBUF_LIBRARIES}) endif() if(HAVE_LIBMTP) target_include_directories(strawberry_lib SYSTEM PRIVATE ${LIBMTP_INCLUDE_DIRS}) + target_link_directories(strawberry_lib PRIVATE ${LIBMTP_LIBRARY_DIRS}) target_link_libraries(strawberry_lib PRIVATE ${LIBMTP_LIBRARIES}) endif() @@ -1291,6 +1243,7 @@ endif() if(HAVE_QTSPARKLE) target_include_directories(strawberry_lib SYSTEM PRIVATE ${QTSPARKLE_INCLUDE_DIRS}) + target_link_directories(strawberry_lib PRIVATE ${QTSPARKLE_LIBRARY_DIRS}) target_link_libraries(strawberry_lib PRIVATE ${QTSPARKLE_LIBRARIES}) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a117d24b..ee8ada56 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -13,34 +13,6 @@ set(TESTUTILS-MOC-HEADERS src/mock_networkaccessmanager.h src/test_utils.h src/t qt_wrap_cpp(TESTUTILS-SOURCES-MOC ${TESTUTILS-MOC-HEADERS}) -link_directories( - ${SQLITE_LIBRARY_DIRS} - ${TAGLIB_LIBRARY_DIRS} -) - -if(HAVE_GSTREAMER) - link_directories( - ${GSTREAMER_LIBRARY_DIRS} - ${GSTREAMER_BASE_LIBRARY_DIRS} - ${GSTREAMER_APP_LIBRARY_DIRS} - ${GSTREAMER_AUDIO_LIBRARY_DIRS} - ${GSTREAMER_TAG_LIBRARY_DIRS} - ${GSTREAMER_PBUTILS_LIBRARY_DIRS} - ) -endif() - -if(HAVE_CHROMAPRINT) - link_directories(${CHROMAPRINT_LIBRARY_DIRS}) -endif() - -if(HAVE_AUDIOCD) - link_directories(${LIBCDIO_LIBRARY_DIRS}) -endif() - -if(HAVE_LIBMTP) - link_directories(${LIBMTP_LIBRARY_DIRS}) -endif() - add_library(test_utils STATIC EXCLUDE_FROM_ALL ${TESTUTILS-SOURCES} ${TESTUTILS-SOURCES-MOC}) target_include_directories(test_utils SYSTEM PRIVATE ${GTEST_INCLUDE_DIRS} @@ -51,6 +23,10 @@ target_include_directories(test_utils PRIVATE ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/ext/libstrawberry-common ) +target_link_directories(test_utils PRIVATE + ${SQLITE_LIBRARY_DIRS} + ${TAGLIB_LIBRARY_DIRS} +) target_link_libraries(test_utils PRIVATE ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY}