From abb3c8e9f7b2ec3b88de5b42140d90d88e1accdc Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 28 Nov 2024 22:44:42 +0100 Subject: [PATCH] Revert "[build][cmake] Improve cmake config file generation (#4541)" This reverts commit c53dd8a9310ad34f730ea853478dc77c8caff23d. --- cmake/GlfwImport.cmake | 10 +--- cmake/InstallConfigurations.cmake | 4 +- cmake/LibraryConfigurations.cmake | 4 ++ cmake/SetupCmakeConfig.cmake | 23 --------- cmake/raylib-config-version.cmake | 21 ++++++++ cmake/raylib-config.cmake | 80 ++++++++++++++++++++++++++++++- src/CMakeLists.txt | 11 +---- 7 files changed, 110 insertions(+), 43 deletions(-) delete mode 100644 cmake/SetupCmakeConfig.cmake create mode 100644 cmake/raylib-config-version.cmake diff --git a/cmake/GlfwImport.cmake b/cmake/GlfwImport.cmake index f10257c3..4a5ef8c6 100644 --- a/cmake/GlfwImport.cmake +++ b/cmake/GlfwImport.cmake @@ -12,18 +12,12 @@ endif() # Also adding only on desktop (web also uses glfw but it is more limited and is added using an emcc linker flag) if(NOT glfw3_FOUND AND NOT USE_EXTERNAL_GLFW STREQUAL "ON" AND "${PLATFORM}" MATCHES "Desktop") MESSAGE(STATUS "Using raylib's GLFW") - set(INTERNAL_GLFW ON CACHE INTERNAL "" FORCE) set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) set(GLFW_INSTALL OFF CACHE BOOL "" FORCE) set(GLFW_LIBRARY_TYPE "OBJECT" CACHE STRING "" FORCE) - - - if (NOT BUILD_SHARED_LIBS) - message(STATUS "Enabling install of GLFW static libs because raylib will be built statically") - set(GLFW_INSTALL ON CACHE BOOL "" FORCE) - endif () + add_subdirectory(external/glfw) @@ -31,7 +25,7 @@ if(NOT glfw3_FOUND AND NOT USE_EXTERNAL_GLFW STREQUAL "ON" AND "${PLATFORM}" MAT if (BUILD_SHARED_LIBS) set_property(TARGET glfw PROPERTY C_VISIBILITY_PRESET hidden) endif() - + list(APPEND raylib_sources $) include_directories(BEFORE SYSTEM external/glfw/include) elseif("${PLATFORM}" STREQUAL "DRM") diff --git a/cmake/InstallConfigurations.cmake b/cmake/InstallConfigurations.cmake index e0f84a15..6c606e56 100644 --- a/cmake/InstallConfigurations.cmake +++ b/cmake/InstallConfigurations.cmake @@ -18,8 +18,10 @@ endif () join_paths(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}") join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") configure_file(../raylib.pc.in raylib.pc @ONLY) +configure_file(../cmake/raylib-config-version.cmake raylib-config-version.cmake @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/raylib.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") -include(SetupCmakeConfig) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/raylib-config-version.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/raylib") +install(FILES ${PROJECT_SOURCE_DIR}/../cmake/raylib-config.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/raylib") # populates raylib_{FOUND, INCLUDE_DIRS, LIBRARIES, LDFLAGS, DEFINITIONS} include(PopulateConfigVariablesLocally) diff --git a/cmake/LibraryConfigurations.cmake b/cmake/LibraryConfigurations.cmake index 6206928c..fb789830 100644 --- a/cmake/LibraryConfigurations.cmake +++ b/cmake/LibraryConfigurations.cmake @@ -125,3 +125,7 @@ if (NOT GRAPHICS) endif () set(LIBS_PRIVATE ${LIBS_PRIVATE} ${OPENAL_LIBRARY}) + +if (${PLATFORM} MATCHES "Desktop") + set(LIBS_PRIVATE ${LIBS_PRIVATE} glfw) +endif () diff --git a/cmake/SetupCmakeConfig.cmake b/cmake/SetupCmakeConfig.cmake deleted file mode 100644 index ba092951..00000000 --- a/cmake/SetupCmakeConfig.cmake +++ /dev/null @@ -1,23 +0,0 @@ -include(CMakePackageConfigHelpers) -include(GNUInstallDirs) - -# Setup install of exported targets -install(EXPORT raylib-targets - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/raylib -) - -# Macro to write config -write_basic_package_version_file( - "${CMAKE_CURRENT_BINARY_DIR}/raylib-config-version.cmake" - VERSION ${raylib_VERSION} - COMPATIBILITY SameMajorVersion -) - -# Setup install of version config -install( - FILES - "../cmake/raylib-config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/raylib-config-version.cmake" - DESTINATION - ${CMAKE_INSTALL_LIBDIR}/cmake/raylib -) diff --git a/cmake/raylib-config-version.cmake b/cmake/raylib-config-version.cmake new file mode 100644 index 00000000..74fd03cc --- /dev/null +++ b/cmake/raylib-config-version.cmake @@ -0,0 +1,21 @@ +set(PACKAGE_VERSION "@PROJECT_VERSION@") + +if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) +endif() +if(NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION) + set(PACKAGE_VERSION_COMPATIBLE TRUE) +else(NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION) + set(PACKAGE_VERSION_UNSUITABLE TRUE) +endif(NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION) + +# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it: +if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "@CMAKE_SIZEOF_VOID_P@" STREQUAL "") + return() +endif() + +if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "@CMAKE_SIZEOF_VOID_P@") + math(EXPR installedBits "8 * 8") + set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)") + set(PACKAGE_VERSION_UNSUITABLE TRUE) +endif() diff --git a/cmake/raylib-config.cmake b/cmake/raylib-config.cmake index 17fefd81..700965c9 100644 --- a/cmake/raylib-config.cmake +++ b/cmake/raylib-config.cmake @@ -1 +1,79 @@ -include("${CMAKE_CURRENT_LIST_DIR}/raylib-targets.cmake") +# - Try to find raylib +# Options: +# raylib_USE_STATIC_LIBS - OFF by default +# raylib_VERBOSE - OFF by default +# Once done, this defines a raylib target that can be passed to +# target_link_libraries as well as following variables: +# +# raylib_FOUND - System has raylib installed +# raylib_INCLUDE_DIRS - The include directories for the raylib header(s) +# raylib_LIBRARIES - The libraries needed to use raylib +# raylib_LDFLAGS - The linker flags needed with raylib +# raylib_DEFINITIONS - Compiler switches required for using raylib + +if (NOT TARGET 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() + + set(raylib_DEFINITIONS ${${XPREFIX}_CFLAGS}) + + find_path(raylib_INCLUDE_DIR + NAMES raylib.h + HINTS ${${XPREFIX}_INCLUDE_DIRS} + ) + + set(RAYLIB_NAMES raylib) + + 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} + ) + + 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 + ) + + 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}") + + 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}") + endif() +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 12cc2434..9735e267 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -90,16 +90,7 @@ if (BUILD_SHARED_LIBS) set_property(TARGET raylib PROPERTY C_VISIBILITY_PRESET hidden) endif () - -# If building as a static lib *AND* using internal GLFW we -# need to set it up as a PRIVATE import so cmake doesn't complain -# it isn't declared on an install rule -if (INTERNAL_GLFW AND BUILD_SHARED_LIBS) - target_link_libraries(raylib PRIVATE glfw) -endif() - -target_link_libraries(raylib PUBLIC "${LIBS_PRIVATE}") - +target_link_libraries(raylib "${LIBS_PRIVATE}") # Sets some compile time definitions for the pre-processor # If CUSTOMIZE_BUILD option is on you will not use config.h by default