From c7f669f6bac6c8b59b3e7ea7cf1b564e7621817f Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 14 Jun 2023 01:10:28 -0700 Subject: [PATCH 1/8] fix: add options for optional deps and find them after installation This adds options for the optional dependencies to require building them if needed. This makes sure that the library is built with a require feature. It also fixes an issue where these dependencies where not being found in the config file after installation --- CMakeLists.txt | 9 +++++++ Matplot++Config.cmake.in | 13 ++++++++++ source/3rd_party/CMakeLists.txt | 45 +++++++++++++++++++++++++++------ 3 files changed, 59 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index de1ffe9d..6b3cb246 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,15 @@ option(MATPLOTPP_BUILD_HIGH_RESOLUTION_WORLD_MAP "Compile the high resolution ma option(MATPLOTPP_BUILD_FOR_DOCUMENTATION_IMAGES "Bypass show() commands and save figures as .svg at destruction" OFF) option(MATPLOTPP_BUILD_EXPERIMENTAL_OPENGL_BACKEND "Compile target with the experimental OpenGL backend" OFF) +# Optional dependencies +option(MATPLOTPP_WITH_JPEG "Require building with JPEG support" OFF) +option(MATPLOTPP_WITH_TIFF "Require building with TIFF support" OFF) +option(MATPLOTPP_WITH_ZLIB "Require building with ZLIB support" OFF) +option(MATPLOTPP_WITH_LAPACK "Require building with LAPACK support" OFF) +option(MATPLOTPP_WITH_BLAS "Require building with BLAS support" OFF) +option(MATPLOTPP_WITH_FFTW "Require building with FFTW support" OFF) +option(MATPLOTPP_WITH_OpenCV "Require building with OpenCV support" OFF) + # Where to find dependencies option(MATPLOTPP_WITH_SYSTEM_CIMG "Use system-provided CImg.h instead of bundled" OFF) option(MATPLOTPP_WITH_SYSTEM_NODESOUP "Use system-provided nodesoup instead of bundled" OFF) diff --git a/Matplot++Config.cmake.in b/Matplot++Config.cmake.in index 4efbd94a..804d5b80 100644 --- a/Matplot++Config.cmake.in +++ b/Matplot++Config.cmake.in @@ -11,11 +11,24 @@ if (NOT CMAKE_CXX_COMPILER_ID STREQUAL MATPLOT_BUILT_CXX_COMPILER_ID) endif() # Find dependencies + if(NOT ${MATPLOT_BUILT_SHARED}) include(CMakeFindDependencyMacro) list(APPEND CMAKE_MODULE_PATH ${MATPLOT_CONFIG_INSTALL_DIR}) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") + + # optional dependencies + set(MATPLOT_OPTIONAL_DEPENDENCIES JPEG TIFF ZLIB LAPACK BLAS FFTW OpenCV) + foreach(MATPLOT_OPTIONAL_DEPENDENCY ${MATPLOT_OPTIONAL_DEPENDENCIES}) + if (@MATPLOTPP_WITH_${MATPLOT_OPTIONAL_DEPENDENCY}@) + find_dependency(${MATPLOT_OPTIONAL_DEPENDENCY} REQUIRED) + else() + find_dependency(${MATPLOT_OPTIONAL_DEPENDENCY}) + endif() + endforeach() + find_dependency(Filesystem COMPONENTS Experimental Final) + # OpenGL backend if (@MATPLOTPP_BUILD_EXPERIMENTAL_OPENGL_BACKEND@) find_dependency(glad) diff --git a/source/3rd_party/CMakeLists.txt b/source/3rd_party/CMakeLists.txt index b5656e12..d2d4d19f 100644 --- a/source/3rd_party/CMakeLists.txt +++ b/source/3rd_party/CMakeLists.txt @@ -69,21 +69,34 @@ find_package(PkgConfig) # Lots of optional packages are not a good idea in general. # It makes the library much less "packagable" (https://youtu.be/sBP17HQAQjk) # and much more difficult to make sure it works on multiple OSs -find_package(JPEG) + +if(MATPLOTPP_WITH_JPEG) + find_package(JPEG REQUIRED) +else() + find_package(JPEG QUIET) +endif() if(JPEG_FOUND) target_compile_definitions(cimg INTERFACE cimg_use_jpeg) target_link_libraries(cimg INTERFACE ${JPEG_LIBRARIES}) target_include_directories(cimg INTERFACE ${JPEG_INCLUDE_DIRS}) endif() -find_package(TIFF) +if(MATPLOTPP_WITH_TIFF) + find_package(TIFF REQUIRED) +else() + find_package(TIFF QUIET) +endif() if(TIFF_FOUND) target_compile_definitions(cimg INTERFACE cimg_use_tiff) target_link_libraries(cimg INTERFACE ${TIFF_LIBRARIES}) target_include_directories(cimg INTERFACE ${TIFF_INCLUDE_DIRS}) endif() -find_package(ZLIB) +if(MATPLOTPP_WITH_ZLIB) + find_package(ZLIB REQUIRED) +else() + find_package(ZLIB QUIET) +endif() if(ZLIB_FOUND) find_package(PNG) if (PNG_FOUND) @@ -93,21 +106,33 @@ if(ZLIB_FOUND) endif () endif() -find_package(LAPACK) +if(MATPLOTPP_WITH_LAPACK) + find_package(LAPACK REQUIRED) +else() + find_package(LAPACK QUIET) +endif() if(LAPACK_FOUND) target_compile_definitions(cimg INTERFACE cimg_use_lapack) target_link_libraries(cimg INTERFACE ${LAPACK_LIBRARIES}) target_include_directories(cimg INTERFACE ${LAPACK_INCLUDE_DIRS}) endif() -find_package(BLAS) +if(MATPLOTPP_WITH_BLAS) + find_package(BLAS REQUIRED) +else() + find_package(BLAS QUIET) +endif() if(BLAS_FOUND) target_compile_definitions(cimg INTERFACE cimg_use_blas) target_link_libraries(cimg INTERFACE ${BLAS_LIBRARIES}) target_include_directories(cimg INTERFACE ${BLAS_INCLUDE_DIRS}) endif() -find_package(FFTW) +if(MATPLOTPP_WITH_FFTW) + find_package(FFTW REQUIRED) +else() + find_package(FFTW QUIET) +endif() if(FFTW_FOUND) target_compile_definitions(cimg INTERFACE cimg_use_fftw3) target_link_libraries(cimg INTERFACE ${FFTW_LIBRARIES}) @@ -115,7 +140,11 @@ if(FFTW_FOUND) endif() if (CMAKE_MODULE_PATH) - find_package(OpenCV QUIET) + if(MATPLOTPP_WITH_OpenCV) + find_package(OpenCV REQUIRED) + else() + find_package(OpenCV QUIET) + endif() if (OpenCV_FOUND) target_compile_definitions(cimg INTERFACE cimg_use_opencv) target_link_libraries(cimg INTERFACE ${OpenCV_LIBRARIES}) @@ -153,4 +182,4 @@ endif() if(MASTER_PROJECT AND NOT BUILD_SHARED_LIBS) install(TARGETS cimg EXPORT Matplot++Targets) -endif() \ No newline at end of file +endif() From 666da2071371b47bd2c57162ff9d972333cd3bb8 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 14 Jun 2023 01:17:44 -0700 Subject: [PATCH 2/8] fix: fix the PNG option --- CMakeLists.txt | 2 +- Matplot++Config.cmake.in | 2 +- source/3rd_party/CMakeLists.txt | 15 +++++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b3cb246..12e814d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,7 +56,7 @@ option(MATPLOTPP_BUILD_EXPERIMENTAL_OPENGL_BACKEND "Compile target with the expe # Optional dependencies option(MATPLOTPP_WITH_JPEG "Require building with JPEG support" OFF) option(MATPLOTPP_WITH_TIFF "Require building with TIFF support" OFF) -option(MATPLOTPP_WITH_ZLIB "Require building with ZLIB support" OFF) +option(MATPLOTPP_WITH_PNG "Require building with PNG support" OFF) option(MATPLOTPP_WITH_LAPACK "Require building with LAPACK support" OFF) option(MATPLOTPP_WITH_BLAS "Require building with BLAS support" OFF) option(MATPLOTPP_WITH_FFTW "Require building with FFTW support" OFF) diff --git a/Matplot++Config.cmake.in b/Matplot++Config.cmake.in index 804d5b80..06845785 100644 --- a/Matplot++Config.cmake.in +++ b/Matplot++Config.cmake.in @@ -18,7 +18,7 @@ if(NOT ${MATPLOT_BUILT_SHARED}) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") # optional dependencies - set(MATPLOT_OPTIONAL_DEPENDENCIES JPEG TIFF ZLIB LAPACK BLAS FFTW OpenCV) + set(MATPLOT_OPTIONAL_DEPENDENCIES JPEG TIFF ZLIB PNG LAPACK BLAS FFTW OpenCV) foreach(MATPLOT_OPTIONAL_DEPENDENCY ${MATPLOT_OPTIONAL_DEPENDENCIES}) if (@MATPLOTPP_WITH_${MATPLOT_OPTIONAL_DEPENDENCY}@) find_dependency(${MATPLOT_OPTIONAL_DEPENDENCY} REQUIRED) diff --git a/source/3rd_party/CMakeLists.txt b/source/3rd_party/CMakeLists.txt index d2d4d19f..a5bbbf63 100644 --- a/source/3rd_party/CMakeLists.txt +++ b/source/3rd_party/CMakeLists.txt @@ -92,18 +92,17 @@ if(TIFF_FOUND) target_include_directories(cimg INTERFACE ${TIFF_INCLUDE_DIRS}) endif() -if(MATPLOTPP_WITH_ZLIB) +if(MATPLOTPP_WITH_PNG) find_package(ZLIB REQUIRED) + find_package(PNG REQUIRED) else() find_package(ZLIB QUIET) + find_package(PNG QUIET) endif() -if(ZLIB_FOUND) - find_package(PNG) - if (PNG_FOUND) - target_compile_definitions(cimg INTERFACE cimg_use_zlib cimg_use_png) - target_include_directories(cimg INTERFACE ${ZLIB_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS}) - target_link_libraries(cimg INTERFACE ${ZLIB_LIBRARIES} ${PNG_LIBRARIES}) - endif () +if(ZLIB_FOUND AND PNG_FOUND) + target_compile_definitions(cimg INTERFACE cimg_use_zlib cimg_use_png) + target_include_directories(cimg INTERFACE ${ZLIB_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS}) + target_link_libraries(cimg INTERFACE ${ZLIB_LIBRARIES} ${PNG_LIBRARIES}) endif() if(MATPLOTPP_WITH_LAPACK) From 17056e3047a3564d748c7a9b2afec0901a326d44 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 14 Jun 2023 01:23:26 -0700 Subject: [PATCH 3/8] fix: only use the old style dependencies if target is not defined --- source/3rd_party/CMakeLists.txt | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/source/3rd_party/CMakeLists.txt b/source/3rd_party/CMakeLists.txt index a5bbbf63..7b976ce9 100644 --- a/source/3rd_party/CMakeLists.txt +++ b/source/3rd_party/CMakeLists.txt @@ -101,8 +101,18 @@ else() endif() if(ZLIB_FOUND AND PNG_FOUND) target_compile_definitions(cimg INTERFACE cimg_use_zlib cimg_use_png) - target_include_directories(cimg INTERFACE ${ZLIB_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS}) - target_link_libraries(cimg INTERFACE ${ZLIB_LIBRARIES} ${PNG_LIBRARIES}) + if (NOT TARGET ZLIB::ZLIB) + add_library(ZLIB::ZLIB INTERFACE) + target_include_directories(ZLIB::ZLIB INTERFACE ${ZLIB_INCLUDE_DIRS}) + target_link_libraries(ZLIB::ZLIB INTERFACE ${ZLIB_LIBRARIES}) + endif() + target_link_libraries(cimg INTERFACE ZLIB::ZLIB) + if (NOT TARGET png) + add_library(png INTERFACE) + target_include_directories(png INTERFACE ${PNG_INCLUDE_DIRS}) + target_link_libraries(cimg INTERFACE ${PNG_LIBRARIES}) + endif() + target_link_libraries(cimg INTERFACE png) endif() if(MATPLOTPP_WITH_LAPACK) @@ -134,8 +144,12 @@ else() endif() if(FFTW_FOUND) target_compile_definitions(cimg INTERFACE cimg_use_fftw3) - target_link_libraries(cimg INTERFACE ${FFTW_LIBRARIES}) - target_include_directories(cimg INTERFACE ${FFTW_INCLUDE_DIRS}) + if (NOT TARGET FFTW::fftw3) + add_library(FFTW::fftw3 INTERFACE) + target_include_directories(FFTW::fftw3 INTERFACE ${FFTW_INCLUDE_DIRS}) + target_link_libraries(FFTW::fftw3 INTERFACE ${FFTW_LIBRARIES}) + endif() + target_link_libraries(cimg INTERFACE FFTW::fftw3) endif() if (CMAKE_MODULE_PATH) @@ -146,8 +160,12 @@ if (CMAKE_MODULE_PATH) endif() if (OpenCV_FOUND) target_compile_definitions(cimg INTERFACE cimg_use_opencv) - target_link_libraries(cimg INTERFACE ${OpenCV_LIBRARIES}) - target_include_directories(cimg INTERFACE ${OpenCV_INCLUDE_DIRS}) + if(NOT TARGET opencv_core) + add_library(opencv_core INTERFACE) + target_include_directories(opencv_core INTERFACE ${OpenCV_INCLUDE_DIRS}) + target_link_libraries(opencv_core INTERFACE ${OpenCV_LIBRARIES}) + endif() + target_link_libraries(cimg INTERFACE opencv_core) endif() else() message("No CMAKE_MODULE_PATH path for OpenCV configured") From 6f6a5316d5b9a5b57597ae30b20c3945d21e6cfc Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 14 Jun 2023 01:27:48 -0700 Subject: [PATCH 4/8] fix: fix nodesoup installation --- source/3rd_party/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/3rd_party/CMakeLists.txt b/source/3rd_party/CMakeLists.txt index 7b976ce9..42ebfb40 100644 --- a/source/3rd_party/CMakeLists.txt +++ b/source/3rd_party/CMakeLists.txt @@ -44,7 +44,9 @@ endif() if(MASTER_PROJECT AND NOT BUILD_SHARED_LIBS) install(TARGETS nodesoup EXPORT Matplot++Targets - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/Matplot++) + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) endif() From 914c869ff9e1c0b01093fc997f13fce4378356ed Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 14 Jun 2023 01:35:23 -0700 Subject: [PATCH 5/8] fix: ensure that all the required libraries are exported --- source/3rd_party/CMakeLists.txt | 9 ++++++++- source/matplot/CMakeLists.txt | 8 ++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/source/3rd_party/CMakeLists.txt b/source/3rd_party/CMakeLists.txt index 42ebfb40..f1ae4f2d 100644 --- a/source/3rd_party/CMakeLists.txt +++ b/source/3rd_party/CMakeLists.txt @@ -1,3 +1,5 @@ +set(EXPORTED_TARGETS) + ####################################################### ### NodeSoup ### ####################################################### @@ -54,6 +56,7 @@ endif() ### CImg ### ####################################################### add_library(cimg INTERFACE) +list(APPEND EXPORTED_TARGETS cimg) if(WITH_SYSTEM_CIMG) find_path(CIMG_INCLUDE_DIR CImg.h REQUIRED) else() @@ -107,12 +110,14 @@ if(ZLIB_FOUND AND PNG_FOUND) add_library(ZLIB::ZLIB INTERFACE) target_include_directories(ZLIB::ZLIB INTERFACE ${ZLIB_INCLUDE_DIRS}) target_link_libraries(ZLIB::ZLIB INTERFACE ${ZLIB_LIBRARIES}) + list(APPEND EXPORTED_TARGETS ZLIB::ZLIB) endif() target_link_libraries(cimg INTERFACE ZLIB::ZLIB) if (NOT TARGET png) add_library(png INTERFACE) target_include_directories(png INTERFACE ${PNG_INCLUDE_DIRS}) target_link_libraries(cimg INTERFACE ${PNG_LIBRARIES}) + list(APPEND EXPORTED_TARGETS png) endif() target_link_libraries(cimg INTERFACE png) endif() @@ -150,6 +155,7 @@ if(FFTW_FOUND) add_library(FFTW::fftw3 INTERFACE) target_include_directories(FFTW::fftw3 INTERFACE ${FFTW_INCLUDE_DIRS}) target_link_libraries(FFTW::fftw3 INTERFACE ${FFTW_LIBRARIES}) + list(APPEND EXPORTED_TARGETS FFTW::fftw3) endif() target_link_libraries(cimg INTERFACE FFTW::fftw3) endif() @@ -166,6 +172,7 @@ if (CMAKE_MODULE_PATH) add_library(opencv_core INTERFACE) target_include_directories(opencv_core INTERFACE ${OpenCV_INCLUDE_DIRS}) target_link_libraries(opencv_core INTERFACE ${OpenCV_LIBRARIES}) + list(APPEND EXPORTED_TARGETS opencv_core) endif() target_link_libraries(cimg INTERFACE opencv_core) endif() @@ -199,6 +206,6 @@ endif() # Install (only necessary for static lib build) if(MASTER_PROJECT AND NOT BUILD_SHARED_LIBS) - install(TARGETS cimg + install(TARGETS ${EXPORTED_TARGETS} EXPORT Matplot++Targets) endif() diff --git a/source/matplot/CMakeLists.txt b/source/matplot/CMakeLists.txt index 0e4a9317..9299a883 100644 --- a/source/matplot/CMakeLists.txt +++ b/source/matplot/CMakeLists.txt @@ -90,7 +90,7 @@ add_library(matplot freestanding/plot.h ) -set(TARGETS matplot) +set(EXPORTED_TARGETS matplot) # Target aliases add_library(Matplot++::matplot ALIAS matplot) @@ -230,7 +230,7 @@ if (MATPLOTPP_BUILD_EXPERIMENTAL_OPENGL_BACKEND) if(TARGET glad AND NOT TARGET glad::glad) # Alias glad to glad::glad add_library(glad::glad ALIAS glad) - list(APPEND TARGETS glad) + list(APPEND EXPORTED_TARGETS glad) endif() if(NOT TARGET glad::glad) # FindGLAD does not usually create a target, so we create an interface target @@ -256,7 +256,7 @@ if (MATPLOTPP_BUILD_EXPERIMENTAL_OPENGL_BACKEND) ) target_link_libraries(matplot_opengl PUBLIC matplot glad::glad glfw ${CMAKE_DL_LIBS}) - list(APPEND TARGETS matplot_opengl) + list(APPEND EXPORTED_TARGETS matplot_opengl) endif() ####################################################### @@ -264,7 +264,7 @@ endif() ####################################################### if (MATPLOTPP_BUILD_INSTALLER) # Install targets - install(TARGETS ${TARGETS} + install(TARGETS ${EXPORTED_TARGETS} EXPORT Matplot++Targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} From 92b806b92b9c73d85f50dd2ea57b73efa4b3c661 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 14 Jun 2023 01:54:17 -0700 Subject: [PATCH 6/8] fix: fix finding FFTW3 --- Matplot++Config.cmake.in | 2 +- source/3rd_party/CMakeLists.txt | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Matplot++Config.cmake.in b/Matplot++Config.cmake.in index 06845785..e0b25cbb 100644 --- a/Matplot++Config.cmake.in +++ b/Matplot++Config.cmake.in @@ -18,7 +18,7 @@ if(NOT ${MATPLOT_BUILT_SHARED}) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") # optional dependencies - set(MATPLOT_OPTIONAL_DEPENDENCIES JPEG TIFF ZLIB PNG LAPACK BLAS FFTW OpenCV) + set(MATPLOT_OPTIONAL_DEPENDENCIES JPEG TIFF ZLIB PNG LAPACK BLAS FFTW3 OpenCV) foreach(MATPLOT_OPTIONAL_DEPENDENCY ${MATPLOT_OPTIONAL_DEPENDENCIES}) if (@MATPLOTPP_WITH_${MATPLOT_OPTIONAL_DEPENDENCY}@) find_dependency(${MATPLOT_OPTIONAL_DEPENDENCY} REQUIRED) diff --git a/source/3rd_party/CMakeLists.txt b/source/3rd_party/CMakeLists.txt index f1ae4f2d..2169d6b9 100644 --- a/source/3rd_party/CMakeLists.txt +++ b/source/3rd_party/CMakeLists.txt @@ -145,19 +145,25 @@ if(BLAS_FOUND) endif() if(MATPLOTPP_WITH_FFTW) - find_package(FFTW REQUIRED) + find_package(FFTW3) + if(NOT FFTW3_FOUND) + find_package(FFTW REQUIRED) + endif() else() - find_package(FFTW QUIET) + find_package(FFTW3 QUIET) + if(NOT FFTW3_FOUND) + find_package(FFTW QUIET) + endif() endif() -if(FFTW_FOUND) +if(FFTW3_FOUND OR FFTW_FOUND) target_compile_definitions(cimg INTERFACE cimg_use_fftw3) - if (NOT TARGET FFTW::fftw3) - add_library(FFTW::fftw3 INTERFACE) - target_include_directories(FFTW::fftw3 INTERFACE ${FFTW_INCLUDE_DIRS}) - target_link_libraries(FFTW::fftw3 INTERFACE ${FFTW_LIBRARIES}) - list(APPEND EXPORTED_TARGETS FFTW::fftw3) + if (NOT TARGET FFTW3::fftw3) + add_library(FFTW3::fftw3 INTERFACE) + target_include_directories(FFTW3::fftw3 INTERFACE ${FFTW3_INCLUDE_DIRS} ${FFTW_INCLUDE_DIRS}) + target_link_libraries(FFTW3::fftw3 INTERFACE ${FFTW3_LIBRARIES} ${FFTW_LIBRARIES}) + list(APPEND EXPORTED_TARGETS FFTW3::fftw3) endif() - target_link_libraries(cimg INTERFACE FFTW::fftw3) + target_link_libraries(cimg INTERFACE FFTW3::fftw3) endif() if (CMAKE_MODULE_PATH) From ed3d1c4044efc2e3e283fca86a1ad5c0af8bc3af Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 14 Jun 2023 02:01:05 -0700 Subject: [PATCH 7/8] fix: fix finding the libpng --- source/3rd_party/CMakeLists.txt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/source/3rd_party/CMakeLists.txt b/source/3rd_party/CMakeLists.txt index 2169d6b9..f9e3684f 100644 --- a/source/3rd_party/CMakeLists.txt +++ b/source/3rd_party/CMakeLists.txt @@ -99,12 +99,18 @@ endif() if(MATPLOTPP_WITH_PNG) find_package(ZLIB REQUIRED) - find_package(PNG REQUIRED) + find_package(libpng) + if(NOT libpng_FOUND) + find_package(PNG REQUIRED) + endif() else() find_package(ZLIB QUIET) - find_package(PNG QUIET) + find_package(libpng QUIET) + if(NOT libpng_FOUND) + find_package(PNG QUIET) + endif() endif() -if(ZLIB_FOUND AND PNG_FOUND) +if(ZLIB_FOUND AND (libpng_FOUND OR PNG_FOUND)) target_compile_definitions(cimg INTERFACE cimg_use_zlib cimg_use_png) if (NOT TARGET ZLIB::ZLIB) add_library(ZLIB::ZLIB INTERFACE) @@ -115,8 +121,8 @@ if(ZLIB_FOUND AND PNG_FOUND) target_link_libraries(cimg INTERFACE ZLIB::ZLIB) if (NOT TARGET png) add_library(png INTERFACE) - target_include_directories(png INTERFACE ${PNG_INCLUDE_DIRS}) - target_link_libraries(cimg INTERFACE ${PNG_LIBRARIES}) + target_include_directories(png INTERFACE ${libpng_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS}) + target_link_libraries(cimg INTERFACE ${libpng_LIBRARIES} ${PNG_LIBRARIES}) list(APPEND EXPORTED_TARGETS png) endif() target_link_libraries(cimg INTERFACE png) From 99c3dea4ddba09df49a56084ddff6952dd31ebf7 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 14 Jun 2023 02:25:12 -0700 Subject: [PATCH 8/8] fix: directly link dependencies instead of aliasing Fixes exporting issues --- source/3rd_party/CMakeLists.txt | 42 +++++++++++++++------------------ source/matplot/CMakeLists.txt | 25 ++++++++++---------- 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/source/3rd_party/CMakeLists.txt b/source/3rd_party/CMakeLists.txt index f9e3684f..5b806ea1 100644 --- a/source/3rd_party/CMakeLists.txt +++ b/source/3rd_party/CMakeLists.txt @@ -112,20 +112,18 @@ else() endif() if(ZLIB_FOUND AND (libpng_FOUND OR PNG_FOUND)) target_compile_definitions(cimg INTERFACE cimg_use_zlib cimg_use_png) - if (NOT TARGET ZLIB::ZLIB) - add_library(ZLIB::ZLIB INTERFACE) - target_include_directories(ZLIB::ZLIB INTERFACE ${ZLIB_INCLUDE_DIRS}) - target_link_libraries(ZLIB::ZLIB INTERFACE ${ZLIB_LIBRARIES}) - list(APPEND EXPORTED_TARGETS ZLIB::ZLIB) + if (TARGET ZLIB::ZLIB) + target_link_libraries(cimg INTERFACE ZLIB::ZLIB) + else() + target_include_directories(cimg INTERFACE ${ZLIB_INCLUDE_DIRS}) + target_link_libraries(cimg INTERFACE ${ZLIB_LIBRARIES}) endif() - target_link_libraries(cimg INTERFACE ZLIB::ZLIB) - if (NOT TARGET png) - add_library(png INTERFACE) - target_include_directories(png INTERFACE ${libpng_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS}) + if (TARGET png) + target_link_libraries(cimg INTERFACE png) + else() + target_include_directories(cimg INTERFACE ${libpng_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS}) target_link_libraries(cimg INTERFACE ${libpng_LIBRARIES} ${PNG_LIBRARIES}) - list(APPEND EXPORTED_TARGETS png) endif() - target_link_libraries(cimg INTERFACE png) endif() if(MATPLOTPP_WITH_LAPACK) @@ -163,13 +161,12 @@ else() endif() if(FFTW3_FOUND OR FFTW_FOUND) target_compile_definitions(cimg INTERFACE cimg_use_fftw3) - if (NOT TARGET FFTW3::fftw3) - add_library(FFTW3::fftw3 INTERFACE) - target_include_directories(FFTW3::fftw3 INTERFACE ${FFTW3_INCLUDE_DIRS} ${FFTW_INCLUDE_DIRS}) - target_link_libraries(FFTW3::fftw3 INTERFACE ${FFTW3_LIBRARIES} ${FFTW_LIBRARIES}) - list(APPEND EXPORTED_TARGETS FFTW3::fftw3) + if (TARGET FFTW3::fftw3) + target_link_libraries(cimg INTERFACE FFTW3::fftw3) + else() + target_include_directories(cimg INTERFACE ${FFTW3_INCLUDE_DIRS} ${FFTW_INCLUDE_DIRS}) + target_link_libraries(cimg INTERFACE ${FFTW3_LIBRARIES} ${FFTW_LIBRARIES}) endif() - target_link_libraries(cimg INTERFACE FFTW3::fftw3) endif() if (CMAKE_MODULE_PATH) @@ -180,13 +177,12 @@ if (CMAKE_MODULE_PATH) endif() if (OpenCV_FOUND) target_compile_definitions(cimg INTERFACE cimg_use_opencv) - if(NOT TARGET opencv_core) - add_library(opencv_core INTERFACE) - target_include_directories(opencv_core INTERFACE ${OpenCV_INCLUDE_DIRS}) - target_link_libraries(opencv_core INTERFACE ${OpenCV_LIBRARIES}) - list(APPEND EXPORTED_TARGETS opencv_core) + if(TARGET opencv_core) + target_link_libraries(cimg INTERFACE opencv_core) + else() + target_include_directories(cimg INTERFACE ${OpenCV_INCLUDE_DIRS}) + target_link_libraries(cimg INTERFACE ${OpenCV_LIBRARIES}) endif() - target_link_libraries(cimg INTERFACE opencv_core) endif() else() message("No CMAKE_MODULE_PATH path for OpenCV configured") diff --git a/source/matplot/CMakeLists.txt b/source/matplot/CMakeLists.txt index 9299a883..3e4850af 100644 --- a/source/matplot/CMakeLists.txt +++ b/source/matplot/CMakeLists.txt @@ -214,6 +214,13 @@ if (MATPLOTPP_BUILD_EXPERIMENTAL_OPENGL_BACKEND) # The biggest con of the OpenGL backend is that it cannot open a window # in another thread. All it can do is get in the middle of the render # loop and draw the plot. + add_library(matplot_opengl + backend/opengl_embed.h + backend/opengl_embed.cpp + backend/opengl.h + backend/opengl.cpp + ) + find_package(OpenGL) # https://github.com/Dav1dde/glad @@ -226,13 +233,13 @@ if (MATPLOTPP_BUILD_EXPERIMENTAL_OPENGL_BACKEND) # find_package(GLAD REQUIRE) would suffice if it worked well FetchContent_Declare(glad GIT_REPOSITORY https://github.com/Dav1dde/glad.git GIT_TAG v0.1.36) FetchContent_MakeAvailable(glad) - endif() - if(TARGET glad AND NOT TARGET glad::glad) - # Alias glad to glad::glad - add_library(glad::glad ALIAS glad) list(APPEND EXPORTED_TARGETS glad) endif() - if(NOT TARGET glad::glad) + if(TARGET glad::glad) + target_link_libraries(matplot_opengl PUBLIC glad::glad) + elseif(TARGET glad) + target_link_libraries(matplot_opengl PUBLIC glad) + else() # FindGLAD does not usually create a target, so we create an interface target add_library(glad::glad INTERFACE) target_include_directories(glad::glad INTERFACE ${GLAD_INCLUDE_PATH}) @@ -248,13 +255,7 @@ if (MATPLOTPP_BUILD_EXPERIMENTAL_OPENGL_BACKEND) FetchContent_MakeAvailable(glfw3) endif() - add_library(matplot_opengl - backend/opengl_embed.h - backend/opengl_embed.cpp - backend/opengl.h - backend/opengl.cpp - ) - target_link_libraries(matplot_opengl PUBLIC matplot glad::glad glfw ${CMAKE_DL_LIBS}) + target_link_libraries(matplot_opengl PUBLIC matplot glfw ${CMAKE_DL_LIBS}) list(APPEND EXPORTED_TARGETS matplot_opengl) endif()