--refactor
This commit is contained in:
@@ -1,31 +1,31 @@
|
||||
set(LIB_NAME CMSIS)
|
||||
if(NOT DEFINED ENV{MCU_SERIES})
|
||||
if(NOT DEFINED MCU_SERIES)
|
||||
message(FATAL_ERROR "MCU_SERIES NOT DEFINED. Please define it like stm32fxx")
|
||||
else()
|
||||
string(TOUPPER $ENV{MCU_SERIES} MCU_SERIES_UPPERCASE)
|
||||
string(TOUPPER ${MCU_SERIES} MCU_SERIES_UPPERCASE)
|
||||
endif()
|
||||
|
||||
project(${LIB_NAME}
|
||||
LANGUAGES C ASM
|
||||
)
|
||||
if (NOT DEFINED ENV{MCU})
|
||||
message(FATAL_ERROR "PLEASE DEFINE ENV{MCU} i.e STM32F427xx")
|
||||
if (NOT DEFINED MCU)
|
||||
message(FATAL_ERROR "PLEASE DEFINE MCU i.e STM32F427xx")
|
||||
endif ()
|
||||
|
||||
if (NOT GTEST)
|
||||
if (NOT $ENV{CORTEX-M} STREQUAL "3" AND NOT $ENV{CORTEX-M} STREQUAL "1" AND NOT $ENV{CORTEX-M} STREQUAL "0" AND NOT $ENV{CORTEX-M} STREQUAL "4" AND NOT $ENV{CORTEX-M} STREQUAL "3" AND NOT $ENV{CORTEX-M} STREQUAL "55" AND NOT $ENV{CORTEX-M} STREQUAL "0+")
|
||||
if (NOT ${CORTEX-M} STREQUAL "3" AND NOT ${CORTEX-M} STREQUAL "1" AND NOT ${CORTEX-M} STREQUAL "0" AND NOT ${CORTEX-M} STREQUAL "4" AND NOT ${CORTEX-M} STREQUAL "3" AND NOT ${CORTEX-M} STREQUAL "55" AND NOT ${CORTEX-M} STREQUAL "0+")
|
||||
message(FATAL_ERROR "Error: please set CORTEX-M")
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED ENV{COMPILE_OPTIONS})
|
||||
set(COMPILE_OPTIONS -ffunction-sections -fdata-sections -fno-common -fmessage-length=0 $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti> -mcpu=cortex-m$ENV{CORTEX-M} -mthumb -mthumb-interwork)
|
||||
if (NOT DEFINED COMPILE_OPTIONS)
|
||||
set(COMPILE_OPTIONS -ffunction-sections -fdata-sections -fno-common -fmessage-length=0 $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti> -mcpu=cortex-m${CORTEX-M} -mthumb -mthumb-interwork)
|
||||
message(WARNING "${LIB_NAME} compile with default options")
|
||||
else ()
|
||||
set(COMPILE_OPTIONS $ENV{COMPILE_OPTIONS})
|
||||
set(COMPILE_OPTIONS ${COMPILE_OPTIONS})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_library(${LIB_NAME} INTERFACE)
|
||||
target_include_directories(${LIB_NAME} INTERFACE Include Device/ST/${MCU_SERIES_UPPERCASE}/Include)
|
||||
target_compile_definitions(${LIB_NAME} INTERFACE "$ENV{MCU}")
|
||||
target_compile_definitions(${LIB_NAME} INTERFACE "${MCU}")
|
||||
target_compile_options(${LIB_NAME} BEFORE INTERFACE ${COMPILE_OPTIONS})
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
add_subdirectory($ENV{MCU_SERIES}_HAL_Driver)
|
||||
add_subdirectory(${MCU_SERIES}_HAL_Driver)
|
||||
add_subdirectory(CMSIS)
|
||||
@@ -1,8 +1,8 @@
|
||||
set(LIB_NAME $ENV{MCU_SERIES}_HAL_DRIVER)
|
||||
string (TOLOWER $ENV{MCU_SERIES} MCU_SERIES)
|
||||
set(LIB_NAME ${MCU_SERIES}_HAL_DRIVER)
|
||||
string (TOLOWER ${MCU_SERIES} MCU_SERIES)
|
||||
|
||||
if (NOT DEFINED ENV{HAL_DRIVER_CONFIG})
|
||||
message(WARNING "HAL_DRIVER_CONFIG not defined \r\n Project will be generate with default config. You can choose full path to configuration file ${MCU_SERIES}_hal_conf.h ENV{HAL_DRIVER_CONFIG}
|
||||
if (NOT DEFINED HAL_DRIVER_CONFIG)
|
||||
message(WARNING "HAL_DRIVER_CONFIG not defined \r\n Project will be generate with default config. You can choose full path to configuration file ${MCU_SERIES}_hal_conf.h
|
||||
filename should be - ${MCU_SERIES}_hal_conf.h" )
|
||||
message(WARNING "PROJECT WILL BE GENERATED WITH DEFAULT CONFIG" )
|
||||
if (NOT EXISTS default_config)
|
||||
@@ -12,17 +12,17 @@ filename should be - ${MCU_SERIES}_hal_conf.h" )
|
||||
file(COPY Inc/${MCU_SERIES}_hal_conf_template.h DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/default_config)
|
||||
file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/default_config/${MCU_SERIES}_hal_conf_template.h ${CMAKE_CURRENT_LIST_DIR}/default_config/${MCU_SERIES}_hal_conf.h )
|
||||
endif()
|
||||
set ($ENV{HAL_DRIVER_CONFIG} ${CMAKE_CURRENT_LIST_DIR}/default_config)
|
||||
set (${HAL_DRIVER_CONFIG} ${CMAKE_CURRENT_LIST_DIR}/default_config)
|
||||
else()
|
||||
string(FIND $ENV{HAL_DRIVER_CONFIG} ${MCU_SERIES}_hal_conf.h output REVERSE)
|
||||
string(SUBSTRING $ENV{HAL_DRIVER_CONFIG} 0 ${output} output)
|
||||
set (ENV{HAL_DRIVER_CONFIG} ${output})
|
||||
string(FIND ${HAL_DRIVER_CONFIG} ${MCU_SERIES}_hal_conf.h output REVERSE)
|
||||
string(SUBSTRING ${HAL_DRIVER_CONFIG} 0 ${output} output)
|
||||
set (HAL_DRIVER_CONFIG ${output})
|
||||
endif()
|
||||
project(${LIB_NAME}
|
||||
LANGUAGES C ASM
|
||||
)
|
||||
|
||||
add_definitions(-DUSE_HAL_DRIVER -D$ENV{MCU} -DUSE_FULL_LL_DRIVER)
|
||||
add_definitions(-DUSE_HAL_DRIVER -D${MCU} -DUSE_FULL_LL_DRIVER)
|
||||
file(GLOB_RECURSE SOURCES "Src/*.c")
|
||||
|
||||
add_library(${LIB_NAME} STATIC ${SOURCES})
|
||||
@@ -30,6 +30,6 @@ add_library(${LIB_NAME}_INTERFACE INTERFACE)
|
||||
if (GTEST)
|
||||
target_include_directories(${LIB_NAME}_INTERFACE INTERFACE Inc)
|
||||
else()
|
||||
target_include_directories(${LIB_NAME} PUBLIC Inc $ENV{HAL_DRIVER_CONFIG})
|
||||
target_include_directories(${LIB_NAME} PUBLIC Inc ${HAL_DRIVER_CONFIG})
|
||||
endif()
|
||||
target_link_libraries(${LIB_NAME} PRIVATE CMSIS)
|
||||
|
||||
Reference in New Issue
Block a user