From 03e20138d37722ba2a9c9a22d36f45262adf0348 Mon Sep 17 00:00:00 2001 From: James Larrowe Date: Thu, 1 Oct 2020 08:18:47 -0400 Subject: [PATCH] Use pkg-config to detect libpng Only fall back to findpng --- CMakeLists.txt | 3 --- src/CMakeLists.txt | 22 +++++++++++++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4cf4161f..f4f234e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,9 +35,6 @@ if(srcdir STREQUAL bindir) message(FATAL_ERROR "Terminating configuration") endif() -find_package(PNG 1.2 REQUIRED) -find_package(BISON REQUIRED) - include_directories("${PROJECT_SOURCE_DIR}/include") if(DEVELOP) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cccca752..c4b22b8c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,16 @@ set(common_src "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 @@ foreach(PROG "asm" "fix" "gfx" "link") 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)