[tools] cmake-clang compatible with bsp that does not support C++.
This commit is contained in:
parent
132ecaffb7
commit
d500f2dae6
|
@ -17,7 +17,10 @@ def GenerateCFiles(env,project):
|
|||
info = utils.ProjectInfo(env)
|
||||
|
||||
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('\\', "/")
|
||||
AR = os.path.join(rtconfig.EXEC_PATH, rtconfig.AR).replace('\\', "/")
|
||||
LINK = os.path.join(rtconfig.EXEC_PATH, rtconfig.LINK).replace('\\', "/")
|
||||
|
@ -28,9 +31,18 @@ def GenerateCFiles(env,project):
|
|||
elif rtconfig.CROSS_TOOL == 'keil':
|
||||
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:
|
||||
CC += ".exe"
|
||||
CXX += ".exe"
|
||||
if CXX != '':
|
||||
CXX += ".exe"
|
||||
AS += ".exe"
|
||||
AR += ".exe"
|
||||
LINK += ".exe"
|
||||
|
@ -41,7 +53,7 @@ def GenerateCFiles(env,project):
|
|||
elif rtconfig.CROSS_TOOL == 'keil':
|
||||
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'")
|
||||
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("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_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_C_COMPILER_WORKS TRUE)\n")
|
||||
cm_file.write("set(CMAKE_CXX_COMPILER_WORKS TRUE)\n\n")
|
||||
cm_file.write("SET(CMAKE_C_FLAGS \""+ CFLAGS + "\")\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':
|
||||
cm_file.write("SET(CMAKE_OBJCOPY \""+ OBJCOPY + "\")\n")
|
||||
cm_file.write("SET(CMAKE_SIZE \""+ SIZE + "\")\n\n")
|
||||
elif rtconfig.CROSS_TOOL == 'keil':
|
||||
cm_file.write("SET(CMAKE_FROMELF \""+ FROMELF + "\")\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")
|
||||
cm_file.write("SET(CMAKE_FROMELF \""+ FROMELF + "\")\n\n")
|
||||
|
||||
LINKER_FLAGS = ''
|
||||
LINKER_LIBS = ''
|
||||
|
@ -83,20 +96,22 @@ def GenerateCFiles(env,project):
|
|||
if 'LIBS' in group.keys():
|
||||
for f in group['LIBS']:
|
||||
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_CXX_STANDARD 14)\n")
|
||||
cm_file.write("PROJECT(rtthread C CXX ASM)\n")
|
||||
|
||||
cm_file.write("SET(CMAKE_EXE_LINKER_FLAGS \""+ re.sub(LINKER_FLAGS + '(\s*)', LINKER_FLAGS + ' ${CMAKE_SOURCE_DIR}/', LFLAGS) + LINKER_LIBS + "\")\n\n")
|
||||
|
||||
if CXX != '':
|
||||
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")
|
||||
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("ADD_DEFINITIONS(\n")
|
||||
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("SET(PROJECT_SOURCES\n")
|
||||
|
@ -104,7 +119,7 @@ def GenerateCFiles(env,project):
|
|||
for f in group['src']:
|
||||
cm_file.write( "\t" + os.path.normpath(f.rfile().abspath).replace("\\", "/") + "\n" )
|
||||
cm_file.write(")\n\n")
|
||||
|
||||
|
||||
if rtconfig.PLATFORM == 'gcc':
|
||||
cm_file.write("LINK_DIRECTORIES(\n")
|
||||
for group in project:
|
||||
|
|
Loading…
Reference in New Issue