RealEvo-IDE构建CMake工程
准备工作
- 下载zlib开源工程。
- 安装CMake。
- 安装RealEvo-IDE。
具体操作步骤如下所示。
创建RealEvo-IDE工程
- 打开RealEvo-IDE,新建SylixOS App工程,命名为zlib。RealEvo-IDE使用详见“快速上手 > IDE 使用”。
- base选择之前创建Zynq7000 Base,勾选"Custom Makefile configuration"选项。
- 单击 Finish 完成工程的新建。
手动修改工程
找到前面新建的zlib工程所属目录(可以在IDE左侧导航,右键单击工程,选择 Properties ,查看工程所属目录),并按照以下操作修改工程文件。
- 删除源码目录中src下的文件,并且将zlib源文件拷贝到该目录下。
- 删除
zlib.mk
文件,这里无法在IDE中右键删除,需要找到工程目录手动删除。 - 添加交叉编译文件sylixos.toolchain.cmake,位置如下图。
sylixos.toolchain.cmake
文件的具体内容如下。
#*********************************************************************************************************
#
# 中国软件开源组织
#
# 嵌入式实时操作系统
#
# SylixOS(TM) LW : long wing
#
# Copyright All Rights Reserved
#
#--------------文件信息--------------------------------------------------------------------------------
#
# 文 件 名: sylixos.toolchain.cmake
#
# 创 建 人: lijiaming(李佳明)
#
# 文件创建日期: 2022 年 06 月 03 日
#
# 描 述: SylixOS cmake toolchain file
#*********************************************************************************************************
set(CMAKE_SYSTEM_NAME SylixOS)
set(SYLIXOS ON)
set(ENV{SYLIXOS} ON)
#*********************************************************************************************************
# config.mk
#*********************************************************************************************************
if(CMAKE_SYLIXOS_BASE_PATH)
string(REPLACE "\\" "/" result "${CMAKE_SYLIXOS_BASE_PATH}")
set(CMAKE_SYLIXOS_BASE_PATH ${result})
set(ENV{SYLIXOS_BASE_PATH} "${CMAKE_SYLIXOS_BASE_PATH}")
else()
return()
endif()
set(SYLIXOS_BASE_PATH $ENV{SYLIXOS_BASE_PATH})
message(STATUS "SylixOS Base Path: ${SYLIXOS_BASE_PATH}")
if(NOT EXISTS ${SYLIXOS_BASE_PATH})
message(FATAL_ERROR "${SYLIXOS_BASE_PATH} not found.")
endif()
if(SYLIXOS_BASE_PATH)
file(STRINGS "${SYLIXOS_BASE_PATH}/config.mk" MK_STRINGS REGEX "^MULTI_PLATFORM_BUILD := .*")
string(REPLACE "MULTI_PLATFORM_BUILD := " "" MULTI_PLATFORM_BUILD "${MK_STRINGS}")
message(STATUS "MULTI_PLATFORM_BUILD := ${MULTI_PLATFORM_BUILD}")
if (MULTI_PLATFORM_BUILD STREQUAL "yes")
message(FATAL_ERROR "${SYLIXOS_BASE_PATH} is multi platform build. CMake not support.")
else ()
file(STRINGS "${SYLIXOS_BASE_PATH}/config.mk" MK_STRINGS REGEX "^TOOLCHAIN_PREFIX := .*")
string(REPLACE "TOOLCHAIN_PREFIX := " "" TOOLCHAIN_PREFIX "${MK_STRINGS}")
file(STRINGS "${SYLIXOS_BASE_PATH}/config.mk" MK_STRINGS REGEX "^FPU_TYPE := .*")
string(REPLACE "FPU_TYPE := " "" FPU_TYPE "${MK_STRINGS}")
file(STRINGS "${SYLIXOS_BASE_PATH}/config.mk" MK_STRINGS REGEX "^CPU_TYPE := .*")
string(REPLACE "CPU_TYPE := " "" CPU_TYPE "${MK_STRINGS}")
file(STRINGS "${SYLIXOS_BASE_PATH}/config.mk" MK_STRINGS REGEX "^DEBUG_LEVEL := .*")
string(REPLACE "DEBUG_LEVEL := " "" DEBUG_LEVEL "${MK_STRINGS}")
endif()
endif()
message(STATUS "TOOLCHAIN_PREFIX := ${TOOLCHAIN_PREFIX}")
message(STATUS "FPU_TYPE := ${FPU_TYPE}")
message(STATUS "CPU_TYPE := ${CPU_TYPE}")
#*********************************************************************************************************
# target.mk
#*********************************************************************************************************
set(LOCAL_INC_PATH "")
set(LOCAL_DSYMBOL "")
set(LOCAL_CFLAGS "")
set(LOCAL_CXXFLAGS "")
set(LOCAL_LINKFLAGS "")
set(LOCAL_DEPEND_LIB "")
set(LOCAL_DEPEND_LIB_PATH "")
set(LOCAL_USE_CXX "yes")
set(LOCAL_USE_CXX_EXCEPT "no")
set(LOCAL_USE_GCOV "no")
set(LOCAL_USE_OMP "no")
set(LOCAL_NO_UNDEF_SYM "no")
if(FPU_TYPE AND NOT(FPU_TYPE MATCHES "disable") AND NOT(FPU_TYPE MATCHES "default"))
if((FPU_TYPE MATCHES "hard-float") OR (FPU_TYPE MATCHES "soft-float") OR (FPU_TYPE MATCHES "double-float") OR (FPU_TYPE MATCHES "float-abi=soft") OR (FPU_TYPE MATCHES "float-abi=hard"))
set(ARCH_FPUFLAGS "-m${FPU_TYPE}")
elseif(FPU_TYPE MATCHES "softfp")
set(ARCH_FPUFLAGS "-mfloat-abi=softfp")
else()
set(ARCH_FPUFLAGS "-mfloat-abi=softfp -mfpu=${FPU_TYPE}")
endif()
endif()
#*********************************************************************************************************
# arch.mk
#*********************************************************************************************************
#*********************************************************************************************************
# i386
#*********************************************************************************************************
if(TOOLCHAIN_PREFIX STREQUAL i386-sylixos-elf-)
set(CMAKE_SYSTEM_PROCESSOR "x86")
set(ARCH_COMMONFLAGS "-mlong-double-64 -fno-omit-frame-pointer -fno-strict-aliasing")
set(ARCH_PIC_ASFLAGS "")
set(ARCH_PIC_CFLAGS "-fPIC")
set(ARCH_PIC_LDFLAGS "-Wl,-shared -fPIC -shared")
set(ARCH_KO_CFLAGS "")
set(ARCH_KO_LDFLAGS "-nostdlib -r")
set(ARCH_KLIB_CFLAGS "")
set(ARCH_KERNEL_CFLAGS "")
set(ARCH_KERNEL_LDFLAGS "")
set(ARCH_CPUFLAGS "-march=${CPU_TYPE} ${ARCH_FPUFLAGS}")
endif()
#*********************************************************************************************************
# x86-64
#*********************************************************************************************************
if(TOOLCHAIN_PREFIX STREQUAL x86_64-sylixos-elf-)
set(CMAKE_SYSTEM_PROCESSOR "x86_64")
set(ARCH_COMMONFLAGS "-mlong-double-64 -mno-red-zone -fno-omit-frame-pointer -fno-strict-aliasing")
set(ARCH_PIC_ASFLAGS "")
set(ARCH_PIC_CFLAGS "-fPIC")
set(ARCH_PIC_LDFLAGS "-Wl,-shared -fPIC -shared")
set(ARCH_KO_CFLAGS "-mcmodel=large")
set(ARCH_KO_LDFLAGS "-nostdlib -r")
set(ARCH_KLIB_CFLAGS "-mcmodel=large")
set(ARCH_KERNEL_CFLAGS "-mcmodel=kernel")
set(ARCH_KERNEL_LDFLAGS "-z max-page-size=4096")
if(CPU_TYPE AND NOT(FPU_TYPE MATCHES "generic"))
set(ARCH_CPUFLAGS "-march=${CPU_TYPE} -m64 ${ARCH_FPUFLAGS}")
else()
set(ARCH_CPUFLAGS "-m64 ${ARCH_FPUFLAGS}")
endif()
endif()
#*********************************************************************************************************
# ARM
#*********************************************************************************************************
if(TOOLCHAIN_PREFIX STREQUAL arm-sylixos-eabi-)
set(CMAKE_SYSTEM_PROCESSOR "arm")
set(ARCH_COMMONFLAGS "-mno-unaligned-access -fno-strict-aliasing")
set(ARCH_PIC_ASFLAGS "")
set(ARCH_PIC_CFLAGS "-fPIC")
set(ARCH_PIC_LDFLAGS "-nostdlib -Wl,-shared -fPIC -shared")
set(ARCH_KO_CFLAGS "")
set(ARCH_KO_LDFLAGS "-nostdlib -r")
set(ARCH_KLIB_CFLAGS "")
set(ARCH_KERNEL_CFLAGS "")
set(ARCH_KERNEL_LDFLAGS "")
set(ARCH_CPUFLAGS "-mcpu=${CPU_TYPE} ${ARCH_FPUFLAGS}")
endif()
#*********************************************************************************************************
# aarch64
#*********************************************************************************************************
if(TOOLCHAIN_PREFIX STREQUAL aarch64-sylixos-elf-)
set(CMAKE_SYSTEM_PROCESSOR "aarch64")
set(ARCH_COMMONFLAGS "-fno-omit-frame-pointer -mstrict-align -ffixed-x18 -fno-strict-aliasing")
set(ARCH_PIC_ASFLAGS "")
set(ARCH_PIC_CFLAGS "-fPIC")
set(ARCH_PIC_LDFLAGS "-Wl,-shared -fPIC -shared")
set(ARCH_KO_CFLAGS "-mcmodel=large -mgeneral-regs-only")
set(ARCH_KO_LDFLAGS "-nostdlib -r")
set(ARCH_KLIB_CFLAGS "")
set(ARCH_KERNEL_CFLAGS "-mgeneral-regs-only")
set(ARCH_KERNEL_LDFLAGS "-Wl,--build-id=none")
set(ARCH_CPUFLAGS "-mcpu=${CPU_TYPE} ${ARCH_FPUFLAGS}")
endif()
#*********************************************************************************************************
# MIPS
#*********************************************************************************************************
if(TOOLCHAIN_PREFIX STREQUAL mips-sylixos-elf-)
set(CMAKE_SYSTEM_PROCESSOR "mips")
set(ARCH_COMMONFLAGS "-fno-strict-aliasing")
set(ARCH_PIC_ASFLAGS "")
set(ARCH_PIC_CFLAGS "-fPIC -mabicalls")
set(ARCH_PIC_LDFLAGS "-mabicalls -Wl,-shared -fPIC -shared")
set(ARCH_KO_CFLAGS "-mlong-calls")
set(ARCH_KO_LDFLAGS "-nostdlib -r")
set(ARCH_KLIB_CFLAGS "-mlong-calls")
set(ARCH_KERNEL_CFLAGS "")
set(ARCH_KERNEL_LDFLAGS "")
set(ARCH_CPUFLAGS "-march=${CPU_TYPE} -EL -G 0 -mno-branch-likely ${ARCH_FPUFLAGS}")
endif()
#*********************************************************************************************************
# MIPS64
#*********************************************************************************************************
if(TOOLCHAIN_PREFIX STREQUAL mips64-sylixos-elf-)
set(CMAKE_SYSTEM_PROCESSOR "mips64")
set(ARCH_COMMONFLAGS "-fno-strict-aliasing")
set(ARCH_PIC_ASFLAGS "")
set(ARCH_PIC_CFLAGS "-fPIC -mabicalls")
set(ARCH_PIC_LDFLAGS "-mabicalls -Wl,-shared -fPIC -shared")
set(ARCH_KO_CFLAGS "-mlong-calls")
set(ARCH_KO_LDFLAGS "-nostdlib -r")
set(ARCH_KLIB_CFLAGS "-mlong-calls")
set(ARCH_KERNEL_CFLAGS "")
set(ARCH_KERNEL_LDFLAGS "")
set(ARCH_CPUFLAGS "-march=${CPU_TYPE} -EL -G 0 -mno-branch-likely -mabi=64 ${ARCH_FPUFLAGS}")
endif()
#*********************************************************************************************************
# PowerPC
#*********************************************************************************************************
if(TOOLCHAIN_PREFIX STREQUAL ppc-sylixos-eabi-)
set(CMAKE_SYSTEM_PROCESSOR "powerpc")
set(ARCH_COMMONFLAGS "-G 0 -mstrict-align -fno-strict-aliasing")
set(ARCH_PIC_ASFLAGS "")
set(ARCH_PIC_CFLAGS "-fPIC")
set(ARCH_PIC_LDFLAGS "-Wl,-shared -fPIC -shared")
set(ARCH_KO_CFLAGS "")
set(ARCH_KO_LDFLAGS "-nostdlib -r")
set(ARCH_KLIB_CFLAGS "")
set(ARCH_KERNEL_CFLAGS "")
set(ARCH_KERNEL_LDFLAGS "")
set(ARCH_CPUFLAGS "-mcpu=${CPU_TYPE} ${ARCH_FPUFLAGS}")
endif()
#*********************************************************************************************************
# SPARC
#*********************************************************************************************************
if(TOOLCHAIN_PREFIX STREQUAL sparc-sylixos-elf-)
set(CMAKE_SYSTEM_PROCESSOR "sparc")
set(ARCH_COMMONFLAGS "-fno-strict-aliasing")
set(ARCH_PIC_ASFLAGS "")
set(ARCH_PIC_CFLAGS "-fPIC")
set(ARCH_PIC_LDFLAGS "-Wl,-shared -fPIC -shared")
set(ARCH_KO_CFLAGS "")
set(ARCH_KO_LDFLAGS "-nostdlib -r")
set(ARCH_KLIB_CFLAGS "")
set(ARCH_KERNEL_CFLAGS "")
set(ARCH_KERNEL_LDFLAGS "")
set(ARCH_CPUFLAGS "-mcpu=${CPU_TYPE} ${ARCH_FPUFLAGS}")
endif()
#*********************************************************************************************************
# RISC-V
#*********************************************************************************************************
if(TOOLCHAIN_PREFIX STREQUAL riscv-sylixos-elf-)
set(CMAKE_SYSTEM_PROCESSOR "riscv")
set(ARCH_COMMONFLAGS "-mstrict-align -mcmodel=medany -mno-save-restore -fno-strict-aliasing")
set(ARCH_PIC_ASFLAGS "")
set(ARCH_PIC_CFLAGS "-fPIC")
set(ARCH_PIC_LDFLAGS "-Wl,-shared -fPIC -shared")
set(ARCH_KO_CFLAGS "-fPIC")
set(ARCH_KO_LDFLAGS "-r -fPIC")
set(ARCH_KLIB_CFLAGS "")
set(ARCH_KERNEL_CFLAGS "")
set(ARCH_KERNEL_LDFLAGS "")
set(ARCH_CPUFLAGS "-march=${CPU_TYPE} -mabi=${FPU_TYPE}")
endif()
#*********************************************************************************************************
# C-SKY
#*********************************************************************************************************
if(TOOLCHAIN_PREFIX STREQUAL csky-sylixos-elfabiv2-)
set(CMAKE_SYSTEM_PROCESSOR "csky")
set(ARCH_COMMONFLAGS "-fno-omit-frame-pointer -fno-strict-aliasing")
set(ARCH_PIC_ASFLAGS "")
set(ARCH_PIC_CFLAGS "-fPIC")
set(ARCH_PIC_LDFLAGS "-Wl,-shared -fPIC -Wl,-z,max-page-size=65536")
set(ARCH_KO_CFLAGS "-Wa,-mno-force2bsr")
set(ARCH_KO_LDFLAGS "-nostdlib -r -Wl,-z,max-page-size=65536")
set(ARCH_KLIB_CFLAGS "-Wa,-mno-force2bsr")
set(ARCH_KERNEL_CFLAGS "")
set(ARCH_KERNEL_LDFLAGS "-Wl,-z,max-page-size=65536")
set(ARCH_CPUFLAGS "-march=${CPU_TYPE} ${ARCH_FPUFLAGS}")
endif()
#*********************************************************************************************************
# LoongARCH64
#*********************************************************************************************************
if(TOOLCHAIN_PREFIX STREQUAL loongarch64-sylixos-elf-)
set(CMAKE_SYSTEM_PROCESSOR "loongarch64")
set(ARCH_COMMONFLAGS "-mstrict-align")
set(ARCH_PIC_ASFLAGS "")
set(ARCH_PIC_CFLAGS "-fPIC")
set(ARCH_PIC_LDFLAGS "-Wl,-shared -fPIC -shared -Wl,-z,max-page-size=65536")
set(ARCH_KO_CFLAGS "-Wa,-mla-global-with-abs,-mla-local-with-abs")
set(ARCH_KO_LDFLAGS "-nostdlib -r -Wl,-z,max-page-size=65536")
set(ARCH_KLIB_CFLAGS "")
set(ARCH_KERNEL_CFLAGS "-Wa,-mla-global-with-pcrel")
set(ARCH_KERNEL_LDFLAGS "-Wl,-z,max-page-size=65536")
set(ARCH_CPUFLAGS "-march=${CPU_TYPE} -G 0 -mabi=lp64d ${ARCH_FPUFLAGS}")
endif()
#*********************************************************************************************************
# gcc.mk
#*********************************************************************************************************
#*********************************************************************************************************
# specify cross compilers and tools
#*********************************************************************************************************
set(CMAKE_C_COMPILER_WORKS 1)
set(CMAKE_CXX_COMPILER_WORKS 1)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc CACHE PATH "SylixOS Base Path")
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++ CACHE PATH "SylixOS Base Path")
set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PREFIX}gcc CACHE PATH "SylixOS Base Path")
set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}g++ CACHE PATH "SylixOS Base Path")
set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy CACHE PATH "SylixOS Base Path")
set(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}objdump CACHE PATH "SylixOS Base Path")
set(CMAKE_AR ${TOOLCHAIN_PREFIX}ar CACHE PATH "SylixOS Base Path")
set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size CACHE PATH "SylixOS Base Path")
set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}ranlib CACHE PATH "SylixOS Base Path")
#*********************************************************************************************************
# Compiler optimize flag
#*********************************************************************************************************
set(TOOLCHAIN_OPTIMIZE_DEBUG "-O0 -g3 -gdwarf-2")
set(TOOLCHAIN_OPTIMIZE_RELEASE "-O2 -g3 -gdwarf-2")
#*********************************************************************************************************
# Toolchain flag
#*********************************************************************************************************
set(TOOLCHAIN_CXX_CFLAGS "")
set(TOOLCHAIN_CXX_EXCEPT_CFLAGS "${TOOLCHAIN_CXX_CFLAGS} -fexceptions -frtti")
set(TOOLCHAIN_NO_CXX_EXCEPT_CFLAGS "${TOOLCHAIN_CXX_CFLAGS} -fno-exceptions -fno-rtti")
set(TOOLCHAIN_GCOV_CFLAGS "-fprofile-arcs -ftest-coverage")
set(TOOLCHAIN_OMP_FLAGS "-fopenmp")
set(TOOLCHAIN_COMMONFLAGS "-Wall -fmessage-length=0 -fsigned-char -fno-short-enums")
set(TOOLCHAIN_ASFLAGS "-x assembler-with-cpp")
set(TOOLCHAIN_NO_UNDEF_SYM_FLAGS "@${SYLIXOS_BASE_PATH}/libsylixos/${CMAKE_BUILD_TYPE}/symbol.ld")
set(TOOLCHAIN_AR_FLAGS "-r")
set(TOOLCHAIN_STRIP_FLAGS "")
set(TOOLCHAIN_STRIP_KO_FLAGS "--strip-unneeded")
#*********************************************************************************************************
# Application.mk
#*********************************************************************************************************
#*********************************************************************************************************
# Include paths
#*********************************************************************************************************
set(TARGET_INC_PATH "${LOCAL_INC_PATH} -I${SYLIXOS_BASE_PATH}/libsylixos/SylixOS -I${SYLIXOS_BASE_PATH}/libsylixos/SylixOS/include -I${SYLIXOS_BASE_PATH}/libsylixos/SylixOS/include/network")
#*********************************************************************************************************
# Compiler preprocess
#*********************************************************************************************************
set(TARGET_DSYMBOL "-DSYLIXOS ${LOCAL_DSYMBOL}")
#*********************************************************************************************************
# Compiler flags
#*********************************************************************************************************
set(TARGET_CFLAGS "${LOCAL_CFLAGS}")
set(TARGET_CXXFLAGS "${LOCAL_CXXFLAGS}")
set(TARGET_LINKFLAGS "${SYLIXOS_BASE_PATH}/libsylixos/Release;${SYLIXOS_BASE_PATH}/libsylixos/Debug;${SYLIXOS_BASE_PATH}/libcextern/Release;${SYLIXOS_BASE_PATH}/libcextern/Debug")
if(LOCAL_USE_CXX STREQUAL yes)
set(TARGET_LIBRARIES "cextern;vpmpdm;stdc++;dsohandle;m;gcc")
else()
set(TARGET_LIBRARIES "cextern;vpmpdm;m;gcc")
endif()
#*********************************************************************************************************
# Depend and compiler parameter (cplusplus in kernel MUST NOT use exceptions and rtti)
#*********************************************************************************************************
if(LOCAL_USE_GCOV STREQUAL yes)
set(TARGET_GCOV_FLAGS "${TOOLCHAIN_GCOV_CFLAGS}")
else()
set(TARGET_GCOV_FLAGS "")
endif()
if(LOCAL_USE_OMP STREQUAL yes)
set(TARGET_OMP_FLAGS "${TOOLCHAIN_OMP_FLAGS}")
else()
set(TARGET_OMP_FLAGS "")
endif()
if(LOCAL_NO_UNDEF_SYM STREQUAL yes)
set(TARGET_NO_UNDEF_SYM_FLAGS "${TOOLCHAIN_NO_UNDEF_SYM_FLAGS}")
else()
set(TARGET_NO_UNDEF_SYM_FLAGS "")
endif()
if(LOCAL_USE_CXX_EXCEPT STREQUAL yes)
set(TARGET_CXX_EXCEPT ${TOOLCHAIN_CXX_EXCEPT_CFLAGS})
else()
set(TARGET_CXX_EXCEPT ${TOOLCHAIN_NO_CXX_EXCEPT_CFLAGS})
endif()
set(TARGET_CPUFLAGS "${ARCH_CPUFLAGS}")
set(TARGET_COMMONFLAGS "${TARGET_CPUFLAGS} ${ARCH_COMMONFLAGS} ${TOOLCHAIN_COMMONFLAGS} ${TARGET_GCOV_FLAGS} ${TARGET_OMP_FLAGS}")
set(CMAKE_THREAD_LIBS_INIT "")
set(CMAKE_DL_LIBS "")
set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP ":")
set(CMAKE_SHARED_LIBRARY_RPATH_ORIGIN_TOKEN "\$ORIGIN")
set(CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG "-Wl,-rpath-link,")
set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-soname,")
set(CMAKE_EXE_EXPORTS_C_FLAG "-Wl,--export-dynamic")
set(CMAKE_ASM_FLAGS "${TARGET_INC_PATH} ${TARGET_COMMONFLAGS} ${ARCH_PIC_ASFLAGS} ${TOOLCHAIN_ASFLAGS} ${TARGET_DSYMBOL}" CACHE INTERNAL "ASM Compiler options")
set(CMAKE_C_FLAGS "${TARGET_INC_PATH} ${TARGET_COMMONFLAGS} ${ARCH_PIC_CFLAGS} ${TARGET_DSYMBOL} ${TARGET_CFLAGS}" CACHE INTERNAL "C Compiler options")
set(CMAKE_CXX_FLAGS "${TARGET_INC_PATH} ${TARGET_COMMONFLAGS} ${ARCH_PIC_CFLAGS} ${TARGET_DSYMBOL} ${TARGET_CXX_EXCEPT} ${TARGET_CXXFLAGS}" CACHE INTERNAL "C++ Compiler options")
set(CMAKE_EXE_LINKER_FLAGS "${ARCH_PIC_LDFLAGS} ${TARGET_NO_UNDEF_SYM_FLAGS} " CACHE INTERNAL "Linker options")
set(CMAKE_SHARED_LINKER_FLAGS "${ARCH_PIC_LDFLAGS} " CACHE INTERNAL "Shared library Linker options")
set(CMAKE_MODULE_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS})
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(CMAKE_C_FLAGS_DEBUG "${TOOLCHAIN_OPTIMIZE_DEBUG}")
set(CMAKE_C_FLAGS_RELEASE "${TOOLCHAIN_OPTIMIZE_RELEASE}")
set(CMAKE_C_FLAGS_MINSIZEREL "")
set(CMAKE_C_FLAGS_RELEWITHDEBINFO "")
set(CMAKE_CXX_FLAGS_DEBUG "${TOOLCHAIN_OPTIMIZE_DEBUG}")
set(CMAKE_CXX_FLAGS_RELEASE "${TOOLCHAIN_OPTIMIZE_RELEASE}")
set(CMAKE_CXX_FLAGS_MINSIZEREL "")
set(CMAKE_CXX_FLAGS_RELEWITHDEBINFO "")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${TOOLCHAIN_OPTIMIZE_DEBUG}")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${TOOLCHAIN_OPTIMIZE_RELEASE}")
set(CMAKE_EXE_LINKER_MINSIZEREL "")
set(CMAKE_EXE_LINKER_RELEWITHDEBINFO "")
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${TOOLCHAIN_OPTIMIZE_DEBUG}")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${TOOLCHAIN_OPTIMIZE_RELEASE}")
set(CMAKE_SHARED_LINKER_MINSIZEREL "")
set(CMAKE_SHARED_LINKER_RELEWITHDEBINFO "")
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${TOOLCHAIN_OPTIMIZE_DEBUG}")
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${TOOLCHAIN_OPTIMIZE_RELEASE}")
set(CMAKE_MODULE_LINKER_MINSIZEREL "")
set(CMAKE_MODULE_LINKER_RELEWITHDEBINFO "")
link_directories(${TARGET_LINKFLAGS})
link_libraries(${TARGET_LIBRARIES})
#*********************************************************************************************************
# End
#*********************************************************************************************************
修改Makefile文件
注意:
如果直接拷贝内容使用,需要注意将86、103、110、111 四行前面的空格修改为Tab。不然会导致编译报错和不能识别命令。如果 zlib的版本发生变化,需要将修改87行zlib为对应版本。
#*********************************************************************************************************
#
# 中国软件开源组织
#
# 嵌入式实时操作系统
#
# SylixOS(TM) LW : long wing
#
# Copyright All Rights Reserved
#
#--------------文件信息--------------------------------------------------------------------------------
#
# 文 件 名: Makefile
#
# 创 建 人: RealEvo-IDE
#
# 文件创建日期: 2023 年 07 月 28 日
#
# 描 述: 本文件由 RealEvo-IDE 生成,用于配置 Makefile 功能,请勿手动修改
#*********************************************************************************************************
#*********************************************************************************************************
# Top directory path
#*********************************************************************************************************
TOPDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
#*********************************************************************************************************
# Include config.mk
#*********************************************************************************************************
CONFIG_MK_EXIST = $(shell if [ -f ../config.mk ]; then echo exist; else echo notexist; fi;)
ifeq ($(CONFIG_MK_EXIST), exist)
include ../config.mk
else
CONFIG_MK_EXIST = $(shell if [ -f config.mk ]; then echo exist; else echo notexist; fi;)
ifeq ($(CONFIG_MK_EXIST), exist)
include config.mk
else
CONFIG_MK_EXIST =
endif
endif
#*********************************************************************************************************
# Include sylixos base config.mk
#*********************************************************************************************************
EMPTY =
SPACE = $(EMPTY) $(EMPTY)
SYLIXOS_BASE_PATH_BAK := $(SYLIXOS_BASE_PATH)
TOOLCHAIN_PREFIX_BAK := $(TOOLCHAIN_PREFIX)
DEBUG_LEVEL_BAK := $(DEBUG_LEVEL)
CPU_TYPE_BAK := $(CPU_TYPE)
FPU_TYPE_BAK := $(FPU_TYPE)
SYLIXOS_BASE_CONFIGMK = $(subst $(SPACE),\ ,$(SYLIXOS_BASE_PATH))/config.mk
include $(SYLIXOS_BASE_CONFIGMK)
SYLIXOS_BASE_PATH := $(SYLIXOS_BASE_PATH_BAK)
DEBUG_LEVEL := $(DEBUG_LEVEL_BAK)
ifneq ($(TOOLCHAIN_PREFIX_BAK),)
TOOLCHAIN_PREFIX := $(TOOLCHAIN_PREFIX_BAK)
endif
ifneq ($(CPU_TYPE_BAK),)
CPU_TYPE := $(CPU_TYPE_BAK)
endif
ifneq ($(FPU_TYPE_BAK),)
FPU_TYPE := $(FPU_TYPE_BAK)
endif
#*********************************************************************************************************
# INSTALL
#*********************************************************************************************************
ifeq ($(DEBUG_LEVEL),release)
PREFIX_INSTALL := Release
else
PREFIX_INSTALL := Debug
endif
#*********************************************************************************************************
# zlib
#*********************************************************************************************************
.PHONY: zlib
zlib:
cmake -Wno-dev -G "MinGW Makefiles" \
-S $(TOPDIR)src/zlib-1.2.13 \
-B $(TOPDIR)build \
-DCMAKE_MAKE_PROGRAM="make" \
-DCMAKE_COLOR_MAKEFILE=OFF \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DCMAKE_BUILD_TYPE=$(DEBUG_LEVEL) \
-DCMAKE_SYLIXOS_BASE_PATH="$(SYLIXOS_BASE_PATH)" \
-DCMAKE_INSTALL_PREFIX="$(TOPDIR)$(PREFIX_INSTALL)" \
-DCMAKE_TOOLCHAIN_FILE="$(TOPDIR)sylixos.toolchain.cmake";
if [ -f $(TOPDIR)build/Makefile ]; then cd $(TOPDIR)build; make && make install/strip; cd $(TOPDIR); else echo CMake failed; fi;
#*********************************************************************************************************
# all
#*********************************************************************************************************
.PHONY: all
all: zlib
@echo "Build done!"
#*********************************************************************************************************
# clean
#*********************************************************************************************************
.PHONY: clean
clean:
rm -rf build; rm -rf $(PREFIX_INSTALL)
@echo "Clean done!"
#*********************************************************************************************************
# End
#*********************************************************************************************************
编译工程
工程文件修改完毕后,在IDE中,右键zlib工程,选择 Refresh ,刷新工程。然后右键工程,并选择 Build Project ,即可开始构建编译工程。并可以查看到打印的构建编译信息。
工程构建成功后,可在Release或Debug目录下看到编译后的SDK包。
至此,使用msys2编译软件的所有步骤皆已完成。