Skip to content

Commit 4f6526d

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. ***Moved the CMake-related files to /cmake*** -- for clarity with the remainder of the project (when using Arduino IDE)
1 parent 17a4ee1 commit 4f6526d

25 files changed

+58
-54
lines changed

Diff for: CMakeLists.txt

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
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-
73
project("Arduino_Core_STM32" CXX C ASM)
84

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")
13-
145
add_library(base_config INTERFACE)
156

167
# better than an if/else because these may be defined later
@@ -72,17 +63,15 @@ target_include_directories(base_config INTERFACE
7263
)
7364

7465
add_subdirectory(${BUILD_CORE_PATH})
75-
add_subdirectory(${BUILD_VARIANT_PATH})
7666
add_subdirectory(${BUILD_LIB_PATH})
7767

78-
7968
add_library(stm32_runtime INTERFACE)
8069
target_link_libraries(stm32_runtime INTERFACE
8170
base_config
8271

8372
SrcWrapper
8473
core
85-
variant
74+
$<TARGET_NAME_IF_EXISTS:variant>
8675

8776
${CMSIS_LIB}
8877
m

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
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

76
function(build_sketch)
7+
add_subdirectory(${BUILD_VARIANT_PATH} ./variant)
8+
add_subdirectory(${CORE_PATH} ./Arduino_Core_STM32)
9+
10+
811
cmake_parse_arguments(PARSE_ARGV 0 SKBD "" "TARGET" "SOURCES;DEPENDS")
912

1013
if(DEFINED SKBD_UNPARSED_ARGUMENTS OR DEFINED SKBD_KEYWORDS_MISSING_VALUES)
@@ -20,7 +23,7 @@ function(build_sketch)
2023
endif()
2124

2225
add_executable(${SKBD_TARGET})
23-
target_include_directories(base_config INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
26+
target_include_directories(base_config BEFORE INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
2427

2528
foreach(SRCS IN LISTS SKBD_SOURCES)
2629
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

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cmake_minimum_required(VERSION 3.21)
2+
3+
file(REAL_PATH "${CMAKE_CURRENT_LIST_DIR}/.." CORE_PATH)
4+
file(REAL_PATH "${CORE_PATH}/cores/arduino" BUILD_CORE_PATH)
5+
file(REAL_PATH "${CORE_PATH}/system" BUILD_SYSTEM_PATH)
6+
file(REAL_PATH "${CORE_PATH}/libraries" BUILD_LIB_PATH)
7+
file(REAL_PATH "${CORE_PATH}/../.Arduino_Core_STM32_downloads" DL_DIR)
8+
file(REAL_PATH "${CORE_PATH}/platform.txt" PLATFORMTXT_PATH)
9+
file(REAL_PATH "${CORE_PATH}/boards.txt" BOARDSTXT_PATH)
10+
file(REAL_PATH "${CORE_PATH}/cmake/scripts" SCRIPTS_FOLDER)
11+
file(REAL_PATH "${CORE_PATH}/cmake/templates/boards_db.cmake" CMAKE_BOARDS_DB_TEMPLATE_PATH)
12+
file(REAL_PATH "${CORE_PATH}/cmake/boards_db.cmake" CMAKE_BOARDS_DB_PATH)
13+
14+
set(JSONCONFIG_URL "https://raw.githubusercontent.com/stm32duino/BoardManagerFiles/dev/package_stmicroelectronics_index.json")
15+
16+
if(NOT "${CMAKE_CURRENT_LIST_DIR}" IN_LIST CMAKE_MODULE_PATH)
17+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
18+
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} ${CORE_PATH}/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
@@ -53,10 +53,10 @@ def get_log(fname) :
5353
# platform lib path is already known, obviously, since that's where this script resides
5454
userlibs = pathlib.Path(libpaths["user"]).resolve()
5555
libs = [u.name for u in userlibs.iterdir() if u.is_dir()]
56-
corepath = pathlib.Path(__file__).parent.parent.resolve()
56+
corepath = pathlib.Path(__file__).parent.parent.parent.resolve()
5757

5858
j2_env = Environment(
59-
loader=FileSystemLoader(str(corepath/"CI"/"update"/"templates")), trim_blocks=True, lstrip_blocks=True
59+
loader=FileSystemLoader(str(corepath/"cmake"/"templates")), trim_blocks=True, lstrip_blocks=True
6060
)
6161
cmake_template = j2_env.get_template("easy_cmake.cmake")
6262

File renamed without changes.

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

+2-4
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
)

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: 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()

0 commit comments

Comments
 (0)