Skip to content

Commit 41729ff

Browse files
authored
Version 1.3.11 (#14)
* Added --elf-template option Added esp-idf example * Hope to fix windows compile error * clang and catch2 don't like each other * fix typo * stupid me
1 parent aff8ce4 commit 41729ff

File tree

16 files changed

+793
-185
lines changed

16 files changed

+793
-185
lines changed

.github/workflows/cmake-multi-platform.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,24 @@ jobs:
2525
matrix:
2626
os: [ubuntu-latest, windows-latest]
2727
build_type: [Release]
28-
c_compiler: [gcc, clang, cl]
28+
# compilation error with clang/catch2 forced me to comment clang out
29+
# c_compiler: [gcc, clang, cl]
30+
c_compiler: [gcc, cl]
2931
include:
3032
- os: windows-latest
3133
c_compiler: cl
3234
cpp_compiler: cl
3335
- os: ubuntu-latest
3436
c_compiler: gcc
3537
cpp_compiler: g++
36-
- os: ubuntu-latest
37-
c_compiler: clang
38-
cpp_compiler: clang++
38+
# - os: ubuntu-latest
39+
# c_compiler: clang
40+
# cpp_compiler: clang++
3941
exclude:
4042
- os: windows-latest
4143
c_compiler: gcc
42-
- os: windows-latest
43-
c_compiler: clang
44+
# - os: windows-latest
45+
# c_compiler: clang
4446
- os: ubuntu-latest
4547
c_compiler: cl
4648

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
.vscode/
2-
mrc
3-
mrc-unit-test
4-
mrc-bootstrap
5-
build/
2+
**/build/
63
src/revision.hpp
74
src/version.hpp
5+
**/sdkconfig*

CMakeLists.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ project(mrc VERSION 1.3.11)
2929

3030
include(CTest)
3131

32-
set(CMAKE_CXX_STANDARD 17)
32+
set(CXX_EXTENSIONS OFF)
33+
set(CMAKE_CXX_STANDARD 20)
3334
set(CMAKE_CXX_STANDARD_REQUIRED ON)
3435

35-
find_package(Filesystem REQUIRED)
36-
3736
if(MSVC)
3837
# make msvc standards compliant...
3938
add_compile_options(/permissive-)
@@ -87,8 +86,8 @@ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/mrc-rsrc.obj
8786
add_executable(mrc ${PROJECT_SOURCE_DIR}/src/mrc.cpp ${CMAKE_BINARY_DIR}/mrc-rsrc.obj)
8887
add_executable(mrc-bootstrap ${PROJECT_SOURCE_DIR}/src/mrc.cpp ${PROJECT_SOURCE_DIR}/src/dummy.cpp)
8988

90-
target_link_libraries(mrc std::filesystem libmcfp::libmcfp)
91-
target_link_libraries(mrc-bootstrap std::filesystem libmcfp::libmcfp)
89+
target_link_libraries(mrc libmcfp::libmcfp)
90+
target_link_libraries(mrc-bootstrap libmcfp::libmcfp)
9291

9392
if(BUILD_TESTING)
9493
find_package(Catch2 3 QUIET)
@@ -99,7 +98,7 @@ if(BUILD_TESTING)
9998
FetchContent_Declare(
10099
Catch2
101100
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
102-
GIT_TAG v3.4.0 # or a later release
101+
GIT_TAG v3.5.2 # or a later release
103102
)
104103

105104
FetchContent_MakeAvailable(Catch2)

changelog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
Version 1.3.11
2+
- Added option --elf-template that can use an object
3+
file or executable in ELF format as template to find
4+
the correct --elf-* flags to use.
5+
This option is used automatically by mrc when you
6+
use it via the cmake plugin.
27
- Remove libmcfp as submodule
38
- Moved from Boost.Test to Catch2 for unit testing
49
- Using FetchContent for dependencies
10+
- Dropped FindFilesystem, assuming std::filesystem is
11+
standard by now.
512

613
Version 1.3.10
714
- Check cmake version before trying to write dependency file commands

cmake/FindFilesystem.cmake

Lines changed: 0 additions & 74 deletions
This file was deleted.

cmake/mrc-config.cmake

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,24 @@ find_package_handle_standard_args(Mrc
8484
REQUIRED_VARS MRC_EXECUTABLE
8585
VERSION_VAR MRC_VERSION_STRING)
8686

87+
# internal, create an ELF template file based on the current compiler flags and all
88+
89+
function(_mrc_create_elf_template _target)
90+
try_compile(BUILD_OK
91+
SOURCE_FROM_CONTENT my_code.cpp [[
92+
extern "C" int my_global_int = 42;
93+
int main() { return 0; }
94+
]]
95+
NO_CACHE
96+
NO_LOG
97+
COPY_FILE "${CMAKE_CURRENT_BINARY_DIR}/${_target}_rsrc_template.exe"
98+
)
99+
100+
if(NOT BUILD_OK)
101+
message(FATAL_ERROR "Failed to create template executable")
102+
endif()
103+
endfunction()
104+
87105
#[=======================================================================[.rst:
88106
.. command:: mrc_target_resources
89107
@@ -118,11 +136,17 @@ find_package_handle_standard_args(Mrc
118136
with their filename. Directories will be added recursively, if the
119137
directory name ends with a slash character, the directory part of
120138
the name will be stripped.
139+
140+
``CREATE_ELF_TEMPLATE``
141+
Create a small executable to be used as template for the ELF object
142+
file generation. This is executable is built using the same compiler
143+
settings as the final project and thus contains the correct ELF
144+
header from which mrc can copy the necessary information.
121145
#]=======================================================================]
122146

123147
function(mrc_target_resources _target)
124148

125-
set(flags VERBOSE)
149+
set(flags VERBOSE CREATE_ELF_TEMPLATE)
126150
set(options COFF_TYPE RSRC_FILE DEPENDS_FILE)
127151
set(sources RESOURCES)
128152
cmake_parse_arguments(MRC_OPTION "${flags}" "${options}" "${sources}" ${ARGN})
@@ -175,9 +199,16 @@ function(mrc_target_resources _target)
175199
list(APPEND MRC_OPTION_RESOURCES "--verbose")
176200
endif()
177201

202+
if(CMAKE_CROSSCOMPILING OR ${MRC_OPTION_CREATE_ELF_TEMPLATE})
203+
_mrc_create_elf_template(${_target})
204+
list(APPEND MRC_OPTION_RESOURCES "--elf-template=${CMAKE_CURRENT_BINARY_DIR}/${_target}_rsrc_template.exe")
205+
endif()
206+
207+
cmake_policy(SET CMP0116 NEW)
208+
178209
# If we can use DEPFILE, use it.
179210
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.21")
180-
add_custom_target("mrc-depends-file_${_target}" ALL
211+
add_custom_target("mrc-depends-file_${_target}" ALL
181212
BYPRODUCTS ${RSRC_DEP_FILE}
182213
COMMAND ${MRC_EXECUTABLE} -o ${RSRC_FILE} -d ${RSRC_DEP_FILE} ${MRC_OPTION_RESOURCES}
183214
VERBATIM)

examples/esp-idf-rsrc/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# The following lines of boilerplate have to be in your project's
2+
# CMakeLists in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.16)
4+
5+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6+
project(my-rsrc-app)

examples/esp-idf-rsrc/README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
Using resources in ESP-IDF
2+
==========================
3+
4+
It is very easy to add resources to esp-idf projects as is shown in this example.
5+
Here we create a single resource called `hello.txt` and its content comes from
6+
the file `hello.txt`. The header file is created and resources are added to
7+
the main component using the cmake snippet:
8+
9+
```cmake
10+
# locate and include the mrc macro's
11+
find_package(Mrc)
12+
13+
# write a header file
14+
mrc_write_header(${CMAKE_CURRENT_SOURCE_DIR}/mrsrc.hpp)
15+
16+
# Add one resource to the executable
17+
mrc_target_resources(${COMPONENT_LIB} CREATE_ELF_TEMPLATE
18+
RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/hello.txt)
19+
```
20+
21+
Now you can simply use that resource:
22+
23+
```c++
24+
#include "esp_log.h"
25+
26+
#include "mrsrc.hpp"
27+
28+
const char TAG[] = "esp-rsrc";
29+
30+
extern "C" void app_main(void)
31+
{
32+
mrsrc::rsrc data("hello.txt");
33+
if (data)
34+
{
35+
std::string s(data.data(), data.size());
36+
ESP_LOGI(TAG, "Resource found: '%s'!", s.c_str());
37+
}
38+
else
39+
ESP_LOGI(TAG, "The resource was not found");
40+
}
41+
```
42+
43+
Use `idf.py build flash monitor` and the output will be:
44+
45+
```console
46+
ESP-ROM:esp32h2-20221101
47+
Build:Nov 1 2022
48+
rst:0x1 (POWERON),boot:0xc (SPI_FAST_FLASH_BOOT)
49+
SPIWP:0xee
50+
mode:DIO, clock div:1
51+
load:0x408460e0,len:0x17ac
52+
load:0x4083cfd0,len:0xe88
53+
load:0x4083efd0,len:0x2c94
54+
entry 0x4083cfda
55+
I (23) boot: ESP-IDF v5.3-dev-1353-gb3f7e2c8a4 2nd stage bootloader
56+
I (24) boot: compile time Feb 1 2024 15:04:08
57+
I (25) boot: chip revision: v0.1
58+
I (28) boot.esp32h2: SPI Speed : 64MHz
59+
I (33) boot.esp32h2: SPI Mode : DIO
60+
I (38) boot.esp32h2: SPI Flash Size : 2MB
61+
I (42) boot: Enabling RNG early entropy source...
62+
I (48) boot: Partition Table:
63+
I (51) boot: ## Label Usage Type ST Offset Length
64+
I (59) boot: 0 nvs WiFi data 01 02 00009000 00006000
65+
I (66) boot: 1 phy_init RF data 01 01 0000f000 00001000
66+
I (74) boot: 2 factory factory app 00 00 00010000 00100000
67+
I (81) boot: End of partition table
68+
I (85) esp_image: segment 0: paddr=00010020 vaddr=42018020 size=0a0e8h ( 41192) map
69+
I (107) esp_image: segment 1: paddr=0001a110 vaddr=40800000 size=05f08h ( 24328) load
70+
I (116) esp_image: segment 2: paddr=00020020 vaddr=42000020 size=1734ch ( 95052) map
71+
I (146) esp_image: segment 3: paddr=00037374 vaddr=40805f08 size=03acch ( 15052) load
72+
I (152) esp_image: segment 4: paddr=0003ae48 vaddr=408099e0 size=011f4h ( 4596) load
73+
I (157) boot: Loaded app from partition at offset 0x10000
74+
I (158) boot: Disabling RNG early entropy source...
75+
I (174) cpu_start: Unicore app
76+
W (183) clk: esp_perip_clk_init() has not been implemented yet
77+
I (190) cpu_start: Pro cpu start user code
78+
I (190) cpu_start: cpu freq: 96000000 Hz
79+
I (191) heap_init: Initializing. RAM available for dynamic allocation:
80+
I (195) heap_init: At 4080BDD0 len 000415B0 (261 KiB): RAM
81+
I (201) heap_init: At 4084D380 len 00002B60 (10 KiB): RAM
82+
I (209) spi_flash: detected chip: generic
83+
I (212) spi_flash: flash io: dio
84+
W (216) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
85+
I (229) cpu_start: Application information:
86+
I (234) cpu_start: Project name: my-rsrc-app
87+
I (239) cpu_start: App version: v1.3.10-23-gaff8ce4-dirty
88+
I (246) cpu_start: Compile time: Feb 1 2024 15:04:01
89+
I (252) cpu_start: ELF file SHA256: 30e7d4161...
90+
I (257) cpu_start: ESP-IDF: v5.3-dev-1353-gb3f7e2c8a4
91+
I (264) cpu_start: Min chip rev: v0.0
92+
I (269) cpu_start: Max chip rev: v0.99
93+
I (273) cpu_start: Chip rev: v0.1
94+
I (279) sleep: Configure to isolate all GPIO pins in sleep state
95+
I (285) sleep: Enable automatic switching of GPIO sleep configuration
96+
I (292) main_task: Started on CPU0
97+
I (292) main_task: Calling app_main()
98+
I (292) esp-rsrc: Resource found: 'Hello, world!
99+
'!
100+
I (302) main_task: Returned from app_main()
101+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
find_package(Mrc)
2+
3+
idf_component_register(SRCS esp-rsrc-app.cpp
4+
INCLUDE_DIRS ".")
5+
6+
mrc_write_header(${CMAKE_CURRENT_SOURCE_DIR}/mrsrc.hpp)
7+
8+
mrc_target_resources(${COMPONENT_LIB} CREATE_ELF_TEMPLATE
9+
RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/hello.txt)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*-
2+
* SPDX-License-Identifier: BSD-2-Clause
3+
*
4+
* Copyright (c) 2024 Maarten L. Hekkelman
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright notice, this
10+
* list of conditions and the following disclaimer
11+
* 2. Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation
13+
* and/or other materials provided with the distribution.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
*/
26+
27+
#include "esp_log.h"
28+
29+
#include "mrsrc.hpp"
30+
31+
const char TAG[] = "esp-rsrc";
32+
33+
extern "C" void app_main(void)
34+
{
35+
mrsrc::rsrc data("hello.txt");
36+
if (data)
37+
{
38+
std::string s(data.data(), data.size());
39+
ESP_LOGI(TAG, "Resource found: '%s'!", s.c_str());
40+
}
41+
else
42+
ESP_LOGI(TAG, "The resource was not found");
43+
44+
}
45+

0 commit comments

Comments
 (0)