cmake: provide an IMPORTED target

This commit is contained in:
Joel Bodenmann 2021-11-03 20:50:24 +01:00
parent cc0b175e7f
commit 56a88c440d
2 changed files with 32 additions and 32 deletions

View File

@ -7,7 +7,7 @@ if(NOT UGFX_ROOT)
endif() endif()
# Assemble list of components # Assemble list of components
list(APPEND ugfx_COMPONENTS list(APPEND ugfx_COMPONENTS_BUILTIN
gadc gadc
gaudio gaudio
gdisp gdisp
@ -34,13 +34,15 @@ list(APPEND ugfx_INCLUDE_DIRS
${UGFX_ROOT}/src ${UGFX_ROOT}/src
) )
# Include each component # Include each built-in component
foreach(component ${ugfx_COMPONENTS}) foreach(component ${ugfx_COMPONENTS_BUILTIN})
include(${UGFX_ROOT}/src/${component}/${component}.cmake) include(${UGFX_ROOT}/src/${component}/${component}.cmake)
endforeach() endforeach()
# Include target setup for ease-of-use # Include each component
include(${CMAKE_CURRENT_LIST_DIR}/target_setup.cmake) foreach(component ${ugfx_FIND_COMPONENTS})
include(${UGFX_ROOT}/${component}/driver.cmake)
endforeach()
# Remove duplicates from non-cached variables # Remove duplicates from non-cached variables
list(REMOVE_DUPLICATES ugfx_SOURCES) list(REMOVE_DUPLICATES ugfx_SOURCES)
@ -49,3 +51,28 @@ list(REMOVE_DUPLICATES ugfx_INCLUDE_DIRS)
# Outsource heavy-lifting to cmake # Outsource heavy-lifting to cmake
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ugfx DEFAULT_MSG UGFX_ROOT ugfx_SOURCES ugfx_INCLUDE_DIRS) 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}
)

View File

@ -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()