-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Clang compatibility] Added Clang CMake definitions. #76
Open
Johnn333
wants to merge
4
commits into
lancaster-university:master
Choose a base branch
from
Johnn333:clang-compatibility
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c2067bf
Add Clang CMake definitions
Johnn333 94eaee8
Merge branch 'lancaster-university:master' into clang-compatibility
Johnn333 ea3a11c
Documentation for users interested in using Clang to build.
Johnn333 e55ab79
Merge branch 'lancaster-university:master' into clang-compatibility
Johnn333 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
add_custom_command( | ||
OUTPUT "${PROJECT_SOURCE_DIR}/${codal.output_folder}/${device.device}.bin" | ||
COMMAND "${LLVM_OBJCOPY}" -O binary "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${device.device}" "${PROJECT_SOURCE_DIR}/${codal.output_folder}/${device.device}.bin" | ||
DEPENDS ${device.device} | ||
COMMENT "converting to bin file." | ||
) | ||
|
||
#specify a dependency on the elf file so that bin is automatically rebuilt when elf is changed. | ||
add_custom_target(${device.device}_bin ALL DEPENDS "${PROJECT_SOURCE_DIR}/${codal.output_folder}/${device.device}.bin") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# See toolchain.cmake before modifying this. | ||
|
||
# This file is a copy from ../ARM_GCC, building with Clang/LLVM however will not immediatly work, | ||
# some flags are not accepted by both compilers (e.g -Wl,--no-wchar-size-warning, defined in target.json), handle conflicts, | ||
# and Clang will require the --target=arm-none-eabi flag. We also need Clang to include extra header files: | ||
# "-I/lib/arm-none-eabi/include -I/etc/alternatives/gcc-arm-none-eabi-include -I/usr/include/newlib/c++/10.3.1 -I/usr/include/newlib/c++/10.3.1/arm-none-eabi" | ||
# Note: The version of newlib may have changed. These changes *should* allow you too build upto the final link. | ||
|
||
# The arm-embedded linker is auto configured, and specifically searches for corresponding libraries/startup files, given | ||
# the architecture on the command line, Clang does not do this and as such linking is a much more difficult step, it remains easiest | ||
# to run the arm-embedded linker, view its command using "$ python(3) build.py -v", further verbose this command, copy it and invoke lld directly. | ||
|
||
# This file hasn't been changed to reflect any of this, modifying target.json is likely the easier route. | ||
# Note: The above build process assumes that arm-embedded is already installed, which brings in all of the dependencies. | ||
|
||
set(EXPLICIT_INCLUDES "") | ||
if((CMAKE_VERSION VERSION_GREATER "3.4.0") OR (CMAKE_VERSION VERSION_EQUAL "3.4.0")) | ||
# from CMake 3.4 <INCLUDES> are separate to <FLAGS> in the | ||
# CMAKE_<LANG>_COMPILE_OBJECT, CMAKE_<LANG>_CREATE_ASSEMBLY_SOURCE, and | ||
# CMAKE_<LANG>_CREATE_PREPROCESSED_SOURCE commands | ||
set(EXPLICIT_INCLUDES "<INCLUDES> ") | ||
endif() | ||
|
||
# Override the link rules: | ||
set(CMAKE_C_CREATE_SHARED_LIBRARY "echo 'shared libraries not supported' && 1") | ||
set(CMAKE_C_CREATE_SHARED_MODULE "echo 'shared modules not supported' && 1") | ||
set(CMAKE_C_CREATE_STATIC_LIBRARY "<CMAKE_AR> -cr <LINK_FLAGS> <TARGET> <OBJECTS>") | ||
set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> ${EXPLICIT_INCLUDES}<FLAGS> -o <OBJECT> -c <SOURCE>") | ||
|
||
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> -Wl,-Map,<TARGET>.map -Wl,--start-group <OBJECTS> <LINK_LIBRARIES> -lm -lc -lgcc -lm -lc -lgcc -Wl,--end-group --specs=nano.specs -o <TARGET>") | ||
|
||
set(CMAKE_CXX_OUTPUT_EXTENSION ".o") | ||
set(CMAKE_DEPFILE_FLAGS_CXX "-MMD -MT <OBJECT> -MF <DEPFILE>") | ||
set(CMAKE_C_OUTPUT_EXTENSION ".o") | ||
set(CMAKE_DEPFILE_FLAGS_C "-MMD -MT <OBJECT> -MF <DEPFILE>") | ||
|
||
set(CMAKE_C_FLAGS_DEBUG_INIT "-g -gdwarf-3") | ||
set(CMAKE_C_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG") | ||
set(CMAKE_C_FLAGS_RELEASE_INIT "-Os -DNDEBUG") | ||
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-Os -g -gdwarf-3 -DNDEBUG") | ||
set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem ") | ||
|
||
|
||
set(CMAKE_ASM_FLAGS_DEBUG_INIT "-g -gdwarf-3") | ||
set(CMAKE_ASM_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG") | ||
set(CMAKE_ASM_FLAGS_RELEASE_INIT "-Os -DNDEBUG") | ||
set(CMAKE_ASM_FLAGS_RELWITHDEBINFO_INIT "-Os -g -gdwarf-3 -DNDEBUG") | ||
set(CMAKE_INCLUDE_SYSTEM_FLAG_ASM "-isystem ") | ||
|
||
set(CMAKE_CXX_CREATE_STATIC_LIBRARY "<CMAKE_AR> -cr <LINK_FLAGS> <TARGET> <OBJECTS>") | ||
|
||
set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> -Wl,-Map,<TARGET>.map -Wl,--start-group <OBJECTS> <LINK_LIBRARIES> -lnosys -lstdc++ -lsupc++ -lm -lc -lgcc -lstdc++ -lsupc++ -lm -lc -lgcc -Wl,--end-group --specs=nano.specs -o <TARGET>") | ||
|
||
set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g -gdwarf-3") | ||
set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG") | ||
set(CMAKE_CXX_FLAGS_RELEASE_INIT "-Os -DNDEBUG") | ||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-Os -g -gdwarf-3 -DNDEBUG") | ||
set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ") | ||
|
||
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER "7.1.0" OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL "7.1.0") | ||
message("${BoldRed}Supressing -Wexpansion-to-defined.${ColourReset}") | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-expansion-to-defined") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-expansion-to-defined") | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
add_custom_command( | ||
OUTPUT "${PROJECT_SOURCE_DIR}/${codal.output_folder}/${device.device}.hex" | ||
COMMAND "${LLVM_OBJCOPY}" -O ihex "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${device.device}" "${PROJECT_SOURCE_DIR}/${codal.output_folder}/${device.device}.hex" | ||
DEPENDS ${device.device} | ||
COMMENT "converting to hex file." | ||
) | ||
|
||
#specify a dependency on the elf file so that hex is automatically rebuilt when elf is changed. | ||
add_custom_target(${device.device}_hex ALL DEPENDS "${PROJECT_SOURCE_DIR}/${codal.output_folder}/${device.device}.hex") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef PLATFORM_INCLUDES | ||
#define PLATFORM_INCLUDES | ||
|
||
#include <stdint.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdarg.h> | ||
#include <math.h> | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Clang/LLVM is NOT the officialy supported toolchain for building Micro:Bit V2 CODAL applications. | ||
# This file serves to define an alternative compiler of which work has been put into making | ||
# compatible, but milage may vary in getting a working build. It is recommended to use | ||
# ARM_GCC where possible, with that being said complete Clang are possible with some tweaking. | ||
# See compiler-flags.cmake | ||
|
||
find_program(LLVM_RANLIB llvm-ranlib) | ||
find_program(LLVM_AR llvm-ar) | ||
find_program(CLANG clang) | ||
find_program(CLANG++ clang++) | ||
find_program(LLVM_OBJCOPY llvm-objcopy) | ||
|
||
set(CMAKE_OSX_SYSROOT "/") | ||
set(CMAKE_OSX_DEPLOYMENT_TARGET "") | ||
|
||
set(CMAKE_SYSTEM_NAME "Generic") | ||
set(CMAKE_SYSTEM_VERSION "2.0.0") | ||
|
||
set(CODAL_TOOLCHAIN "CLANG") | ||
|
||
if(CMAKE_VERSION VERSION_LESS "3.5.0") | ||
include(CMakeForceCompiler) | ||
cmake_force_c_compiler("${CLANG}" GNU) | ||
cmake_force_cxx_compiler("${CLANG++}" GNU) | ||
else() | ||
# from 3.5 the force_compiler macro is deprecated: CMake can detect | ||
# llvm-gcc as being a GNU compiler automatically | ||
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") | ||
set(CMAKE_C_COMPILER "${CLANG}") | ||
set(CMAKE_CXX_COMPILER "${CLANG++}") | ||
endif() | ||
|
||
SET(CMAKE_AR "${LLVM_AR}" CACHE FILEPATH "Archiver") | ||
SET(CMAKE_RANLIB "${LLVM_RANLIB}" CACHE FILEPATH "rlib") | ||
set(CMAKE_CXX_OUTPUT_EXTENSION ".o") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the
--target=arm-none-eabi
flag be added to this file?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other flags added to lancaster-university/codal-microbit-v2@master...Johnn333:codal-microbit-v2-clang:master could also be include in this file instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly, although I'm not sure where it would be added. "cpu_opts" in target.json feels like a more correct spot for it? Although we can't easily have a separate target.json.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main flags added here is for include paths which annoyingly have a version number in their name. Probably not the best thing to push as depending on arm-none-eabi version they may not have the directory? As for the others flags it was mostly to suppress warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is more
-W
flags added to the target-lock.json file. I assume those might not be required and could be removed to reduce the diff?What was the reason they were added? To help catch issues with the toolchain porting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From memory it was all just to reduce warnings aswell. Clang would give a warning about unused linker inputs so I got rid of them. It still builds but now I think about it may have something to do with the hex size diff? Might be worth looking into.