Skip to content

Commit e79233f

Browse files
committed
Automatically enable used HAL driver modules
Currently, to add a driver module to a project, you have to: - Add the driver module in `CMakeLists.txt` - Set the driver module enabled (e.g. in a HAL config file, such as `stm32f4xx_hal_conf.h`) This change automatically sets the driver module enable definition when a module is included in `CMakeLists.txt`, meaning that you don't also have to edit a header file to enable the module.
1 parent 5d70c43 commit e79233f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

cmake/FindHAL.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ foreach(COMP ${HAL_FIND_COMPONENTS_FAMILIES})
215215
if(NOT (TARGET HAL::STM32::${FAMILY}${CORE_C}))
216216
message(TRACE "FindHAL: creating library HAL::STM32::${FAMILY}${CORE_C}")
217217
add_library(HAL::STM32::${FAMILY}${CORE_C} INTERFACE IMPORTED)
218+
target_compile_definitions(HAL::STM32::${FAMILY}${CORE_C} INTERFACE "USE_HAL_DRIVER")
218219
target_link_libraries(HAL::STM32::${FAMILY}${CORE_C} INTERFACE
219220
STM32::${FAMILY}${CORE_C}
220221
CMSIS::STM32::${FAMILY}${CORE_C})
@@ -246,6 +247,7 @@ foreach(COMP ${HAL_FIND_COMPONENTS_FAMILIES})
246247
if(HAL_${FAMILY}${CORE_U}_${DRV}_SOURCE AND (NOT (TARGET HAL::STM32::${FAMILY}::${DRV})))
247248
message(TRACE "FindHAL: creating library HAL::STM32::${FAMILY}${CORE_C}::${DRV}")
248249
add_library(HAL::STM32::${FAMILY}${CORE_C}::${DRV} INTERFACE IMPORTED)
250+
target_compile_definitions(HAL::STM32::${FAMILY}${CORE_C}::${DRV} INTERFACE "HAL_${DRV}_MODULE_ENABLED")
249251
target_link_libraries(HAL::STM32::${FAMILY}${CORE_C}::${DRV} INTERFACE HAL::STM32::${FAMILY}${CORE_C})
250252
target_sources(HAL::STM32::${FAMILY}${CORE_C}::${DRV} INTERFACE "${HAL_${FAMILY}${CORE_U}_${DRV}_SOURCE}")
251253
endif()

0 commit comments

Comments
 (0)