Browse Source

cmake: provide an IMPORTED target

master
Joel Bodenmann 11 months ago
parent
commit
56a88c440d
  1. 37
      cmake/Findugfx.cmake
  2. 27
      cmake/target_setup.cmake

37
cmake/Findugfx.cmake

@ -7,7 +7,7 @@ if(NOT UGFX_ROOT)
endif()
# Assemble list of components
list(APPEND ugfx_COMPONENTS
list(APPEND ugfx_COMPONENTS_BUILTIN
gadc
gaudio
gdisp
@ -34,13 +34,15 @@ list(APPEND ugfx_INCLUDE_DIRS
${UGFX_ROOT}/src
)
# Include each component
foreach(component ${ugfx_COMPONENTS})
# Include each built-in component
foreach(component ${ugfx_COMPONENTS_BUILTIN})
include(${UGFX_ROOT}/src/${component}/${component}.cmake)
endforeach()
# Include target setup for ease-of-use
include(${CMAKE_CURRENT_LIST_DIR}/target_setup.cmake)
# Include each component
foreach(component ${ugfx_FIND_COMPONENTS})
include(${UGFX_ROOT}/${component}/driver.cmake)
endforeach()
# Remove duplicates from non-cached variables
list(REMOVE_DUPLICATES ugfx_SOURCES)
@ -49,3 +51,28 @@ list(REMOVE_DUPLICATES ugfx_INCLUDE_DIRS)
# Outsource heavy-lifting to cmake
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ugfx DEFAULT_MSG UGFX_ROOT ugfx_SOURCES ugfx_INCLUDE_DIRS)
# Create the target
if(NOT TARGET ugfx)
add_library(ugfx INTERFACE IMPORTED)
endif()
target_include_directories(
ugfx
INTERFACE
${ugfx_INCLUDE_DIRS}
)
target_sources(
ugfx
INTERFACE
${ugfx_SOURCES}
)
target_compile_definitions(
ugfx
INTERFACE
${ugfx_DEFS}
)
target_link_libraries(
ugfx
INTERFACE
${ugfx_LIBS}
)

27
cmake/target_setup.cmake

@ -1,27 +0,0 @@
function(ugfx_target_setup TARGET)
target_include_directories(
${TARGET}
PRIVATE
${ugfx_INCLUDE_DIRS}
)
target_sources(
${TARGET}
PRIVATE
${ugfx_SOURCES}
)
target_compile_definitions(
${TARGET}
PRIVATE
${ugfx_DEFS}
)
target_link_libraries(
${TARGET}
PRIVATE
${ugfx_LIBS}
)
endfunction()
Loading…
Cancel
Save