Skip to content

Commit e1f25dd

Browse files
authored
[cbuild2cmake] Set generated property of files expected to be created by executes
1 parent 28a7676 commit e1f25dd

File tree

8 files changed

+171
-8
lines changed

8 files changed

+171
-8
lines changed

pkg/maker/buildcontent.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Arm Limited. All rights reserved.
2+
* Copyright (c) 2024-2025 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -764,10 +764,19 @@ func (c *Cbuild) CMakeSetFileProperties(file Files, abstractions CompilerAbstrac
764764
if hasAbstractions {
765765
content += c.CompilerAbstractions(abstractions, language)
766766
}
767+
// file is generated by executes
768+
filename := c.AddRootPrefix(c.ContextRoot, file.File)
769+
isGenerated := slices.Contains(c.GeneratedFiles, filename)
767770
// set file properties
768-
if hasMisc || hasAbstractions {
769-
content += "\nset_source_files_properties(\"" + c.AddRootPrefix(c.ContextRoot, file.File) +
770-
"\" PROPERTIES\n COMPILE_OPTIONS \"" + GetFileOptions(file, hasAbstractions, ";") + "\"\n)"
771+
if hasMisc || hasAbstractions || isGenerated {
772+
content += "\nset_source_files_properties(\"" + filename + "\" PROPERTIES"
773+
if hasMisc || hasAbstractions {
774+
content += "\n COMPILE_OPTIONS \"" + GetFileOptions(file, hasAbstractions, ";") + "\""
775+
}
776+
if isGenerated {
777+
content += "\n GENERATED TRUE"
778+
}
779+
content += "\n)"
771780
}
772781
return content
773782
}
@@ -879,6 +888,13 @@ func (m *Maker) ListExecutesIOs(io string, list []string, run string) string {
879888
return content
880889
}
881890

891+
func (m *Maker) GetGeneratedFiles(list []string) {
892+
for _, input := range list {
893+
file := AddRootPrefix("", input, m.SolutionRoot)
894+
m.GeneratedFiles = utils.AppendUniquely(m.GeneratedFiles, file)
895+
}
896+
}
897+
882898
func (m *Maker) ExecutesCommands(executes []Executes) string {
883899
var content string
884900
for _, item := range executes {
@@ -905,6 +921,7 @@ func (m *Maker) ExecutesCommands(executes []Executes) string {
905921
}
906922
if len(item.Output) > 0 {
907923
content += m.ListExecutesIOs("OUTPUT", item.Output, item.Run)
924+
m.GetGeneratedFiles(item.Output)
908925
}
909926
content += customTarget
910927
if !runAlways {

pkg/maker/buildcontent_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Arm Limited. All rights reserved.
2+
* Copyright (c) 2024-2025 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -519,4 +519,14 @@ add_dependencies(project.debug+target-executes
519519
assert.Equal(files, cbuild.GetAPIFiles("CORE:API"))
520520
})
521521

522+
t.Run("get executes generated files", func(t *testing.T) {
523+
var m maker.Maker
524+
var files = []string{"./source0.c", "./source1.c"}
525+
m.GetGeneratedFiles(files)
526+
assert.Equal(
527+
[]string{"${SOLUTION_ROOT}/source0.c", "${SOLUTION_ROOT}/source1.c"},
528+
m.GeneratedFiles,
529+
)
530+
})
531+
522532
}

pkg/maker/contextlists.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Arm Limited. All rights reserved.
2+
* Copyright (c) 2024-2025 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -27,6 +27,7 @@ func (m *Maker) CreateContextCMakeLists(index int) error {
2727
contextDir := path.Join(m.SolutionTmpDir, cbuild.BuildDescType.Context)
2828
cbuild.IncludeGlobal = make(LanguageMap)
2929
cbuild.UserIncGlobal = make(LanguageMap)
30+
cbuild.GeneratedFiles = m.GeneratedFiles
3031

3132
var cmakeTargetType, outputDirType, linkerVars, linkerOptions string
3233
if outputType == "elf" {

pkg/maker/maker.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Arm Limited. All rights reserved.
2+
* Copyright (c) 2024-2025 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -34,6 +34,7 @@ type Vars struct {
3434
Cbuilds []Cbuild
3535
Contexts []string
3636
EnvVars utils.EnvVars
37+
GeneratedFiles []string
3738
ToolchainConfigs map[*semver.Version]Toolchain
3839
RegisteredToolchains map[*semver.Version]Toolchain
3940
SelectedToolchainVersion []*semver.Version

pkg/maker/parser.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Arm Limited. All rights reserved.
2+
* Copyright (c) 2024-2025 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -82,6 +82,7 @@ type Cbuild struct {
8282
UserIncGlobal LanguageMap
8383
BuildGroups []string
8484
Toolchain string
85+
GeneratedFiles []string
8586
}
8687

8788
type Cbuilds struct {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
cmake_minimum_required(VERSION 3.27)
2+
3+
# Roots
4+
include("../roots.cmake")
5+
6+
set(CONTEXT project.Release+ARMCM0)
7+
set(TARGET ${CONTEXT})
8+
set(OUT_DIR "${SOLUTION_ROOT}/out/project/ARMCM0/Release")
9+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
10+
set(LD_SCRIPT "${SOLUTION_ROOT}/project/RTE/Device/ARMCM0/ARMCM0_ac6.sct")
11+
set(LD_SCRIPT_PP ${LD_SCRIPT})
12+
13+
# Processor Options
14+
set(CPU Cortex-M0)
15+
set(FPU NO_FPU)
16+
17+
# Toolchain config map
18+
include("toolchain.cmake")
19+
20+
# Setup project
21+
project(${CONTEXT} LANGUAGES C)
22+
23+
# Compilation database
24+
add_custom_target(database
25+
COMMAND ${CMAKE_COMMAND} -E make_directory "${OUT_DIR}"
26+
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json" "${OUT_DIR}"
27+
)
28+
set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES})
29+
30+
# Setup context
31+
add_executable(${CONTEXT})
32+
set_target_properties(${CONTEXT} PROPERTIES PREFIX "" SUFFIX ".axf" OUTPUT_NAME "project")
33+
set_target_properties(${CONTEXT} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${OUT_DIR})
34+
add_library(${CONTEXT}_GLOBAL INTERFACE)
35+
36+
# Includes
37+
target_include_directories(${CONTEXT} PUBLIC
38+
${SOLUTION_ROOT}/project/RTE/_Release_ARMCM0
39+
${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Include
40+
${CMSIS_PACK_ROOT}/ARM/Cortex_DFP/1.1.0/Device/ARMCM0/Include
41+
)
42+
43+
# Defines
44+
target_compile_definitions(${CONTEXT} PUBLIC
45+
$<$<COMPILE_LANGUAGE:C,CXX>:
46+
ARMCM0
47+
_RTE_
48+
>
49+
)
50+
51+
# Compile options
52+
target_compile_options(${CONTEXT} PUBLIC
53+
$<$<COMPILE_LANGUAGE:C>:
54+
"SHELL:${CC_CPU}"
55+
"SHELL:${CC_FLAGS}"
56+
"SHELL:-std=gnu11"
57+
"SHELL:-Wno-macro-redefined"
58+
"SHELL:-Wno-pragma-pack"
59+
"SHELL:-Wno-parentheses-equality"
60+
"SHELL:-Wno-license-management"
61+
>
62+
)
63+
64+
# Add groups and components
65+
include("groups.cmake")
66+
include("components.cmake")
67+
68+
target_link_libraries(${CONTEXT} PUBLIC
69+
Group_Source
70+
ARM_CMSIS_CORE_6_1_0
71+
ARM_Device_Startup_C_Startup_2_2_0
72+
)
73+
74+
# Linker options
75+
target_link_options(${CONTEXT} PUBLIC
76+
"SHELL:${LD_CPU}"
77+
"SHELL:${_LS}\"${LD_SCRIPT_PP}\""
78+
"SHELL:--entry=Reset_Handler"
79+
"SHELL:--map"
80+
"SHELL:--info summarysizes"
81+
"SHELL:--summary_stderr"
82+
"SHELL:--diag_suppress=L6314W"
83+
)
84+
set_target_properties(${CONTEXT} PROPERTIES LINK_DEPENDS ${LD_SCRIPT})
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# components.cmake
2+
3+
# component ARM::CMSIS:[email protected]
4+
add_library(ARM_CMSIS_CORE_6_1_0 INTERFACE)
5+
target_include_directories(ARM_CMSIS_CORE_6_1_0 INTERFACE
6+
$<TARGET_PROPERTY:${CONTEXT},INTERFACE_INCLUDE_DIRECTORIES>
7+
${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Include
8+
)
9+
target_compile_definitions(ARM_CMSIS_CORE_6_1_0 INTERFACE
10+
$<TARGET_PROPERTY:${CONTEXT},INTERFACE_COMPILE_DEFINITIONS>
11+
)
12+
13+
# component ARM::Device:Startup&C [email protected]
14+
add_library(ARM_Device_Startup_C_Startup_2_2_0 OBJECT
15+
"${SOLUTION_ROOT}/project/RTE/Device/ARMCM0/startup_ARMCM0.c"
16+
"${SOLUTION_ROOT}/project/RTE/Device/ARMCM0/system_ARMCM0.c"
17+
)
18+
target_include_directories(ARM_Device_Startup_C_Startup_2_2_0 PUBLIC
19+
$<TARGET_PROPERTY:${CONTEXT},INTERFACE_INCLUDE_DIRECTORIES>
20+
${CMSIS_PACK_ROOT}/ARM/Cortex_DFP/1.1.0/Device/ARMCM0/Include
21+
)
22+
target_compile_definitions(ARM_Device_Startup_C_Startup_2_2_0 PUBLIC
23+
$<TARGET_PROPERTY:${CONTEXT},INTERFACE_COMPILE_DEFINITIONS>
24+
)
25+
target_compile_options(ARM_Device_Startup_C_Startup_2_2_0 PUBLIC
26+
$<TARGET_PROPERTY:${CONTEXT},INTERFACE_COMPILE_OPTIONS>
27+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# groups.cmake
2+
3+
# group Source
4+
add_library(Group_Source OBJECT
5+
"${SOLUTION_ROOT}/project/source0.c"
6+
"${SOLUTION_ROOT}/project/source1.c"
7+
)
8+
target_include_directories(Group_Source PUBLIC
9+
$<TARGET_PROPERTY:${CONTEXT},INTERFACE_INCLUDE_DIRECTORIES>
10+
)
11+
target_compile_definitions(Group_Source PUBLIC
12+
$<TARGET_PROPERTY:${CONTEXT},INTERFACE_COMPILE_DEFINITIONS>
13+
)
14+
target_compile_options(Group_Source PUBLIC
15+
$<TARGET_PROPERTY:${CONTEXT},INTERFACE_COMPILE_OPTIONS>
16+
)
17+
set_source_files_properties("${SOLUTION_ROOT}/project/source0.c" PROPERTIES
18+
GENERATED TRUE
19+
)
20+
set_source_files_properties("${SOLUTION_ROOT}/project/source1.c" PROPERTIES
21+
GENERATED TRUE
22+
)

0 commit comments

Comments
 (0)