Use pkg-config to detect libpng

Only fall back to findpng
This commit is contained in:
James Larrowe
2020-10-01 08:18:47 -04:00
parent dfcba36448
commit 03e20138d3
2 changed files with 19 additions and 6 deletions

View File

@@ -35,9 +35,6 @@ if(srcdir STREQUAL bindir)
message(FATAL_ERROR "Terminating configuration") message(FATAL_ERROR "Terminating configuration")
endif() endif()
find_package(PNG 1.2 REQUIRED)
find_package(BISON REQUIRED)
include_directories("${PROJECT_SOURCE_DIR}/include") include_directories("${PROJECT_SOURCE_DIR}/include")
if(DEVELOP) if(DEVELOP)

View File

@@ -12,6 +12,16 @@ set(common_src
"version.c" "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" BISON_TARGET(ASMy "asm/asmy.y"
"${PROJECT_SOURCE_DIR}/src/asm/asmy.c" "${PROJECT_SOURCE_DIR}/src/asm/asmy.c"
DEFINES_FILE "${PROJECT_SOURCE_DIR}/src/asm/asmy.h" 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) install(TARGETS rgb${PROG} RUNTIME DESTINATION bin)
endforeach() endforeach()
target_compile_definitions(rgbgfx PRIVATE ${PNG_DEFINITIONS}) if(LIBPNG_FOUND) # pkg-config
target_include_directories(rgbgfx PRIVATE ${PNG_INCLUDE_DIRS}) target_include_directories(rgbgfx PRIVATE ${LIBPNG_INCLUDE_DIRS})
target_link_libraries(rgbgfx PRIVATE ${PNG_LIBRARIES}) 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) include(CheckLibraryExists)
check_library_exists("m" "sin" "" HAS_LIBM) check_library_exists("m" "sin" "" HAS_LIBM)