Skip to content
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

[DO NOT MERGE] NuttX cmake #46

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ core
/.project
/pcode
/tags
build/
6 changes: 6 additions & 0 deletions .vscode/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.cortex-debug.peripherals.state.json
.cortex-debug.registers.state.json
compile_commands.json

# C/C++ extension does some local caching in this folder
ipch/
22 changes: 22 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"configurations": [
{
"name": "Linux",
"intelliSenseMode": "gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"browse": {
"path": [
"${workspaceFolder}/include/",
"."
],
"limitSymbolsToIncludedHeaders": true
},
"compileCommands": "${workspaceFolder}/.vscode/compile_commands.json",
"configurationProvider": "vector-of-bool.cmake-tools"
}
],
"version": 4
}
5 changes: 5 additions & 0 deletions .vscode/cmake-kits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{
"name": "detect"
}
]
8 changes: 8 additions & 0 deletions .vscode/cmake-variants.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CONFIG:
default: stm32f4discovery/nsh
choices:
stm32f4discovery/nsh:
short: stm32f4discovery/nsh
buildType: MinSizeRel
settings:
CONFIG: stm32f4discovery/nsh
16 changes: 16 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"chiehyu.vscode-astyle",
"dan-c-underwood.arm",
"github.vscode-pull-request-github",
"marus25.cortex-debug",
"ms-azuretools.vscode-docker",
"ms-python.python",
"ms-vscode.cpptools",
"twxs.cmake",
"vector-of-bool.cmake-tools",
"zixuanwang.linkerscript"
]
}
51 changes: 51 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug STM32F427 (jlink)",
"device": "STM32F427VI",
"svdFile": "${workspaceRoot}/../cmsis-svd/data/STMicro/STM32F427.svd",
"executable": "${command:cmake.launchTargetPath}",
"request": "launch",
"type": "cortex-debug",
"servertype": "jlink",
"interface": "swd",
"cwd": "${workspaceRoot}",
"internalConsoleOptions": "openOnSessionStart",
"preLaunchCommands": [
"set mem inaccessible-by-default off",
"set print pretty",
]
},
{
"name": "Debug STM32F7x5 (jlink)",
"device": "STM32F765VI",
"svdFile": "${workspaceRoot}/../cmsis-svd/data/STMicro/STM32F7x5.svd",
"executable": "${command:cmake.launchTargetPath}",
"request": "launch",
"type": "cortex-debug",
"servertype": "jlink",
"interface": "swd",
"internalConsoleOptions": "openOnSessionStart",
"preLaunchCommands": [
"set mem inaccessible-by-default off",
"set print pretty",
]
},
{
"name": "Debug STM32F7x7 (jlink)",
"device": "STM32F777NI",
"svdFile": "${workspaceRoot}/../cmsis-svd/data/STMicro/STM32F7x7.svd",
"executable": "${command:cmake.launchTargetPath}",
"request": "launch",
"type": "cortex-debug",
"servertype": "jlink",
"interface": "swd",
"internalConsoleOptions": "openOnSessionStart",
"preLaunchCommands": [
"set mem inaccessible-by-default off",
"set print pretty",
]
}
]
}
49 changes: 49 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"astyle.c.enable": true,
"astyle.cpp.enable": true,
"breadcrumbs.enabled": true,
"cmake.autoRestartBuild": true,
"cmake.buildDirectory": "${workspaceFolder}/build/${variant:CONFIG}",
"cmake.buildBeforeRun": true,
"cmake.configureOnOpen": true,
"cmake.copyCompileCommands": "${workspaceFolder}/.vscode/compile_commands.json",
"cortex-debug.enableTelemetry": false,
"C_Cpp.clang_format_fallbackStyle": "none",
"C_Cpp.configurationWarnings": "Disabled",
"C_Cpp.default.cppStandard": "c++11",
"C_Cpp.default.cStandard": "c89",
"C_Cpp.default.intelliSenseMode": "gcc-x64",
"C_Cpp.errorSquiggles": "Disabled",
"C_Cpp.formatting": "Disabled",
"C_Cpp.intelliSenseEngine": "Default",
"C_Cpp.intelliSenseEngineFallback": "Disabled",
"debug.toolBarLocation": "docked",
"editor.dragAndDrop": false,
"editor.insertSpaces": false,
"editor.minimap.maxColumn": 120,
"editor.minimap.renderCharacters": false,
"editor.minimap.showSlider": "always",
"editor.smoothScrolling": true,
"editor.suggest.localityBonus": true,
"editor.tabSize": 8,
"editor.wordWrapColumn": 120,
"explorer.openEditors.visible": 0,
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"files.watcherExclude": {
"**/build/*": true
},
"githubPullRequests.defaultMergeMethod": "squash",
"githubPullRequests.telemetry.enabled": false,
"gitlens.advanced.telemetry.enabled": false,
"search.exclude": {
"build/**": true
},
"search.showLineNumbers": true,
"telemetry.enableTelemetry": false,
"window.title": "${dirty} ${activeEditorMedium}${separator}${rootName}",
"workbench.editor.highlightModifiedTabs": true,
"workbench.enableExperiments": false,
"workbench.settings.enableNaturalLanguageSearch": false,
"workbench.statusBar.feedback.visible": false
}
208 changes: 208 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
cmake_minimum_required(VERSION 3.2)

string(REPLACE "/" ";" BOARD_CONFIG ${CONFIG})
list(GET BOARD_CONFIG 0 NUTTX_BOARD)
list(GET BOARD_CONFIG 1 NUTTX_CONFIG)

message(STATUS "NuttX: ${NUTTX_BOARD}/${NUTTX_CONFIG}")
message(STATUS "NuttX board: ${NUTTX_BOARD}")
message(STATUS "NuttX config: ${NUTTX_CONFIG}")

# CMake build type (Debug Release RelWithDebInfo MinSizeRel Coverage)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "MinSizeRel" CACHE STRING "Build type" FORCE)
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug;Release;RelWithDebInfo;MinSizeRel")

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 99)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(NUTTX_DIR ${CMAKE_CURRENT_SOURCE_DIR})

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

# must be done early to bring all CONFIG variables into cmake
include(defconfig)

# TODO: generalize like in arch/arm/src/armv7-m/Toolchain.defs
if("${CONFIG_ARCH_CORTEXM0}" STREQUAL "y")
set(CMAKE_SYSTEM_PROCESSOR cortex-m0)
elseif("${CONFIG_ARCH_CORTEXM3}" STREQUAL "y")
set(CMAKE_SYSTEM_PROCESSOR cortex-m3)
elseif("${CONFIG_ARCH_CORTEXM4}" STREQUAL "y")
set(CMAKE_SYSTEM_PROCESSOR cortex-m4)
elseif("${CONFIG_ARCH_CORTEXM7}" STREQUAL "y")
set(CMAKE_SYSTEM_PROCESSOR cortex-m7)
else()
message(FATAL_ERROR "processor not set")
endif()

set(CMAKE_TOOLCHAIN_FILE Toolchain-arm-none-eabi)

project(NuttX LANGUAGES ASM C CXX)

include(ccache)
include(nuttx_add_library)
include(set_parent_srcs)

#=============================================================================

# .version
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/.version
COMMAND tools/version.sh -v 0.0 -b 0 ${CMAKE_BINARY_DIR}/.version
DEPENDS ${NUTTX_DIR}/configs/${NUTTX_BOARD}/${NUTTX_CONFIG}/defconfig
WORKING_DIRECTORY ${NUTTX_DIR}
)

#=============================================================================
# mkconfig & mkversion
include(ExternalProject)
ExternalProject_Add(nuttx_host_tools
SOURCE_DIR ${CMAKE_SOURCE_DIR}/tools
INSTALL_DIR ${CMAKE_BINARY_DIR}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}
USES_TERMINAL_CONFIGURE true
USES_TERMINAL_BUILD true
USES_TERMINAL_INSTALL true
)

# mkconfig and mkversion
add_custom_command(
OUTPUT
${CMAKE_BINARY_DIR}/include/nuttx/config.h
${CMAKE_BINARY_DIR}/include/nuttx/version.h
COMMAND
${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/include/nuttx
COMMAND
${CMAKE_BINARY_DIR}/bin/mkconfig ${CMAKE_BINARY_DIR} > ${CMAKE_BINARY_DIR}/include/nuttx/config.h
COMMAND
${CMAKE_BINARY_DIR}/bin/mkversion ${CMAKE_BINARY_DIR} > ${CMAKE_BINARY_DIR}/include/nuttx/version.h
DEPENDS
nuttx_host_tools
${CMAKE_BINARY_DIR}/.config
${CMAKE_BINARY_DIR}/.version
WORKING_DIRECTORY ${NUTTX_DIR}
)

#=============================================================================
# symlinks (TODO: move to build directory)
add_custom_command(
OUTPUT nuttx_symlinks.stamp
#COMMAND ${CMAKE_COMMAND} -E remove
#${NUTTX_DIR}/include/arch
#${NUTTX_DIR}/arch/${CONFIG_ARCH}/include/board
#${NUTTX_DIR}/arch/${CONFIG_ARCH}/include/chip
#${NUTTX_DIR}/arch/${CONFIG_ARCH}/src/board
#${NUTTX_DIR}/arch/${CONFIG_ARCH}/src/chip

#COMMAND ${CMAKE_COMMAND} -E create_symlink ${NUTTX_DIR}/arch/${CONFIG_ARCH}/include ${NUTTX_DIR}/include/arch # include/arch
#COMMAND ${CMAKE_COMMAND} -E create_symlink ${NUTTX_DIR}/configs/${NUTTX_BOARD}/include ${NUTTX_DIR}/arch/${CONFIG_ARCH}/include/board # arch/arm/include/board
#COMMAND ${CMAKE_COMMAND} -E create_symlink ${NUTTX_DIR}/arch/${CONFIG_ARCH}/include/${CONFIG_ARCH_CHIP} ${NUTTX_DIR}/arch/${CONFIG_ARCH}/include/chip # arch/arm/include/chip
#COMMAND ${CMAKE_COMMAND} -E create_symlink ${NUTTX_DIR}/configs/${NUTTX_BOARD}/src ${NUTTX_DIR}/arch/${CONFIG_ARCH}/src/board # arch/arm/src/board
#COMMAND ${CMAKE_COMMAND} -E create_symlink ${NUTTX_DIR}/arch/${CONFIG_ARCH}/src/${CONFIG_ARCH_CHIP} ${NUTTX_DIR}/arch/${CONFIG_ARCH}/src/chip # arch/arm/src/chip

COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/include

COMMAND ${CMAKE_COMMAND} -E copy_directory ${NUTTX_DIR}/arch/${CONFIG_ARCH}/include ${CMAKE_BINARY_DIR}/include/arch
COMMAND ${CMAKE_COMMAND} -E copy_directory ${NUTTX_DIR}/configs/${NUTTX_BOARD}/include ${CMAKE_BINARY_DIR}/include/arch/board # include/arch/board
COMMAND ${CMAKE_COMMAND} -E copy_directory ${NUTTX_DIR}/arch/${CONFIG_ARCH}/include/${CONFIG_ARCH_CHIP} ${CMAKE_BINARY_DIR}/include/arch/chip # include/arch/chip

COMMAND ${CMAKE_COMMAND} -E touch nuttx_symlinks.stamp
DEPENDS
${CMAKE_BINARY_DIR}/.config
)


add_custom_target(nuttx_context
DEPENDS
nuttx_symlinks.stamp
${CMAKE_BINARY_DIR}/include/nuttx/config.h
${CMAKE_BINARY_DIR}/include/nuttx/version.h
)

#=============================================================================
# compiler options

if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.9)
# force color for gcc > 4.9
add_compile_options(-fdiagnostics-color=always)
endif()
endif()

add_compile_options(
-fno-builtin
-fno-strength-reduce
-fno-strict-aliasing

-fomit-frame-pointer

-Wno-cpp
)

#=============================================================================
# create NuttX executable
#add_library(nuttx empty.c)
add_executable(nuttx empty.c)

#=============================================================================
# add all subdirectories

include_directories(include)
include_directories(${CMAKE_BINARY_DIR}/include)

include_directories(sched) # TODO: use target dependencies for linking

add_definitions("-D__KERNEL")

add_subdirectory(arch)
add_subdirectory(audio)
add_subdirectory(binfmt)
add_subdirectory(configs)
add_subdirectory(drivers)
add_subdirectory(fs)
add_subdirectory(graphics)
add_subdirectory(libs)
add_subdirectory(mm)
add_subdirectory(net)
add_subdirectory(sched)
add_subdirectory(wireless)

#=============================================================================
# NuttX Apps
if(CONFIG_APPS_DIR)
add_subdirectory(${CONFIG_APPS_DIR} apps)
endif()

#=============================================================================
# link final binary
get_property(nuttx_app_libs GLOBAL PROPERTY NUTTX_APP_LIBS)
get_property(nuttx_libs GLOBAL PROPERTY NUTTX_LIBRARIES)

set(LD_SCRIPT "${NUTTX_DIR}/configs/${NUTTX_BOARD}/scripts/ld.script")

if(NOT EXISTS ${LD_SCRIPT})
set(LD_SCRIPT "${NUTTX_DIR}/configs/${NUTTX_BOARD}/scripts/flash.ld")
endif()

target_link_libraries(nuttx PRIVATE

--entry=__start

-nostartfiles
-nodefaultlibs

-Wl,--script=${LD_SCRIPT}
#-Wl,-Map=${PX4_CONFIG}.map
#-Wl,--warn-common
#-Wl,--gc-sections

-Wl,--start-group
${nuttx_libs}
${nuttx_app_libs}
-Wl,--end-group

gcc
)
Loading