Skip to content

Commit ef166a5

Browse files
massonalfpistm
authored andcommitted
feat: full support of precompiled libraries
Required changing the CMakeLists.txt template structure and targets definition designs to handle the different cases (precompile=true|full, float ABI...).
1 parent 2f2feb1 commit ef166a5

File tree

534 files changed

+9953
-4845
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

534 files changed

+9953
-4845
lines changed

CI/update/cmake_libs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
continue
3535

3636
config = autoconfig(lib)
37+
config["extra_libs"].add("core")
3738
render(lib, cmake_template, config)
3839
else :
3940
config = autoconfig(rootdir)
41+
config["extra_libs"].add("core")
4042
render(rootdir, cmake_template, config)

CI/update/templates/CMakeLists.txt

Lines changed: 43 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,69 @@
1-
{% if precompiled != "full" %}
2-
1+
{% if objlib and sources %}
2+
# v3.21 implemented semantic changes regarding $<TARGET_OBJECTS:...>
3+
# See https://cmake.org/cmake/help/v3.21/command/target_link_libraries.html#linking-object-libraries-via-target-objects
4+
cmake_minimum_required(VERSION 3.21)
5+
{% endif %}
36

4-
add_library({{target}}{{" OBJECT" if objlib}} EXCLUDE_FROM_ALL
5-
{% for file in sources | sort %}
6-
{{file}}
7-
{% endfor %}
8-
)
7+
add_library({{target}} INTERFACE)
8+
add_library({{target}}_usage INTERFACE)
99

1010
{% if includedirs %}
11-
target_include_directories({{target}} PUBLIC
11+
target_include_directories({{target}}_usage INTERFACE
1212
{% for dir in includedirs | sort %}
1313
{{dir}}
1414
{% endfor %}
1515
)
1616
{% endif %}
1717

18-
target_link_libraries({{target}} PUBLIC
19-
core_config
20-
{% for lib in extra_libs | sort %}
21-
{{lib}}
22-
{% endfor %}
23-
)
24-
25-
{% if precompiled == "true" %}
26-
if(EXISTS "{{"${CMAKE_CURRENT_SOURCE_DIR}"}}/src/{{"${"}}MCU{{"}"}}/lib{{target}}.a")
27-
target_link_libraries({{target}} PUBLIC
28-
"{{"${CMAKE_CURRENT_SOURCE_DIR}"}}/src/{{"${"}}MCU{{"}"}}/lib{{target}}.a"
29-
)
30-
endif()
31-
{% endif %}
32-
3318
{% if ldflags %}
34-
taget_link_options({{target}} PUBLIC
19+
target_link_options({{target}}_usage INTERFACE
3520
{{ldflags}}
3621
)
3722
{% endif %}
3823

39-
{% else %} {# precompiled == "full" #}
40-
41-
{#
42-
When precompiled = full, we define 3 targets:
43-
target, target_bin, target_usage
44-
target is the externally usable library
45-
target_bin contains the source files, to be used as fallback
46-
target_usage contains the "transitive usage requirements", i.e., include directories, linker options...
47-
48-
target wraps target_usage and [target_bin or the precompiled library]
49-
target_bin uses target_usage (it's a public interface, i.e. meant for me and my users)
50-
#}
51-
52-
add_library({{target}} INTERFACE)
53-
add_library({{target}}_usage INTERFACE)
54-
add_library({{target}}_bin {{" OBJECT" if objlib}} EXCLUDE_FROM_ALL
55-
{% for file in sources | sort %}
56-
{{file}}
57-
{% endfor %}
24+
target_link_libraries({{target}}_usage INTERFACE
25+
core_config
26+
{% for lib in extra_libs | sort %}
27+
{{lib}}
28+
{% endfor %}
5829
)
59-
target_link_libraries({{target}} INTERFACE {{target}}_usage)
60-
target_link_libraries({{target}}_bin PUBLIC {{target}}_usage)
6130

62-
if(EXISTS "./src/{{"${"}}MCU{{"}"}}/lib{{target}}.a")
63-
target_link_libraries({{target}} INTERFACE
64-
"./src/{{"${"}}MCU{{"}"}}/lib{{target}}.a"
65-
)
66-
else()
67-
target_link_libraries({{target}} INTERFACE
68-
{{target}}_bin
69-
$<TARGET_OBJECTS:{{target}}_bin>
70-
)
71-
endif()
31+
target_link_libraries({{target}} INTERFACE {{target}}_usage)
7232

7333

74-
{% if includedirs %}
75-
target_include_directories({{target}}_usage INTERFACE
76-
{% for dir in includedirs | sort %}
77-
{{dir}}
78-
{% endfor %}
79-
)
34+
{% if precompiled in ("true", "full") %}
35+
set({{target}}_PRECOMPILED false)
36+
{% for config, libs in binaries | dictsort | reverse %}
37+
{{"if" if loop.first else "elseif"}} ("${MCU}${FPCONF}" STREQUAL "{{config}}")
38+
target_link_libraries({{target}}_usage INTERFACE
39+
{% for lib in libs %}
40+
"{{"${CMAKE_CURRENT_SOURCE_DIR}/"}}{{lib}}"
41+
{% endfor %}
42+
)
43+
set({{target}}_PRECOMPILED true)
44+
{{"endif()" if loop.last}}
45+
{% endfor %}
8046
{% endif %}
8147

82-
target_link_libraries({{target}}_usage INTERFACE
83-
core_config
84-
{% for lib in extra_libs | sort %}
85-
{{lib}}
48+
{% if sources %}
49+
add_library({{target}}_bin {{"OBJECT" if objlib else "STATIC"}} EXCLUDE_FROM_ALL
50+
{% for file in sources | sort %}
51+
{{file}}
8652
{% endfor %}
8753
)
54+
target_link_libraries({{target}}_bin PUBLIC {{target}}_usage)
8855

89-
{% if ldflags %}
90-
taget_link_options({{target}}_usage INTERFACE
91-
{{ldflags}}
56+
{% if precompiled == "full" %}
57+
if(NOT {{"${"}}{{target}}_PRECOMPILED{{"}"}})
58+
{% endif %}
59+
target_link_libraries({{target}} INTERFACE
60+
{{target}}_bin
61+
{% if objlib %}
62+
$<TARGET_OBJECTS:{{target}}_bin>
63+
{% endif %}
9264
)
65+
{% if precompiled == "full" %}
66+
endif()
9367
{% endif %}
9468

95-
{% endif %} {# precompiled ?= "full" #}
69+
{% endif %}

CI/update/templates/boards_db.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ set({{pnum}}_VARIANT_PATH "${CMAKE_CURRENT_LIST_DIR}/../variants/{{config.build.
66
set({{pnum}}_MAXSIZE {{config.upload.maximum_size}})
77
set({{pnum}}_MAXDATASIZE {{config.upload.maximum_data_size}})
88
set({{pnum}}_MCU {{config.build.mcu}})
9+
{% if config._fpconf != "-" %}
10+
set({{pnum}}_FPCONF {{config._fpconf}})
11+
{% endif %}
912
add_library({{pnum}} INTERFACE)
1013
target_compile_options({{pnum}} INTERFACE
1114
"SHELL:{{config.build.st_extra_flags}}"

CI/utils/cmake_gen.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def get_default_config() :
1111
objlib = True,
1212
ldflags = "",
1313
precompiled = "false",
14+
binaries = dict(),
1415
)
1516

1617
def parse_configfile(file) :
@@ -52,6 +53,22 @@ def render(dir, template, config) :
5253
with open(dir / "CMakeLists.txt", "w") as outfile :
5354
outfile.write(template.render(**config))
5455

56+
def get_static_libs(dir) :
57+
result = dict()
58+
cpu = ""
59+
fpconf = "-" # format: f"{fpu}-{float_abi}"; this makes "-" by default
60+
for file in dir.glob("src/*/lib*.a") :
61+
if not file.is_file() :
62+
continue
63+
cpu = file.parent.name
64+
result.setdefault(cpu+fpconf, list()).append(file.relative_to(dir))
65+
for file in dir.glob("src/*/*/lib*.a") :
66+
if not file.is_file() :
67+
continue
68+
fpconf = file.parent.name
69+
cpu = file.parent.parent.name
70+
result.setdefault(cpu+fpconf, list()).append(file.relative_to(dir))
71+
return result
5572

5673
def config_for_bareflat(dir, force_recurse=False) :
5774
# no library.properties
@@ -76,6 +93,7 @@ def config_for_modern(dir) :
7693
config["target"] = dir.name
7794
config["sources"].update(get_sources(dir/"src", recursive=True, relative_to=dir))
7895
config["includedirs"].add((dir/"src").relative_to(dir))
96+
config["binaries"].update(get_static_libs(dir))
7997

8098
return config
8199

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ target_link_libraries(stm32_runtime INTERFACE
238238
core_config
239239

240240
SrcWrapper
241-
$<TARGET_OBJECTS:SrcWrapper>
242241
core
243242
variant
244243

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy