Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cbuild2cmake] Replace blanks in CMake target names derived from build contexts #182

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cmd/cbuild2cmake/commands/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,20 @@ set(OUTPUTS_1
assert.False(mismatch)
})

t.Run("test blanks", func(t *testing.T) {
cmd := commands.NewRootCmd()
testCaseRoot := testRoot + "/run/solutions/blanks"
cbuildIdxFile := testCaseRoot + "/solution.cbuild-idx.yml"
cmd.SetArgs([]string{cbuildIdxFile, "--debug"})
err := cmd.Execute()
assert.Nil(err)

// check golden references
err, mismatch := inittest.CompareFiles(testCaseRoot+"/ref", testCaseRoot+"/tmp")
assert.Nil(err)
assert.False(mismatch)
})

t.Run("test linker preprocessing", func(t *testing.T) {
cmd := commands.NewRootCmd()
testCaseRoot := testRoot + "/run/solutions/linker-pre-processing"
Expand Down
2 changes: 1 addition & 1 deletion pkg/maker/contextlists.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (m *Maker) CreateContextCMakeLists(index int) error {
# Roots
include("../roots.cmake")

set(CONTEXT ` + cbuild.BuildDescType.Context + `)
set(CONTEXT ` + strings.ReplaceAll(cbuild.BuildDescType.Context, " ", "_") + `)
set(TARGET ${CONTEXT})
set(OUT_DIR "` + outDir + `")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)` + outputByProducts + linkerVars + `
Expand Down
5 changes: 3 additions & 2 deletions pkg/maker/superlists.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path/filepath"
"regexp"
"strconv"
"strings"

"github.com/Open-CMSIS-Pack/cbuild2cmake/pkg/utils"
log "github.com/sirupsen/logrus"
Expand All @@ -23,7 +24,7 @@ func (m *Maker) CreateSuperCMakeLists() error {

var contexts, dirs, contextOutputs string
for i, cbuild := range m.Cbuilds {
contexts = contexts + " \"" + cbuild.BuildDescType.Context + "\"\n"
contexts = contexts + " \"" + strings.ReplaceAll(cbuild.BuildDescType.Context, " ", "_") + "\"\n"
dirs = dirs + " \"${CMAKE_CURRENT_SOURCE_DIR}/" + cbuild.BuildDescType.Context + "\"\n"

var contextOutputsName = "OUTPUTS_" + strconv.Itoa(i+1)
Expand Down Expand Up @@ -61,7 +62,7 @@ func (m *Maker) CreateSuperCMakeLists() error {

// Write content
content :=
`cmake_minimum_required(VERSION 3.22)
`cmake_minimum_required(VERSION 3.27)
include(ExternalProject)

project("` + csolution + `" NONE)
Expand Down
6 changes: 6 additions & 0 deletions test/data/solutions/blanks/project/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "RTE_Components.h"
#include CMSIS_device_header

int main(void) {
return 0;
}
120 changes: 120 additions & 0 deletions test/data/solutions/blanks/project/project X.AC6 X+ARMCM0 X.cbuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
build:
generated-by: csolution version 0.0.0
solution: ../solution.csolution.yml
project: project X.cproject.yml
context: project X.AC6 X+ARMCM0 X
compiler: AC6
device: ARMCM0
device-pack: ARM::Cortex_DFP@1.1.0
processor:
fpu: off
core: Cortex-M0
packs:
- pack: ARM::CMSIS@6.1.0
path: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0
- pack: ARM::Cortex_DFP@1.1.0
path: ${CMSIS_PACK_ROOT}/ARM/Cortex_DFP/1.1.0
misc:
ASM:
- -masm=auto
C:
- -std=gnu11
- -Wno-macro-redefined
- -Wno-pragma-pack
- -Wno-parentheses-equality
- -Wno-license-management
CPP:
- -Wno-macro-redefined
- -Wno-pragma-pack
- -Wno-parentheses-equality
- -Wno-license-management
Link:
- --entry=Reset_Handler
- --map
- --info summarysizes
- --summary_stderr
- --diag_suppress=L6314W
define:
- ARMCM0
- _RTE_
define-asm:
- ARMCM0
- _RTE_
add-path:
- RTE/_AC6_X_ARMCM0_X
- ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Include
- ${CMSIS_PACK_ROOT}/ARM/Cortex_DFP/1.1.0/Device/ARMCM0/Include
add-path-asm:
- RTE/_AC6_X_ARMCM0_X
- ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Include
- ${CMSIS_PACK_ROOT}/ARM/Cortex_DFP/1.1.0/Device/ARMCM0/Include
output-dirs:
intdir: ../tmp
outdir: ../out/project X/ARMCM0 X/AC6 X
rtedir: RTE
output:
- type: elf
file: project X.axf
components:
- component: ARM::CMSIS:CORE@6.1.0
condition: ARMv6_7_8-M Device
from-pack: ARM::CMSIS@6.1.0
selected-by: ARM::CMSIS:CORE
files:
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Include
category: include
version: 6.1.0
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Include/tz_context.h
category: header
version: 6.1.0
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Template/ARMv8-M/main_s.c
category: sourceC
attr: template
version: 1.1.1
select: Secure mode 'main' module for ARMv8-M
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Template/ARMv8-M/tz_context.c
category: sourceC
attr: template
version: 1.1.1
select: RTOS Context Management (TrustZone for ARMv8-M)
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Documentation/html/Core/index.html
category: doc
version: 6.1.0
- component: ARM::Device:Startup&C Startup@2.2.0
condition: ARMCM0 CMSIS
from-pack: ARM::Cortex_DFP@1.1.0
selected-by: ARM::Device:Startup&C Startup
files:
- file: ${CMSIS_PACK_ROOT}/ARM/Cortex_DFP/1.1.0/Device/ARMCM0/Include/ARMCM0.h
category: header
version: 2.2.0
- file: RTE/Device/ARMCM0/ARMCM0_ac6.sct
category: linkerScript
attr: config
version: 1.0.0
- file: RTE/Device/ARMCM0/startup_ARMCM0.c
category: sourceC
attr: config
version: 2.0.3
- file: RTE/Device/ARMCM0/system_ARMCM0.c
category: sourceC
attr: config
version: 1.0.0
linker:
script: RTE/Device/ARMCM0/ARMCM0_ac6.sct
groups:
- group: Source
files:
- file: main.c
category: sourceC
constructed-files:
- file: RTE/_AC6_X_ARMCM0_X/RTE_Components.h
category: header
licenses:
- license: Apache-2.0
packs:
- pack: ARM::CMSIS@6.1.0
- pack: ARM::Cortex_DFP@1.1.0
components:
- component: ARM::CMSIS:CORE@6.1.0
- component: ARM::Device:Startup&C Startup@2.2.0
10 changes: 10 additions & 0 deletions test/data/solutions/blanks/project/project X.cproject.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
project:

components:
- component: ARM::CMSIS:CORE
- component: ARM::Device:Startup&C Startup

groups:
- group: Source
files:
- file: ./main.c
66 changes: 66 additions & 0 deletions test/data/solutions/blanks/ref/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
cmake_minimum_required(VERSION 3.27)
include(ExternalProject)

project("solution" NONE)

# Roots
include("roots.cmake")

# Context specific lists
set(CONTEXTS
"project_X.AC6_X+ARMCM0_X"
)
list(LENGTH CONTEXTS CONTEXTS_LENGTH)
math(EXPR CONTEXTS_LENGTH "${CONTEXTS_LENGTH}-1")

set(DIRS
"${CMAKE_CURRENT_SOURCE_DIR}/project X.AC6 X+ARMCM0 X"
)

set(OUTPUTS_1
"${SOLUTION_ROOT}/out/project X/ARMCM0 X/AC6 X/project X.axf"
)


set(ARGS
"-DSOLUTION_ROOT=${SOLUTION_ROOT}"
"-DCMSIS_PACK_ROOT=${CMSIS_PACK_ROOT}"
"-DCMSIS_COMPILER_ROOT=${CMSIS_COMPILER_ROOT}"
)

# Iterate over contexts
foreach(INDEX RANGE ${CONTEXTS_LENGTH})

math(EXPR N "${INDEX}+1")
list(GET CONTEXTS ${INDEX} CONTEXT)
list(GET DIRS ${INDEX} DIR)

# Create external project, set configure and build steps
ExternalProject_Add(${CONTEXT}
PREFIX ${DIR}
SOURCE_DIR ${DIR}
BINARY_DIR ${N}
INSTALL_COMMAND ""
TEST_COMMAND ""
CONFIGURE_COMMAND ${CMAKE_COMMAND} -G Ninja -S <SOURCE_DIR> -B <BINARY_DIR> ${ARGS}
BUILD_COMMAND ${CMAKE_COMMAND} -E echo "Building CMake target '${CONTEXT}'"
COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --verbose
BUILD_ALWAYS TRUE
BUILD_BYPRODUCTS ${OUTPUTS_${N}}
USES_TERMINAL_BUILD ON
)
ExternalProject_Add_StepTargets(${CONTEXT} build configure)

# Debug
message(VERBOSE "Configure Context: ${CMAKE_COMMAND} -G Ninja -S ${DIR} -B ${N}")

# Database generation step
ExternalProject_Add_Step(${CONTEXT} database
COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target database
EXCLUDE_FROM_MAIN TRUE
ALWAYS TRUE
DEPENDEES configure
)
ExternalProject_Add_StepTargets(${CONTEXT} database)

endforeach()
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
cmake_minimum_required(VERSION 3.27)

# Roots
include("../roots.cmake")

set(CONTEXT project_X.AC6_X+ARMCM0_X)
set(TARGET ${CONTEXT})
set(OUT_DIR "${SOLUTION_ROOT}/out/project X/ARMCM0 X/AC6 X")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(LD_SCRIPT "${SOLUTION_ROOT}/project/RTE/Device/ARMCM0/ARMCM0_ac6.sct")
set(LD_SCRIPT_PP ${LD_SCRIPT})

# Processor Options
set(CPU Cortex-M0)
set(FPU NO_FPU)

# Toolchain config map
include("toolchain.cmake")

# Setup project
project(${CONTEXT} LANGUAGES C)

# Compilation database
add_custom_target(database
COMMAND ${CMAKE_COMMAND} -E make_directory "${OUT_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json" "${OUT_DIR}"
)
set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES})

# Setup context
add_executable(${CONTEXT})
set_target_properties(${CONTEXT} PROPERTIES PREFIX "" SUFFIX ".axf" OUTPUT_NAME "project X")
set_target_properties(${CONTEXT} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${OUT_DIR})
add_library(${CONTEXT}_GLOBAL INTERFACE)

# Includes
target_include_directories(${CONTEXT} PUBLIC
${SOLUTION_ROOT}/project/RTE/_AC6_X_ARMCM0_X
${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Include
${CMSIS_PACK_ROOT}/ARM/Cortex_DFP/1.1.0/Device/ARMCM0/Include
)

# Defines
target_compile_definitions(${CONTEXT} PUBLIC
$<$<COMPILE_LANGUAGE:C,CXX>:
ARMCM0
_RTE_
>
)

# Compile options
target_compile_options(${CONTEXT} PUBLIC
$<$<COMPILE_LANGUAGE:C>:
"SHELL:${CC_CPU}"
"SHELL:${CC_FLAGS}"
"SHELL:-std=gnu11"
"SHELL:-Wno-macro-redefined"
"SHELL:-Wno-pragma-pack"
"SHELL:-Wno-parentheses-equality"
"SHELL:-Wno-license-management"
>
)

# Add groups and components
include("groups.cmake")
include("components.cmake")

target_link_libraries(${CONTEXT} PUBLIC
Group_Source
ARM_CMSIS_CORE_6_1_0
ARM_Device_Startup_C_Startup_2_2_0
)

# Linker options
target_link_options(${CONTEXT} PUBLIC
"SHELL:${LD_CPU}"
"SHELL:${_LS}\"${LD_SCRIPT_PP}\""
"SHELL:--entry=Reset_Handler"
"SHELL:--map"
"SHELL:--info summarysizes"
"SHELL:--summary_stderr"
"SHELL:--diag_suppress=L6314W"
)
set_target_properties(${CONTEXT} PROPERTIES LINK_DEPENDS ${LD_SCRIPT})
11 changes: 11 additions & 0 deletions test/data/solutions/blanks/solution.cbuild-idx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
build-idx:
generated-by: csolution version 0.0.0
cdefault: ${CMSIS_COMPILER_ROOT}/cdefault.yml
csolution: solution.csolution.yml
tmpdir: tmp
cprojects:
- cproject: project/project X.cproject.yml
cbuilds:
- cbuild: project/project X.AC6 X+ARMCM0 X.cbuild.yml
project: project X
configuration: .AC6 X+ARMCM0 X
18 changes: 18 additions & 0 deletions test/data/solutions/blanks/solution.csolution.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
solution:
created-for: CMSIS-Toolbox@2.6.0
cdefault:

packs:
- pack: ARM::Cortex_DFP
- pack: ARM::CMSIS

target-types:
- type: ARMCM0 X
device: ARMCM0

build-types:
- type: AC6 X
compiler: AC6

projects:
- project: ./project/project X.cproject.yml