Skip to content

Commit

Permalink
Use IMPORTED targets handled external dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
hobyst committed Sep 4, 2023
1 parent 12467e1 commit f1c0c6e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 41 deletions.
17 changes: 7 additions & 10 deletions CMake/BackendsDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ if(RMLUI_SAMPLES_BACKEND MATCHES "^SDL")
# Set up the detected SDL as the SDL::SDL INTERFACE target if it hasn't already been created
# This is done for consistent referencing across the CMake code regardless of the CMake version used
if(NOT TARGET SDL::SDL)
add_library(SDL INTERFACE)
add_library(SDL::SDL ALIAS SDL)
add_library(SDL::SDL INTERFACE IMPORTED)

# Any CMake target linking against SDL::SDL will link against the SDL libraries and have
# their include directories added to their target properties
target_link_libraries(SDL INTERFACE ${SDL_LIBRARIES})
target_include_directories(SDL INTERFACE ${SDL_INCLUDE_DIRS})
target_link_libraries(SDL::SDL INTERFACE ${SDL_LIBRARIES})
target_include_directories(SDL::SDL INTERFACE ${SDL_INCLUDE_DIRS})
endif()

# SDL_GL2 backend requires GLEW
Expand Down Expand Up @@ -102,13 +101,12 @@ if(RMLUI_SAMPLES_BACKEND MATCHES "^SDL")
# to make the code more future-proof
# For us, its name will be SDL::Image
if(NOT TARGET SDL::Image)
add_library(SDLimage INTERFACE)
add_library(SDL::Image ALIAS SDLimage)
add_library(SDL::Image INTERFACE IMPORTED)

# Any CMake target linking against SDL::Image will link against the SDL_image libraries
# and have their include directories added to their target properties
target_link_libraries(SDLimage INTERFACE ${SDL_IMAGE_LIBRARIES})
target_include_directories(SDLimage INTERFACE ${SDL_IMAGE_INCLUDE_DIRS})
target_link_libraries(SDL::Image INTERFACE ${SDL_IMAGE_LIBRARIES})
target_include_directories(SDL::Image INTERFACE ${SDL_IMAGE_INCLUDE_DIRS})
endif()
endif()
endif()
Expand Down Expand Up @@ -203,8 +201,7 @@ if(RMLUI_SAMPLES_BACKEND MATCHES "^SFML")

# Create dumb targets to replace the modern component-specific targets
foreach(sfml_component ${RMLUI_SFML_REQUIRED_COMPONENTS})
add_library(rmlui_SFML_${sfml_component} INTERFACE)
add_library(SFML::${sfml_component} ALIAS rmlui_SFML_${sfml_component})
add_library(SFML::${sfml_component} INTERFACE IMPORTED)
endforeach()
endif()
endif()
Expand Down
11 changes: 5 additions & 6 deletions CMake/Modules/Emscripten/FindFreetype.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,19 @@ endif()

# Emscripten includes Freetype support as part of it's SDK, meaning there's no need to find it
set(Freetype_FOUND TRUE)
add_library(freetype INTERFACE)
add_library(Freetype::Freetype ALIAS freetype)
add_library(Freetype::Freetype INTERFACE IMPORTED)

# Set found Freetype version
# Version set based on latest Emscripten SDK at the time of writing this file
set(FREETYPE_VERSION_STRING "2.6")

# Enable compilation and linking against Freetype
target_compile_options(freetype INTERFACE "-sUSE_FREETYPE=1")
target_link_libraries(freetype INTERFACE "-sUSE_FREETYPE=1")
target_compile_options(Freetype::Freetype INTERFACE "-sUSE_FREETYPE=1")
target_link_libraries(Freetype::Freetype INTERFACE "-sUSE_FREETYPE=1")

# Get final compiler and linker flags to print them
get_target_property(Freetype_COMPILE_FLAGS freetype "INTERFACE_COMPILE_OPTIONS")
get_target_property(Freetype_LINK_FLAGS freetype "INTERFACE_LINK_OPTIONS")
get_target_property(Freetype_COMPILE_FLAGS Freetype::Freetype "INTERFACE_COMPILE_OPTIONS")
get_target_property(Freetype_LINK_FLAGS Freetype::Freetype "INTERFACE_LINK_OPTIONS")

find_package_message(
"Freetype"
Expand Down
11 changes: 5 additions & 6 deletions CMake/Modules/Emscripten/FindOpenGL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ endif()

# Emscripten includes OpenGL ES support as part of it's SDK, meaning there's no need to find it
set(OpenGL_FOUND TRUE)
add_library(opengl INTERFACE)
add_library(OpenGL::GL ALIAS opengl)
add_library(OpenGL::GL INTERFACE IMPORTED)

# Set found OpenGL version
if((OpenGL_FIND_VERSION VERSION_GREATER_EQUAL "1") AND (OpenGL_FIND_VERSION VERSION_LESS "2"))
Expand All @@ -50,18 +49,18 @@ endif()
# Handle OpenGL 1 edge case
# More info: https://emscripten.org/docs/porting/multimedia_and_graphics/OpenGL-support.html#emulation-of-older-desktop-opengl-api-features
if(OpenGL_VERSION VERSION_EQUAL "1")
target_link_libraries(opengl INTERFACE "-sLEGACY_GL_EMULATION")
target_link_libraries(OpenGL::GL INTERFACE "-sLEGACY_GL_EMULATION")
endif()

# Handle OpenGL ES software emulation
# More info: https://emscripten.org/docs/porting/multimedia_and_graphics/OpenGL-support.html#opengl-es-2-0-3-0-emulation
if(OpenGL_ENABLE_EMULATION AND OpenGL_VERSION VERSION_GREATER_EQUAL "2")
target_link_libraries(opengl INTERFACE "-sFULL_ES${OpenGL_VERSION}")
target_link_libraries(OpenGL::GL INTERFACE "-sFULL_ES${OpenGL_VERSION}")
endif()

# Get final compiler and linker flags to print them
get_target_property(OpenGL_COMPILE_FLAGS opengl "INTERFACE_COMPILE_OPTIONS")
get_target_property(OpenGL_LINK_FLAGS opengl "INTERFACE_LINK_OPTIONS")
get_target_property(OpenGL_COMPILE_FLAGS OpenGL::GL "INTERFACE_COMPILE_OPTIONS")
get_target_property(OpenGL_LINK_FLAGS OpenGL::GL "INTERFACE_LINK_OPTIONS")

find_package_message(
"OpenGL"
Expand Down
11 changes: 5 additions & 6 deletions CMake/Modules/Emscripten/FindSDL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ endif()

# Emscripten includes SDL support as part of it's SDK, meaning there's no need to find it
set(SDL_FOUND TRUE)
add_library(sdl INTERFACE)
add_library(SDL::SDL ALIAS sdl)
add_library(SDL::SDL INTERFACE IMPORTED)

# Set found SDL version based on latest Emscripten SDK at the time of writing this file
if((SDL_FIND_VERSION VERSION_GREATER_EQUAL "1") AND (SDL_FIND_VERSION VERSION_LESS "2"))
Expand All @@ -49,12 +48,12 @@ elseif((SDL_FIND_VERSION VERSION_GREATER_EQUAL "2") AND (SDL_FIND_VERSION VERSIO
endif()

# Enable compilation and linking against SDL
target_compile_options(sdl INTERFACE "-sUSE_SDL=${SDL_EMSCRIPTEN_COMPILER_SELECTED_VERSION}")
target_link_libraries(sdl INTERFACE "-sUSE_SDL=${SDL_EMSCRIPTEN_COMPILER_SELECTED_VERSION}")
target_compile_options(SDL::SDL INTERFACE "-sUSE_SDL=${SDL_EMSCRIPTEN_COMPILER_SELECTED_VERSION}")
target_link_libraries(SDL::SDL INTERFACE "-sUSE_SDL=${SDL_EMSCRIPTEN_COMPILER_SELECTED_VERSION}")

# Get final compiler and linker flags to print them
get_target_property(SDL_COMPILE_FLAGS sdl "INTERFACE_COMPILE_OPTIONS")
get_target_property(SDL_LINK_FLAGS sdl "INTERFACE_LINK_OPTIONS")
get_target_property(SDL_COMPILE_FLAGS SDL::SDL "INTERFACE_COMPILE_OPTIONS")
get_target_property(SDL_LINK_FLAGS SDL::SDL "INTERFACE_LINK_OPTIONS")

find_package_message(
"SDL"
Expand Down
11 changes: 5 additions & 6 deletions CMake/Modules/Emscripten/FindSDL_image.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ message(WARNING

# Emscripten includes SDL support as part of it's SDK, meaning there's no need to find it
set(SDL_image_FOUND TRUE)
add_library(sdl_image INTERFACE)
add_library(SDL::Image ALIAS sdl_image)
add_library(SDL::Image INTERFACE IMPORTED)

# Set found SDL_image version based on latest Emscripten SDK at the time of writing this file
if((SDL_image_FIND_VERSION VERSION_GREATER_EQUAL "1") AND (SDL_image_FIND_VERSION VERSION_LESS "2"))
Expand All @@ -54,12 +53,12 @@ elseif((SDL_image_FIND_VERSION VERSION_GREATER_EQUAL "2") AND (SDL_image_FIND_VE
endif()

# Enable compilation and linking against SDL
target_compile_options(sdl_image INTERFACE "-sUSE_SDL_IMAGE=${SDL_image_EMSCRIPTEN_COMPILER_SELECTED_VERSION}")
target_link_libraries(sdl_image INTERFACE "-sUSE_SDL_IMAGE=${SDL_image_EMSCRIPTEN_COMPILER_SELECTED_VERSION}")
target_compile_options(SDL::Image INTERFACE "-sUSE_SDL_IMAGE=${SDL_image_EMSCRIPTEN_COMPILER_SELECTED_VERSION}")
target_link_libraries(SDL::Image INTERFACE "-sUSE_SDL_IMAGE=${SDL_image_EMSCRIPTEN_COMPILER_SELECTED_VERSION}")

# Get final compiler and linker flags to print them
get_target_property(SDL_image_COMPILE_FLAGS sdl_image "INTERFACE_COMPILE_OPTIONS")
get_target_property(SDL_image_LINK_FLAGS sdl_image "INTERFACE_LINK_OPTIONS")
get_target_property(SDL_image_COMPILE_FLAGS SDL::Image "INTERFACE_COMPILE_OPTIONS")
get_target_property(SDL_image_LINK_FLAGS SDL::Image "INTERFACE_LINK_OPTIONS")

find_package_message(
"SDL_image"
Expand Down
2 changes: 1 addition & 1 deletion CMake/Modules/Emscripten/Findglfw3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ endif()

# Emscripten includes GLFW support as part of it's SDK, meaning there's no need to find it
set(glfw3_FOUND TRUE)
add_library(glfw INTERFACE)
add_library(glfw INTERFACE IMPORTED)

# Set found GLFW version based on latest Emscripten SDK at the time of writing this file
# Version set based on latest Emscripten SDK at the time of writing this file
Expand Down
10 changes: 4 additions & 6 deletions CMake/SamplesShellDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
endif()

# Set up wrapper target
add_library(windows_shell_shlwapi INTERFACE)
add_library(Windows::Shell::LightweightUtility ALIAS windows_shell_shlwapi)
target_link_libraries(windows_shell_shlwapi INTERFACE ${Shlwapi})
add_library(Windows::Shell::LightweightUtility INTERFACE IMPORTED)
target_link_libraries(Windows::Shell::LightweightUtility INTERFACE ${Shlwapi})

# Link against required libraries from macOS
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
Expand All @@ -72,7 +71,6 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
endif()

# Set up wrapper target
add_library(macos_cocoa INTERFACE)
add_library(macOS::Cocoa ALIAS macos_cocoa)
target_link_libraries(macos_cocoa INTERFACE ${Cocoa})
add_library(macOS::Cocoa INTERFACE IMPORTED)
target_link_libraries(macOS::Cocoa INTERFACE ${Cocoa})
endif()

0 comments on commit f1c0c6e

Please sign in to comment.