Skip to content

Commit

Permalink
Let Findglfw3.cmake detect whether the GLFW library is static, to pro…
Browse files Browse the repository at this point in the history
…vide a fatal error when building a TGUI dll in such case instead of silently continuing and creating a broken dll file (closes #247)
  • Loading branch information
texus committed Oct 10, 2024
1 parent 6e7270a commit 842ef89
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions cmake/Modules/Findglfw3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,23 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(glfw3

if(glfw3_FOUND)
if(GLFW_LIBRARY AND NOT TARGET glfw)
add_library(glfw UNKNOWN IMPORTED)
set_target_properties(glfw PROPERTIES
IMPORTED_LOCATION "${GLFW_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${GLFW_INCLUDE_DIR}")

get_filename_component(GLFW_LIBRARY_FILENAME "${GLFW_LIBRARY}" NAME)
if(GLFW_LIBRARY_FILENAME STREQUAL "glfw3dll.lib" OR GLFW_LIBRARY_FILENAME STREQUAL "libglfw3dll.a")
add_library(glfw UNKNOWN IMPORTED) # UNKNOWN instead of SHARED because we otherwise must also provide the path to the DLL on Windows
set_target_properties(glfw PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "GLFW_DLL")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows"
AND (GLFW_LIBRARY_FILENAME STREQUAL "libglfw3.a"
OR GLFW_LIBRARY_FILENAME STREQUAL "glfw3.lib"
OR GLFW_LIBRARY_FILENAME STREQUAL "glfw3_mt.lib"))
# If we know that the library is static then explicitly mark it as such so that we can give an error when building TGUI as a dll
add_library(glfw STATIC IMPORTED)
else()
add_library(glfw UNKNOWN IMPORTED)
endif()

set_target_properties(glfw PROPERTIES
IMPORTED_LOCATION "${GLFW_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${GLFW_INCLUDE_DIR}")
endif()
endif()

0 comments on commit 842ef89

Please sign in to comment.