shithub: rgbds

Download patch

ref: 4f13a336b9610c5a58bc1a63a04220a89d07253b
parent: dfcba364487a775a88e196ec0a2a2d4d29d80ec5
parent: 03e20138d37722ba2a9c9a22d36f45262adf0348
author: Eldred Habert <eldredhabert0@gmail.com>
date: Fri Oct 2 18:30:30 EDT 2020

Merge pull request #578 from JL2210/cmake-pkgconfig

Use pkg-config to detect libpng

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,9 +35,6 @@
   message(FATAL_ERROR "Terminating configuration")
 endif()
 
-find_package(PNG 1.2 REQUIRED)
-find_package(BISON REQUIRED)
-
 include_directories("${PROJECT_SOURCE_DIR}/include")
 
 if(DEVELOP)
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -12,6 +12,16 @@
     "version.c"
     )
 
+find_package(BISON REQUIRED)
+find_package(PkgConfig)
+
+if(NOT PKG_CONFIG_FOUND)
+  # fallback to find_package
+  find_package(PNG REQUIRED)
+else()
+  pkg_check_modules(LIBPNG REQUIRED libpng)
+endif()
+
 BISON_TARGET(ASMy "asm/asmy.y"
              "${PROJECT_SOURCE_DIR}/src/asm/asmy.c"
              DEFINES_FILE "${PROJECT_SOURCE_DIR}/src/asm/asmy.h"
@@ -68,9 +78,15 @@
   install(TARGETS rgb${PROG} RUNTIME DESTINATION bin)
 endforeach()
 
-target_compile_definitions(rgbgfx PRIVATE ${PNG_DEFINITIONS})
-target_include_directories(rgbgfx PRIVATE ${PNG_INCLUDE_DIRS})
-target_link_libraries(rgbgfx PRIVATE ${PNG_LIBRARIES})
+if(LIBPNG_FOUND) # pkg-config
+  target_include_directories(rgbgfx PRIVATE ${LIBPNG_INCLUDE_DIRS})
+  target_link_directories(rgbgfx PRIVATE ${LIBPNG_LIBRARY_DIRS})
+  target_link_libraries(rgbgfx PRIVATE ${LIBPNG_LIBRARIES})
+else()
+  target_compile_definitions(rgbgfx PRIVATE ${PNG_DEFINITIONS})
+  target_include_directories(rgbgfx PRIVATE ${PNG_INCLUDE_DIRS})
+  target_link_libraries(rgbgfx PRIVATE ${PNG_LIBRARIES})
+endif()
 
 include(CheckLibraryExists)
 check_library_exists("m" "sin" "" HAS_LIBM)