1function(set_library LIBRARY_TYPE LANGUAGE) 2set(EXTRADEFINES " -fstack-usage ") 3 4if(${LIBRARY_TYPE} STREQUAL "REDLIB") 5 set(EXTRADEFINES "${EXTRADEFINES} -D__REDLIB__") 6 set(TARGET_LINK_SYSTEM_LIBRARIES "-lcr_c -lcr_eabihelpers -lgcc" PARENT_SCOPE) 7elseif(${LIBRARY_TYPE} STREQUAL "NEWLIB") 8 set(EXTRADEFINES "${EXTRADEFINES} -D__NEWLIB__") 9 if(${LANGUAGE} STREQUAL "CPP") 10 set(TARGET_LINK_SYSTEM_LIBRARIES "-lstdc++ crti.o crtn.o crtbegin.o crtend.o" PARENT_SCOPE) 11 else() 12 set(TARGET_LINK_SYSTEM_LIBRARIES "-lgcc -lc -lm" PARENT_SCOPE) 13 endif() 14elseif(${LIBRARY_TYPE} STREQUAL "NEWLIB_NANO") 15 set(EXTRADEFINES "${EXTRADEFINES} -D__NEWLIB__") 16 if(${LANGUAGE} STREQUAL "CPP") 17 set(TARGET_LINK_SYSTEM_LIBRARIES "-lstdc++_nano crti.o crtn.o crtbegin.o crtend.o" PARENT_SCOPE) 18 else() 19 set(TARGET_LINK_SYSTEM_LIBRARIES "-lgcc -lc_nano -lm" PARENT_SCOPE) 20 endif() 21endif() 22 23set(CMAKE_ASM_FLAGS " ${CMAKE_ASM_FLAGS} ${EXTRADEFINES}" PARENT_SCOPE) 24set(CMAKE_C_FLAGS " ${CMAKE_C_FLAGS} ${EXTRADEFINES}" PARENT_SCOPE) 25set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} ${EXTRADEFINES}" PARENT_SCOPE) 26endfunction() 27 28function(set_floating_point FPU_TYPE FPU_ABI) 29if(${FPU_TYPE} MATCHES "FPV4-SP-D16") 30 set(FPU "-fsingle-precision-constant -mfpu=fpv4-sp-d16") 31elseif(${FPU_TYPE} MATCHES "FPV5-D16") 32 set(FPU "-fsingle-precision-constant -mfpu=fpv5-d16") 33elseif(${FPU_TYPE} MATCHES "FPV5-SP-D16") 34 set(FPU "-fsingle-precision-constant -mfpu=fpv5-sp-d16") 35endif() 36if(${FPU_ABI} MATCHES "HARD") 37 set(FPU "${FPU} -mfloat-abi=hard" PARENT_SCOPE) 38elseif(${FPU_ABI} MATCHES "SOFT") 39 set(FPU "${FPU} -mfloat-abi=softfp" PARENT_SCOPE) 40else() 41 set(FPU "${FPU}" PARENT_SCOPE) 42endif() 43endfunction() 44 45function(set_debug_console DEBUG_CONSOLE LIBRARY_TYPE) 46if(${DEBUG_CONSOLE} MATCHES "SEMIHOST") 47 set(DEBUG_CONSOLE_CONFIG "-DSDK_DEBUGCONSOLE=0" PARENT_SCOPE) 48else() 49 set(SPECS "--specs=nano.specs --specs=nosys.specs" PARENT_SCOPE) 50 set(DEBUG_CONSOLE_CONFIG "-DSDK_DEBUGCONSOLE=1" PARENT_SCOPE) 51endif() 52 53if(${LIBRARY_TYPE} STREQUAL "NEWLIB" OR ${LIBRARY_TYPE} STREQUAL "NEWLIB_NANO") 54 if(${DEBUG_CONSOLE} STREQUAL "SEMIHOST") 55 set(TARGET_LINK_SYSTEM_LIBRARIES "${TARGET_LINK_SYSTEM_LIBRARIES} -lcr_newlib_semihost" PARENT_SCOPE) 56 elseif(${DEBUG_CONSOLE} STREQUAL "UART" OR ${DEBUG_CONSOLE} STREQUAL "NOHOST") 57 set(TARGET_LINK_SYSTEM_LIBRARIES "${TARGET_LINK_SYSTEM_LIBRARIES} -lcr_newlib_nohost" PARENT_SCOPE) 58 elseif(${DEBUG_CONSOLE} STREQUAL "NONE") 59 set(TARGET_LINK_SYSTEM_LIBRARIES "${TARGET_LINK_SYSTEM_LIBRARIES} -lcr_newlib_none" PARENT_SCOPE) 60 endif() 61elseif(${LIBRARY_TYPE} STREQUAL "REDLIB") 62 if(${DEBUG_CONSOLE} STREQUAL "SEMIHOST") 63 set(TARGET_LINK_SYSTEM_LIBRARIES "${TARGET_LINK_SYSTEM_LIBRARIES} -lcr_semihost" PARENT_SCOPE) 64 elseif(${DEBUG_CONSOLE} STREQUAL "SEMIHOST_NF") 65 set(TARGET_LINK_SYSTEM_LIBRARIES "${TARGET_LINK_SYSTEM_LIBRARIES} -lcr_semihost_nf" PARENT_SCOPE) 66 elseif(${DEBUG_CONSOLE} STREQUAL "SEMIHOST_MB") 67 set(TARGET_LINK_SYSTEM_LIBRARIES "${TARGET_LINK_SYSTEM_LIBRARIES} -lcr_semihost_mb" PARENT_SCOPE) 68 elseif(${DEBUG_CONSOLE} STREQUAL "SEMIHOST_MB_NF") 69 set(TARGET_LINK_SYSTEM_LIBRARIES "${TARGET_LINK_SYSTEM_LIBRARIES} -lcr_semihost_mb_nf" PARENT_SCOPE) 70 elseif(${DEBUG_CONSOLE} STREQUAL "UART" OR ${DEBUG_CONSOLE} STREQUAL "NOHOST_NF" OR ${DEBUG_CONSOLE} STREQUAL "NOHOST") 71 set(TARGET_LINK_SYSTEM_LIBRARIES "${TARGET_LINK_SYSTEM_LIBRARIES} -lcr_nohost_nf" PARENT_SCOPE) 72 endif() 73endif() 74endfunction() 75 76function(include_if_use module) 77 set(MATCHED false) 78 if(${CONFIG_USE_${module}}) 79 set(MATCHED true) 80 endif() 81 # In case that module file name has device/board/kit suffix 82 if(NOT MATCHED) 83 string(REGEX REPLACE ".${CONFIG_DEVICE}$" "" replVar ${module}) 84 if(${CONFIG_USE_${replVar}}) 85 set(MATCHED true) 86 endif() 87 endif() 88 if(NOT MATCHED) 89 string(REGEX REPLACE ".${CONFIG_BOARD}$" "" replVar ${module}) 90 if(${CONFIG_USE_${replVar}}) 91 set(MATCHED true) 92 endif() 93 endif() 94 if(NOT MATCHED) 95 string(REGEX REPLACE ".${CONFIG_KIT}$" "" replVar ${module}) 96 if(${CONFIG_USE_${replVar}}) 97 set(MATCHED true) 98 endif() 99 endif() 100 101 if(MATCHED) 102 include(${module} OPTIONAL RESULT_VARIABLE loaded_file) 103 if(EXISTS ${loaded_file}) 104 return() 105 else() 106 message(SEND_ERROR "${module}.cmake does not exist.") 107 endif() 108 endif() 109endfunction() 110 111function(add_config_file CONFIG_FILE INCLUDE_PATH MODULE_NAME) 112 get_target_property(PROJECT_SOURCES ${MCUX_SDK_PROJECT_NAME} SOURCES) 113 get_filename_component(BASE_NAME ${CONFIG_FILE} NAME) 114 115 foreach(PROJ_FILE ${PROJECT_SOURCES}) 116 string(FIND "${PROJ_FILE}" "${BASE_NAME}" CONFIG_FILE_INDEX) 117 if(${CONFIG_FILE_INDEX} GREATER -1) 118 get_source_file_property(CONFIG_FILE_PROPERTY "${PROJ_FILE}" COMPONENT_CONFIG_FILE) 119 if(${CONFIG_FILE_PROPERTY} MATCHES "(^${MODULE_NAME}$)|(^${MODULE_NAME} )|( ${MODULE_NAME} )|( ${MODULE_NAME}$)") 120 message("Skip ${CONFIG_FILE} in ${MODULE_NAME} because user-defined file ${PROJ_FILE} has been added into project.") 121 return() 122 endif() 123 endif() 124 endforeach() 125 126 message("Use ${CONFIG_FILE} in ${MODULE_NAME}.") 127 target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE ${CONFIG_FILE}) 128 if(NOT ${INCLUDE_PATH} STREQUAL "") 129 target_include_directories(${MCUX_SDK_PROJECT_NAME} PUBLIC ${INCLUDE_PATH}) 130 endif() 131endfunction()