Skip to content

Commit 4a169ad

Browse files
massonalfpistm
authored andcommitted
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 c4af950 commit 4a169ad

36 files changed

+79
-83
lines changed

cmake/FindArduinoCtags.cmake

Lines changed: 2 additions & 2 deletions
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
# -------------------------------------------------------------------------------

cmake/build_sketch.cmake

Lines changed: 8 additions & 2 deletions
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})

cmake/ensure_core_deps.cmake

Lines changed: 4 additions & 4 deletions
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)

cmake/environment.cmake

Lines changed: 20 additions & 0 deletions
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()

cmake/external_library.cmake

Lines changed: 1 addition & 2 deletions
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()

cmake/overall_settings.cmake

Lines changed: 0 additions & 1 deletion
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.

CI/update/cmake_core.py renamed to cmake/scripts/cmake_core.py

Lines changed: 2 additions & 3 deletions
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
)

scripts/cmake_easy_setup.py renamed to cmake/scripts/cmake_easy_setup.py

Lines changed: 2 additions & 2 deletions
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

CI/utils/cmake_gen.py renamed to cmake/scripts/cmake_gen.py

Lines changed: 1 addition & 1 deletion
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
}

0 commit comments

Comments
 (0)