CMake: fix dependency build with -Draylib_USE_STATIC_LIBS=ON

Fixes #899, which made apparent three issues with how static libraries
are handled in raylib-config.cmake:

- XPREFIX is set before pkg_check_modules, which causes a duplicate
  STATIC in variables, e.g. PC_RAYLIB_STATIC_STATIC_.*
- raylib_static is searched for, but no library exists with that name
- raylib_LDFLAGS isn't populated properly

This commit fixes these.
This commit is contained in:
Ahmad Fatoum 2019-07-24 00:08:29 +02:00
parent 7b448f59e2
commit 47137b1489
No known key found for this signature in database
GPG Key ID: C3EAC3DE9321D59B
1 changed files with 13 additions and 12 deletions

View File

@ -12,12 +12,14 @@
# raylib_DEFINITIONS - Compiler switches required for using raylib
set(XPREFIX PC_RAYLIB)
find_package(PkgConfig QUIET)
pkg_check_modules(${XPREFIX} QUIET raylib)
if (raylib_USE_STATIC_LIBS)
set(XPREFIX ${XPREFIX}_STATIC)
endif()
find_package(PkgConfig QUIET)
pkg_check_modules(${XPREFIX} QUIET raylib)
set(raylib_DEFINITIONS ${${XPREFIX}_CFLAGS})
find_path(raylib_INCLUDE_DIR
@ -25,17 +27,16 @@ find_path(raylib_INCLUDE_DIR
HINTS ${${XPREFIX}_INCLUDE_DIRS}
)
set(RAYLIB_NAMES raylib)
if (raylib_USE_STATIC_LIBS)
find_library(raylib_LIBRARY
NAMES raylib_static
HINTS ${${XPREFIX}_LIBRARY_DIRS}
)
else ()
find_library(raylib_LIBRARY
NAMES raylib
HINTS ${${XPREFIX}_LIBRARY_DIRS}
)
endif ()
set(RAYLIB_NAMES libraylib.a raylib.lib ${RAYLIB_NAMES})
endif()
find_library(raylib_LIBRARY
NAMES ${RAYLIB_NAMES}
HINTS ${${XPREFIX}_LIBRARY_DIRS}
)
set(raylib_LIBRARIES ${raylib_LIBRARY})
set(raylib_LIBRARY_DIRS ${${XPREFIX}_LIBRARY_DIRS})