[tools] cmake-clang compatible with bsp that does not support C++.

This commit is contained in:
guozhanxin 2021-07-01 08:13:57 +08:00
parent 132ecaffb7
commit d500f2dae6
1 changed files with 36 additions and 21 deletions

View File

@ -17,7 +17,10 @@ def GenerateCFiles(env,project):
info = utils.ProjectInfo(env) info = utils.ProjectInfo(env)
CC = os.path.join(rtconfig.EXEC_PATH, rtconfig.CC).replace('\\', "/") CC = os.path.join(rtconfig.EXEC_PATH, rtconfig.CC).replace('\\', "/")
CXX = os.path.join(rtconfig.EXEC_PATH, rtconfig.CXX).replace('\\', "/") if 'CXX' in dir(rtconfig):
CXX = os.path.join(rtconfig.EXEC_PATH, rtconfig.CXX).replace('\\', "/")
else:
CXX = ''
AS = os.path.join(rtconfig.EXEC_PATH, rtconfig.AS).replace('\\', "/") AS = os.path.join(rtconfig.EXEC_PATH, rtconfig.AS).replace('\\', "/")
AR = os.path.join(rtconfig.EXEC_PATH, rtconfig.AR).replace('\\', "/") AR = os.path.join(rtconfig.EXEC_PATH, rtconfig.AR).replace('\\', "/")
LINK = os.path.join(rtconfig.EXEC_PATH, rtconfig.LINK).replace('\\', "/") LINK = os.path.join(rtconfig.EXEC_PATH, rtconfig.LINK).replace('\\', "/")
@ -28,9 +31,18 @@ def GenerateCFiles(env,project):
elif rtconfig.CROSS_TOOL == 'keil': elif rtconfig.CROSS_TOOL == 'keil':
FROMELF = os.path.join(rtconfig.EXEC_PATH, 'fromelf').replace('\\', "/") FROMELF = os.path.join(rtconfig.EXEC_PATH, 'fromelf').replace('\\', "/")
CFLAGS = rtconfig.CFLAGS.replace('\\', "/").replace('\"', "\\\"")
if 'CXXFLAGS' in dir(rtconfig):
CXXFLAGS = rtconfig.CXXFLAGS.replace('\\', "/").replace('\"', "\\\"")
else:
CXXFLAGS = CFLAGS
AFLAGS = rtconfig.AFLAGS.replace('\\', "/").replace('\"', "\\\"")
LFLAGS = rtconfig.LFLAGS.replace('\\', "/").replace('\"', "\\\"")
if "win32" in sys.platform: if "win32" in sys.platform:
CC += ".exe" CC += ".exe"
CXX += ".exe" if CXX != '':
CXX += ".exe"
AS += ".exe" AS += ".exe"
AR += ".exe" AR += ".exe"
LINK += ".exe" LINK += ".exe"
@ -41,7 +53,7 @@ def GenerateCFiles(env,project):
elif rtconfig.CROSS_TOOL == 'keil': elif rtconfig.CROSS_TOOL == 'keil':
FROMELF += ".exe" FROMELF += ".exe"
if not os.path.exists(CC) or not os.path.exists(CXX) or not os.path.exists(AS) or not os.path.exists(AR) or not os.path.exists(LINK): if not os.path.exists(CC) or not os.path.exists(AS) or not os.path.exists(AR) or not os.path.exists(LINK):
print("'Cannot found toolchain directory, please check RTT_CC and RTT_EXEC_PATH'") print("'Cannot found toolchain directory, please check RTT_CC and RTT_EXEC_PATH'")
sys.exit(-1) sys.exit(-1)
@ -50,24 +62,25 @@ def GenerateCFiles(env,project):
cm_file.write("CMAKE_MINIMUM_REQUIRED(VERSION 3.10)\n\n") cm_file.write("CMAKE_MINIMUM_REQUIRED(VERSION 3.10)\n\n")
cm_file.write("SET(CMAKE_SYSTEM_NAME Generic)\n") cm_file.write("SET(CMAKE_SYSTEM_NAME Generic)\n")
cm_file.write("set(CMAKE_SYSTEM_PROCESSOR " + rtconfig.CPU +")\n") cm_file.write("SET(CMAKE_SYSTEM_PROCESSOR " + rtconfig.CPU +")\n")
cm_file.write("#SET(CMAKE_VERBOSE_MAKEFILE ON)\n\n") cm_file.write("#SET(CMAKE_VERBOSE_MAKEFILE ON)\n\n")
cm_file.write("SET(CMAKE_C_COMPILER \""+ CC + "\")\n") cm_file.write("SET(CMAKE_C_COMPILER \""+ CC + "\")\n")
cm_file.write("SET(CMAKE_CXX_COMPILER \""+ CXX + "\")\n")
cm_file.write("SET(CMAKE_ASM_COMPILER \""+ AS + "\")\n") cm_file.write("SET(CMAKE_ASM_COMPILER \""+ AS + "\")\n")
cm_file.write("set(CMAKE_C_COMPILER_WORKS TRUE)\n") cm_file.write("SET(CMAKE_C_FLAGS \""+ CFLAGS + "\")\n")
cm_file.write("set(CMAKE_CXX_COMPILER_WORKS TRUE)\n\n") cm_file.write("SET(CMAKE_ASM_FLAGS \""+ AFLAGS + "\")\n")
cm_file.write("SET(CMAKE_C_COMPILER_WORKS TRUE)\n\n")
if CXX != '':
cm_file.write("SET(CMAKE_CXX_COMPILER \""+ CXX + "\")\n")
cm_file.write("SET(CMAKE_CXX_FLAGS \""+ CXXFLAGS + "\")\n")
cm_file.write("SET(CMAKE_CXX_COMPILER_WORKS TRUE)\n\n")
if rtconfig.PLATFORM == 'gcc': if rtconfig.PLATFORM == 'gcc':
cm_file.write("SET(CMAKE_OBJCOPY \""+ OBJCOPY + "\")\n") cm_file.write("SET(CMAKE_OBJCOPY \""+ OBJCOPY + "\")\n")
cm_file.write("SET(CMAKE_SIZE \""+ SIZE + "\")\n\n") cm_file.write("SET(CMAKE_SIZE \""+ SIZE + "\")\n\n")
elif rtconfig.CROSS_TOOL == 'keil': elif rtconfig.CROSS_TOOL == 'keil':
cm_file.write("SET(CMAKE_FROMELF \""+ FROMELF + "\")\n") cm_file.write("SET(CMAKE_FROMELF \""+ FROMELF + "\")\n\n")
cm_file.write("SET(CMAKE_C_FLAGS \""+ rtconfig.CFLAGS.replace('\\', "/").replace('\"', "\\\"") + "\")\n")
cm_file.write("SET(CMAKE_CXX_FLAGS \""+ rtconfig.CXXFLAGS.replace('\\', "/").replace('\"', "\\\"") + "\")\n")
cm_file.write("SET(CMAKE_ASM_FLAGS \""+ rtconfig.AFLAGS.replace('\\', "/").replace('\"', "\\\"") + "\")\n")
LINKER_FLAGS = '' LINKER_FLAGS = ''
LINKER_LIBS = '' LINKER_LIBS = ''
@ -83,20 +96,22 @@ def GenerateCFiles(env,project):
if 'LIBS' in group.keys(): if 'LIBS' in group.keys():
for f in group['LIBS']: for f in group['LIBS']:
LINKER_LIBS += ' ' + f.replace("\\", "/") + '.lib' LINKER_LIBS += ' ' + f.replace("\\", "/") + '.lib'
cm_file.write("SET(CMAKE_EXE_LINKER_FLAGS \""+ re.sub(LINKER_FLAGS + '(\s*)', LINKER_FLAGS + ' ${CMAKE_SOURCE_DIR}/',rtconfig.LFLAGS.replace('\\', "/").replace('\"', "\\\"")) + LINKER_LIBS + "\")\n\n") cm_file.write("SET(CMAKE_EXE_LINKER_FLAGS \""+ re.sub(LINKER_FLAGS + '(\s*)', LINKER_FLAGS + ' ${CMAKE_SOURCE_DIR}/', LFLAGS) + LINKER_LIBS + "\")\n\n")
cm_file.write("SET(CMAKE_CXX_STANDARD 14)\n") if CXX != '':
cm_file.write("PROJECT(rtthread C CXX ASM)\n") cm_file.write("SET(CMAKE_CXX_STANDARD 14)\n")
cm_file.write("PROJECT(rtthread C CXX ASM)\n")
else:
cm_file.write("PROJECT(rtthread C ASM)\n")
cm_file.write("INCLUDE_DIRECTORIES(\n") cm_file.write("INCLUDE_DIRECTORIES(\n")
for i in info['CPPPATH']: for i in info['CPPPATH']:
cm_file.write( "\t" + i.replace("\\", "/") + "\n") cm_file.write( "\t" + i.replace("\\", "/") + "\n")
cm_file.write(")\n\n") cm_file.write(")\n\n")
cm_file.write("ADD_DEFINITIONS(\n") cm_file.write("ADD_DEFINITIONS(\n")
for i in info['CPPDEFINES']: for i in info['CPPDEFINES']:
cm_file.write("\t-D" + i + "\n") cm_file.write("\t-D" + i + "\n")
cm_file.write(")\n\n") cm_file.write(")\n\n")
cm_file.write("SET(PROJECT_SOURCES\n") cm_file.write("SET(PROJECT_SOURCES\n")
@ -104,7 +119,7 @@ def GenerateCFiles(env,project):
for f in group['src']: for f in group['src']:
cm_file.write( "\t" + os.path.normpath(f.rfile().abspath).replace("\\", "/") + "\n" ) cm_file.write( "\t" + os.path.normpath(f.rfile().abspath).replace("\\", "/") + "\n" )
cm_file.write(")\n\n") cm_file.write(")\n\n")
if rtconfig.PLATFORM == 'gcc': if rtconfig.PLATFORM == 'gcc':
cm_file.write("LINK_DIRECTORIES(\n") cm_file.write("LINK_DIRECTORIES(\n")
for group in project: for group in project: