Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: cmake config include guard #2592

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 52 additions & 50 deletions cmake/raylib-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,67 +11,69 @@
# raylib_LDFLAGS - The linker flags needed with raylib
# raylib_DEFINITIONS - Compiler switches required for using raylib

set(XPREFIX PC_RAYLIB)
if (NOT TARGET raylib)
set(XPREFIX PC_RAYLIB)

find_package(PkgConfig QUIET)
pkg_check_modules(${XPREFIX} QUIET raylib)
find_package(PkgConfig QUIET)
pkg_check_modules(${XPREFIX} QUIET raylib)

if (raylib_USE_STATIC_LIBS)
set(XPREFIX ${XPREFIX}_STATIC)
endif()
if (raylib_USE_STATIC_LIBS)
set(XPREFIX ${XPREFIX}_STATIC)
endif()

set(raylib_DEFINITIONS ${${XPREFIX}_CFLAGS})
set(raylib_DEFINITIONS ${${XPREFIX}_CFLAGS})

find_path(raylib_INCLUDE_DIR
NAMES raylib.h
HINTS ${${XPREFIX}_INCLUDE_DIRS}
)
find_path(raylib_INCLUDE_DIR
NAMES raylib.h
HINTS ${${XPREFIX}_INCLUDE_DIRS}
)

set(RAYLIB_NAMES raylib)
set(RAYLIB_NAMES raylib)

if (raylib_USE_STATIC_LIBS)
set(RAYLIB_NAMES libraylib.a raylib.lib ${RAYLIB_NAMES})
endif()
if (raylib_USE_STATIC_LIBS)
set(RAYLIB_NAMES libraylib.a raylib.lib ${RAYLIB_NAMES})
endif()

find_library(raylib_LIBRARY
NAMES ${RAYLIB_NAMES}
HINTS ${${XPREFIX}_LIBRARY_DIRS}
)
find_library(raylib_LIBRARY
NAMES ${RAYLIB_NAMES}
HINTS ${${XPREFIX}_LIBRARY_DIRS}
)

set(raylib_LIBRARIES ${raylib_LIBRARY})
set(raylib_LIBRARY_DIRS ${${XPREFIX}_LIBRARY_DIRS})
set(raylib_LIBRARY_DIR ${raylib_LIBRARY_DIRS})
set(raylib_INCLUDE_DIRS ${raylib_INCLUDE_DIR})
set(raylib_LDFLAGS ${${XPREFIX}_LDFLAGS})
set(raylib_LIBRARIES ${raylib_LIBRARY})
set(raylib_LIBRARY_DIRS ${${XPREFIX}_LIBRARY_DIRS})
set(raylib_LIBRARY_DIR ${raylib_LIBRARY_DIRS})
set(raylib_INCLUDE_DIRS ${raylib_INCLUDE_DIR})
set(raylib_LDFLAGS ${${XPREFIX}_LDFLAGS})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(raylib DEFAULT_MSG
raylib_LIBRARY
raylib_INCLUDE_DIR
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(raylib DEFAULT_MSG
raylib_LIBRARY
raylib_INCLUDE_DIR
)

mark_as_advanced(raylib_LIBRARY raylib_INCLUDE_DIR)
mark_as_advanced(raylib_LIBRARY raylib_INCLUDE_DIR)

if (raylib_USE_STATIC_LIBS)
add_library(raylib STATIC IMPORTED GLOBAL)
else()
add_library(raylib SHARED IMPORTED GLOBAL)
endif()
string (REPLACE ";" " " raylib_LDFLAGS "${raylib_LDFLAGS}")
if (raylib_USE_STATIC_LIBS)
add_library(raylib STATIC IMPORTED GLOBAL)
else()
add_library(raylib SHARED IMPORTED GLOBAL)
endif()
string (REPLACE ";" " " raylib_LDFLAGS "${raylib_LDFLAGS}")

set_target_properties(raylib
PROPERTIES
IMPORTED_LOCATION "${raylib_LIBRARIES}"
IMPORTED_IMPLIB "${raylib_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${raylib_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${raylib_LDFLAGS}"
INTERFACE_COMPILE_OPTIONS "${raylib_DEFINITIONS}"
)
set_target_properties(raylib
PROPERTIES
IMPORTED_LOCATION "${raylib_LIBRARIES}"
IMPORTED_IMPLIB "${raylib_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${raylib_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${raylib_LDFLAGS}"
INTERFACE_COMPILE_OPTIONS "${raylib_DEFINITIONS}"
)

if (raylib_VERBOSE)
message(STATUS "raylib_FOUND: ${raylib_FOUND}")
message(STATUS "raylib_INCLUDE_DIRS: ${raylib_INCLUDE_DIRS}")
message(STATUS "raylib_LIBRARIES: ${raylib_LIBRARIES}")
message(STATUS "raylib_LDFLAGS: ${raylib_LDFLAGS}")
message(STATUS "raylib_DEFINITIONS: ${raylib_DEFINITIONS}")
if (raylib_VERBOSE)
message(STATUS "raylib_FOUND: ${raylib_FOUND}")
message(STATUS "raylib_INCLUDE_DIRS: ${raylib_INCLUDE_DIRS}")
message(STATUS "raylib_LIBRARIES: ${raylib_LIBRARIES}")
message(STATUS "raylib_LDFLAGS: ${raylib_LDFLAGS}")
message(STATUS "raylib_DEFINITIONS: ${raylib_DEFINITIONS}")
endif()
endif()