1################交叉编译##################### 2#cross-compilation config 3set(CMAKE_SYSTEM_NAME Linux) 4set(CMAKE_SYSTEM_PROCESSOR arm) 5 6set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 7set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 8set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 9set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 10 11 12set(CPU_TYPE "$ENV{CPU_TYPE}" ) 13set(PLAM_TYPE "$ENV{PLAM_TYPE}" ) 14set(LIB_TYPE "$ENV{LIB_TYPE}" ) 15set(SYSTEM "$ENV{SYSTEM}" ) 16set(CORE "$ENV{CORE}" ) 17set(LIB_RUN_TYPE "$ENV{LIB_RUN_TYPE}" ) 18set(BUILD_DIR "$ENV{BUILD_TMP_DIR}" ) #version id 19set(OBJCOPY_PATH "$ENV{OBJCOPY_PATH}" ) #OBJCOPY_PATH 20set(COMPILE_MODE "$ENV{COMPILE_MODE}" ) 21set(CC_TYPE "$ENV{CC_TYPE}" ) 22set(TOOLCHAIN_DIR "$ENV{HCC_PATH}") #该路径应该是外部传入,指向编译工具路径 23 24##compiler specified in /etc/profile 25set(CMAKE_C_COMPILER "${TOOLCHAIN_DIR}/arm-none-eabi-gcc" CACHE PATH "arm-gcc C compiler" FORCE) 26set(CMAKE_ASM_COMPILER "${TOOLCHAIN_DIR}/arm-none-eabi-gcc" CACHE PATH "arm-gcc ASM compiler" FORCE) 27 28if(${CPU_TYPE} STREQUAL "m4") 29 set(CMAKE_ASM_FLAGS "--specs=nosys.specs") 30 set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> -O2 -pipe ${STRONG_COMPILE_WARING_FLAG} ${COMPILE_WARING_FLAG} -std=gnu11 -fno-common -fomit-frame-pointer -mthumb -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -Wa,-mimplicit-it=thumb -fstack-protector-strong -funsigned-char <FLAGS> <INCLUDES> -c <SOURCE> -o <OBJECT>") 31 set(CMAKE_C_FLAGS "--specs=nosys.specs") #原ID形式\"888888\" 32 set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> -O2 -pipe ${STRONG_COMPILE_WARING_FLAG} ${COMPILE_WARING_FLAG} -std=gnu11 -fno-common -fomit-frame-pointer -mcpu=cortex-m4 -mthumb -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -fstack-protector-strong -fdata-sections -ffunction-sections -fshort-enums -funsigned-char -DSECUREC_BUFFER_SIZE=32 <FLAGS> <INCLUDES> -c <SOURCE> -o <OBJECT>") 33endif() 34 35 36set(CMAKE_LINKER "${TOOLCHAIN_DIR}/arm-none-eabi-ld" CACHE STRING "" FORCE) 37set(CMAKE_AR "${TOOLCHAIN_DIR}/arm-none-eabi-ar" CACHE STRING "" FORCE) 38set(CMAKE_C_LINK_FLAGS "-r ") 39set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> -r <TARGET> <OBJECTS>") 40