Skip to content

Commit 4f9d391

Browse files
committed
refactor: general cleanup, messaging
Important: the changed implemented here _require_ the user to call `project()` in "step 1", before calling any custom function, but after defining the toolchain file. The whole of Arduino_Core_STM32 (variant + core) is now added automatically when the user calls build_sketch() ; they don't have to do it themselves anymore. Also the standard libraries have moved from stm32_runtime to base_config. Indeed, even the files from the core depend on them. Also, _all_ the Arduino libraries depend on base_config only (even SrcWrapper). Additional dependencies were actually not needed. ***Moved the CMake-related files to /cmake*** -- for clarity with the remainder of the project (when using Arduino IDE) -- Also, this prevents IDEs from building the core "standalone" when seeing a CMakeLists.txt at the root, -- since that would be meaningless anyway. Also improve portability by replacing backslashes with forward slashes in paths on Windows. ======================= Change: moved the download folder away Having the download folder along the core seemed to cause malfunctions with some external tools (Arduino plugin on VScode). Moving it in the user's home folder fixes this issue. Each core installation nonetheless has its own download subfolder, to allow different versions with different requirements to coexist.
1 parent 8f910ff commit 4f9d391

36 files changed

+79
-83
lines changed

Diff for: cmake/FindArduinoCtags.cmake

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 3.21)
22
include(FetchContent)
33
include(FindPackageHandleStandardArgs)
44

5-
file(REAL_PATH "${CMAKE_CURRENT_LIST_DIR}/../../.Arduino_Core_STM32_downloads" DL_DIR)
6-
75
function(get_ctags)
86
cmake_host_system_information(
97
RESULT HOSTINFO
@@ -65,7 +63,9 @@ function(get_ctags)
6563
URL_HASH SHA512=${CHECKSUM}
6664
UPDATE_DISCONNECTED
6765
)
66+
message(STATUS "Downloading Arduino's ctags...")
6867
FetchContent_MakeAvailable(ctags)
68+
message(STATUS "Downloading Arduino's ctags... Done.")
6969
endfunction()
7070

7171
# -------------------------------------------------------------------------------

Diff for: cmake/build_sketch.cmake

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
cmake_minimum_required(VERSION 3.21)
22

3-
set(SCRIPTS_FOLDER ${CMAKE_CURRENT_LIST_DIR}/../scripts)
43
include(sketch_preprocess_sources)
54
include(convert_file)
65

6+
include(set_base_arduino_config)
7+
78
function(build_sketch)
9+
add_subdirectory(${BUILD_VARIANT_PATH} ./variant)
10+
add_subdirectory(${BUILD_CORE_PATH} ./cores/arduino)
11+
add_subdirectory(${BUILD_LIB_PATH} ./libraries)
12+
13+
814
cmake_parse_arguments(PARSE_ARGV 0 SKBD "" "TARGET" "SOURCES;DEPENDS")
915

1016
if(DEFINED SKBD_UNPARSED_ARGUMENTS OR DEFINED SKBD_KEYWORDS_MISSING_VALUES)
@@ -20,7 +26,7 @@ function(build_sketch)
2026
endif()
2127

2228
add_executable(${SKBD_TARGET})
23-
target_include_directories(base_config INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
29+
target_include_directories(base_config BEFORE INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
2430

2531
foreach(SRCS IN LISTS SKBD_SOURCES)
2632
sketch_preprocess_sources(OUTPUT_VARIABLE SRCS SOURCES ${SRCS})

Diff for: cmake/ensure_core_deps.cmake

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
cmake_minimum_required(VERSION 3.21)
22
include(FetchContent)
33

4-
file(REAL_PATH "${CMAKE_CURRENT_LIST_DIR}/../platform.txt" PLATFORMTXT_PATH)
5-
file(REAL_PATH "${CMAKE_CURRENT_LIST_DIR}/../../.Arduino_Core_STM32_downloads" DL_DIR)
6-
set(JSONCONFIG_URL "https://raw.githubusercontent.com/stm32duino/BoardManagerFiles/dev/package_stmicroelectronics_index.json")
7-
84
function(get_core_version OUTVAR)
95
file(READ ${PLATFORMTXT_PATH} PLATFORMTXT)
106
string(REGEX MATCH "version=.+\n" LINE "${PLATFORMTXT}")
@@ -147,8 +143,12 @@ function(ensure_core_deps)
147143
if(NOT EXISTS ${DL_DIR}/dist/CMSIS5 OR NOT EXISTS ${DL_DIR}/dist/xpack)
148144
get_core_version(COREVER)
149145
declare_deps(${COREVER})
146+
message(STATUS "Downloading the CMSIS...")
150147
FetchContent_MakeAvailable(CMSIS5)
148+
message(STATUS "Downloading the CMSIS... Done.")
149+
message(STATUS "Downloading the compiler toolchain...")
151150
FetchContent_MakeAvailable(xpack)
151+
message(STATUS "Downloading the compiler toolchain... Done.")
152152
endif()
153153

154154
set(CMSIS5_PATH ${DL_DIR}/dist/CMSIS5 PARENT_SCOPE)

Diff for: cmake/environment.cmake

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
cmake_minimum_required(VERSION 3.21)
2+
3+
string(MD5 PATH_HASH "${CMAKE_CURRENT_LIST_FILE}")
4+
5+
file(REAL_PATH "${CMAKE_CURRENT_LIST_DIR}/.." CORE_PATH)
6+
file(REAL_PATH "${CORE_PATH}/cores/arduino" BUILD_CORE_PATH)
7+
file(REAL_PATH "${CORE_PATH}/system" BUILD_SYSTEM_PATH)
8+
file(REAL_PATH "${CORE_PATH}/libraries" BUILD_LIB_PATH)
9+
file(REAL_PATH "~/.Arduino_Core_STM32_dl/${PATH_HASH}" DL_DIR EXPAND_TILDE)
10+
file(REAL_PATH "${CORE_PATH}/platform.txt" PLATFORMTXT_PATH)
11+
file(REAL_PATH "${CORE_PATH}/boards.txt" BOARDSTXT_PATH)
12+
file(REAL_PATH "${CORE_PATH}/cmake/scripts" SCRIPTS_FOLDER)
13+
file(REAL_PATH "${CORE_PATH}/cmake/templates/boards_db.cmake" CMAKE_BOARDS_DB_TEMPLATE_PATH)
14+
file(REAL_PATH "${CORE_PATH}/cmake/boards_db.cmake" CMAKE_BOARDS_DB_PATH)
15+
16+
set(JSONCONFIG_URL "https://raw.githubusercontent.com/stm32duino/BoardManagerFiles/dev/package_stmicroelectronics_index.json")
17+
18+
if(NOT "${CMAKE_CURRENT_LIST_DIR}" IN_LIST CMAKE_MODULE_PATH)
19+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
20+
endif()

Diff for: cmake/external_library.cmake

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
cmake_minimum_required(VERSION 3.21)
2-
set(CI_FOLDER ${CMAKE_CURRENT_LIST_DIR}/../CI)
32

43
function(external_library)
54
cmake_parse_arguments(PARSE_ARGV 0 XLIB "FORCE" "PATH" "DEPENDS")
@@ -15,7 +14,7 @@ function(external_library)
1514

1615
if(NOT EXISTS ${XLIB_PATH}/CMakeLists.txt OR ${XLIB_FORCE})
1716
execute_process(
18-
COMMAND ${Python3_EXECUTABLE} ${CI_FOLDER}/update/cmake_libs.py -l ${XLIB_PATH} -d ${XLIB_DEPENDS}
17+
COMMAND ${Python3_EXECUTABLE} ${SCRIPTS_FOLDER}/cmake_libs.py -l ${XLIB_PATH} -d ${XLIB_DEPENDS}
1918
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
2019
)
2120
endif()

Diff for: cmake/overall_settings.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
cmake_minimum_required(VERSION 3.21)
2-
add_library(user_settings INTERFACE)
32

43
function(overall_settings)
54
if(TARGET user_settings)
File renamed without changes.

Diff for: CI/update/cmake_core.py renamed to cmake/scripts/cmake_core.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
import sys
55
from pathlib import Path
66
from jinja2 import Environment, FileSystemLoader
7+
from cmake_gen import *
78

89
script_path = Path(__file__).parent.resolve()
9-
sys.path.append(str(script_path.parent))
10-
from utils.cmake_gen import *
1110

1211
parser = argparse.ArgumentParser()
1312
parser.add_argument("corepath", type=Path, help="path to .../cores/arduino")
1413

1514
shargs = parser.parse_args()
1615

17-
templates_dir = script_path / "templates"
16+
templates_dir = script_path / ".." / "templates"
1817
j2_env = Environment(
1918
loader=FileSystemLoader(str(templates_dir)), trim_blocks=True, lstrip_blocks=True
2019
)

Diff for: scripts/cmake_easy_setup.py renamed to cmake/scripts/cmake_easy_setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ def get_log(fname) :
6262
# platform lib path is already known, obviously, since that's where this script resides
6363
userlibs = pathlib.Path(libpaths["user"]).resolve()
6464
libs = [u.name for u in userlibs.iterdir() if u.is_dir()]
65-
corepath = pathlib.Path(__file__).parent.parent.resolve()
65+
corepath = pathlib.Path(__file__).parent.parent.parent.resolve()
6666

6767
j2_env = Environment(
68-
loader=FileSystemLoader(str(corepath/"CI"/"update"/"templates")), trim_blocks=True, lstrip_blocks=True
68+
loader=FileSystemLoader(str(corepath/"cmake"/"templates")), trim_blocks=True, lstrip_blocks=True
6969
)
7070
cmake_template = j2_env.get_template("easy_cmake.cmake")
7171

Diff for: CI/utils/cmake_gen.py renamed to cmake/scripts/cmake_gen.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def get_sources(dir, recursive=False, relative_to=None) :
4444
walker = type(dir).glob
4545

4646
return {
47-
file.relative_to(relative_to)
47+
str(file.relative_to(relative_to)).replace("\\", "/")
4848
for file in walker(dir, "*")
4949
if file.is_file() and file.suffix in SOURCEFILE_EXTS
5050
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
#!/usr/bin/env python3
22

33
import argparse
4-
import sys
54
from pathlib import Path
65
from jinja2 import Environment, FileSystemLoader
6+
from cmake_gen import *
77

88
script_path = Path(__file__).parent.resolve()
9-
sys.path.append(str(script_path.parent))
10-
from utils.cmake_gen import *
119

1210
parser = argparse.ArgumentParser()
1311
input_dirs = parser.add_mutually_exclusive_group(required=True)
@@ -17,7 +15,7 @@
1715

1816
shargs = parser.parse_args()
1917

20-
templates_dir = script_path / "templates"
18+
templates_dir = script_path / ".." / "templates"
2119
j2_env = Environment(
2220
loader=FileSystemLoader(str(templates_dir)), trim_blocks=True, lstrip_blocks=True
2321
)
@@ -29,11 +27,9 @@
2927
continue
3028

3129
config = autoconfig(lib)
32-
config["extra_libs"].add("core")
3330
config["extra_libs"].update(shargs.depends)
3431
render(lib, cmake_template, config)
3532
else :
3633
config = autoconfig(shargs.library)
37-
config["extra_libs"].add("core")
3834
config["extra_libs"].update(shargs.depends)
3935
render(shargs.library, cmake_template, config)

Diff for: CI/update/cmake_variant.py renamed to cmake/scripts/cmake_variant.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
#!/usr/bin/env python3
22

33
import argparse
4-
import sys
54
from pathlib import Path
65
from jinja2 import Environment, FileSystemLoader
6+
from cmake_gen import *
77

88
script_path = Path(__file__).parent.resolve()
9-
sys.path.append(str(script_path.parent))
10-
from utils.cmake_gen import *
119

1210
parser = argparse.ArgumentParser()
1311
parser.add_argument("variantspath", type=Path, help="path to .../variants/")
1412

1513
shargs = parser.parse_args()
1614

17-
templates_dir = script_path / "templates"
15+
templates_dir = script_path / ".." / "templates"
1816
j2_env = Environment(
1917
loader=FileSystemLoader(str(templates_dir)), trim_blocks=True, lstrip_blocks=True
2018
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: scripts/syms.py renamed to cmake/scripts/syms.py

File renamed without changes.

Diff for: CMakeLists.txt renamed to cmake/set_base_arduino_config.cmake

+12-23
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
cmake_minimum_required(VERSION 3.21)
22

3-
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
4-
find_package(ArduinoCtags REQUIRED)
5-
6-
7-
project("Arduino_Core_STM32" CXX C ASM)
8-
9-
10-
set(BUILD_CORE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cores/arduino")
11-
set(BUILD_SYSTEM_PATH "${CMAKE_CURRENT_SOURCE_DIR}/system")
12-
set(BUILD_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/libraries")
3+
# note: the doc say these must be called _at file scope_, not in a function
4+
enable_language(C)
5+
enable_language(CXX)
6+
enable_language(ASM)
137

148
add_library(base_config INTERFACE)
159

@@ -20,7 +14,13 @@ target_link_libraries(base_config INTERFACE
2014
)
2115

2216
# generic compilation options
23-
target_link_libraries(base_config INTERFACE board)
17+
target_link_libraries(base_config INTERFACE
18+
board
19+
m
20+
stdc++
21+
c
22+
gcc
23+
)
2424
target_compile_definitions(base_config INTERFACE
2525
USE_FULL_LL_DRIVER
2626
ARDUINO_ARCH_STM32
@@ -71,22 +71,11 @@ target_include_directories(base_config INTERFACE
7171
"${BUILD_SYSTEM_PATH}/Middlewares/OpenAMP/virtual_driver"
7272
)
7373

74-
add_subdirectory(${BUILD_CORE_PATH})
75-
add_subdirectory(${BUILD_VARIANT_PATH})
76-
add_subdirectory(${BUILD_LIB_PATH})
77-
78-
7974
add_library(stm32_runtime INTERFACE)
8075
target_link_libraries(stm32_runtime INTERFACE
8176
base_config
8277

8378
SrcWrapper
8479
core
85-
variant
86-
87-
${CMSIS_LIB}
88-
m
89-
stdc++
90-
c
91-
gcc
80+
$<TARGET_NAME_IF_EXISTS:variant>
9281
)

Diff for: cmake/set_board.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
cmake_minimum_required(VERSION 3.21)
2-
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
32

43
function(set_board BOARD_ID)
54
include(updatedb)

Diff for: cmake/sketch_preprocess_sources.cmake

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
cmake_minimum_required(VERSION 3.21)
22

3-
set(SCRIPTS_FOLDER ${CMAKE_CURRENT_LIST_DIR}/../scripts)
4-
53
function(sketch_preprocess_sources)
64
cmake_parse_arguments(PARSE_ARGV 0 SPC "" "OUTPUT_VARIABLE" "SOURCES")
75
set(SRCLIST "")
File renamed without changes.
File renamed without changes.

Diff for: CI/update/templates/easy_cmake.cmake renamed to cmake/templates/easy_cmake.cmake

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if (NOT ${CMAKE_PARENT_LIST_FILE} STREQUAL ${CMAKE_CURRENT_LIST_FILE})
2626
return()
2727
endif()
2828

29-
29+
project("{{tgtname+"_project" if tgtname else "@project_name_here@"}}")
3030

3131
# STEP 2: configure the build
3232
# -----------------------------------------------------------------------------
@@ -56,8 +56,6 @@ overall_settings(
5656

5757
# STEP 3: configure your sketch
5858
# -----------------------------------------------------------------------------
59-
project("{{tgtname+"_project" if tgtname else "@project_name_here@"}}")
60-
6159
include(external_library)
6260
# I cannot tell the dependencies of the library ahead-of-time
6361
# Please write them in using the DEPENDS ... clause

Diff for: cmake/toolchain.cmake

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
cmake_minimum_required(VERSION 3.21)
22

3+
include("${CMAKE_CURRENT_LIST_DIR}/environment.cmake")
4+
5+
find_package(ArduinoCtags REQUIRED)
6+
37
find_package(
48
Python3 3.9 REQUIRED
59
COMPONENTS Interpreter

Diff for: cmake/updatedb.cmake

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
cmake_minimum_required(VERSION 3.21)
2-
set(CORE_PATH ${CMAKE_CURRENT_LIST_DIR}/..)
3-
set(SCRIPTS_FOLDER ${CORE_PATH}/scripts)
42

53
function(updatedb)
6-
set(BOARDS_TXT ${CORE_PATH}/boards.txt)
7-
set(PLATFORM_TXT ${CORE_PATH}/platform.txt)
8-
set(TEMPLATE ${CORE_PATH}/CI/update/templates/boards_db.cmake)
9-
set(DB ${CORE_PATH}/cmake/boards_db.cmake)
10-
11-
set_directory_properties(PROPERTIES
12-
CMAKE_CONFIGURE_DEPENDS "${BOARDS_TXT};${PLATFORM_TXT};${TEMPLATE}"
4+
set_property(DIRECTORY APPEND
5+
PROPERTY CMAKE_CONFIGURE_DEPENDS
6+
"${BOARDSTXT_PATH}" "${PLATFORMTXT_PATH}" "${CMAKE_BOARDS_DB_TEMPLATE_PATH}"
137
)
148

15-
if(${BOARDS_TXT} IS_NEWER_THAN ${DB} OR ${TEMPLATE} IS_NEWER_THAN ${DB})
9+
if(
10+
${BOARDSTXT_PATH} IS_NEWER_THAN ${CMAKE_BOARDS_DB_PATH}
11+
OR ${PLATFORMTXT_PATH} IS_NEWER_THAN ${CMAKE_BOARDS_DB_PATH}
12+
OR ${CMAKE_BOARDS_DB_TEMPLATE_PATH} IS_NEWER_THAN ${CMAKE_BOARDS_DB_PATH}
13+
)
1614
execute_process(
1715
COMMAND ${Python3_EXECUTABLE} ${SCRIPTS_FOLDER}/parse_boards.py
18-
-b ${BOARDS_TXT} -p ${PLATFORM_TXT} -t ${TEMPLATE} -o ${DB}
19-
# COMMAND_ERROR_IS_FATAL ANY # requires VERSION 3.19
16+
-b ${BOARDSTXT_PATH}
17+
-p ${PLATFORMTXT_PATH}
18+
-t ${CMAKE_BOARDS_DB_TEMPLATE_PATH}
19+
-o ${CMAKE_BOARDS_DB_PATH}
20+
21+
COMMAND_ERROR_IS_FATAL ANY
2022
)
2123
endif()
2224
endfunction()

Diff for: libraries/CMSIS_DSP/CMakeLists.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ target_include_directories(CMSIS_DSP_usage INTERFACE
1212

1313
target_link_libraries(CMSIS_DSP_usage INTERFACE
1414
base_config
15-
core
1615
)
1716

1817
target_link_libraries(CMSIS_DSP INTERFACE CMSIS_DSP_usage)
@@ -29,9 +28,9 @@ add_library(CMSIS_DSP_bin OBJECT EXCLUDE_FROM_ALL
2928
src/FastMathFunctions/FastMathFunctions.c
3029
src/FilteringFunctions/FilteringFunctions.c
3130
src/MatrixFunctions/MatrixFunctions.c
32-
src/SVMFunctions/SVMFunctions.c
3331
src/StatisticsFunctions/StatisticsFunctions.c
3432
src/SupportFunctions/SupportFunctions.c
33+
src/SVMFunctions/SVMFunctions.c
3534
src/TransformFunctions/TransformFunctions.c
3635
)
3736
target_link_libraries(CMSIS_DSP_bin PUBLIC CMSIS_DSP_usage)

Diff for: libraries/EEPROM/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ target_include_directories(EEPROM_usage INTERFACE
1212

1313
target_link_libraries(EEPROM_usage INTERFACE
1414
base_config
15-
core
1615
)
1716

1817
target_link_libraries(EEPROM INTERFACE EEPROM_usage)

Diff for: libraries/IWatchdog/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ target_include_directories(IWatchdog_usage INTERFACE
1212

1313
target_link_libraries(IWatchdog_usage INTERFACE
1414
base_config
15-
core
1615
)
1716

1817
target_link_libraries(IWatchdog INTERFACE IWatchdog_usage)

Diff for: libraries/Keyboard/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ target_include_directories(Keyboard_usage INTERFACE
1212

1313
target_link_libraries(Keyboard_usage INTERFACE
1414
base_config
15-
core
1615
)
1716

1817
target_link_libraries(Keyboard INTERFACE Keyboard_usage)

0 commit comments

Comments
 (0)