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

CMake: Fix generation with multiple repos #1140

Merged
merged 6 commits into from
Mar 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
5 changes: 5 additions & 0 deletions tools/build_script_generator/cmake/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def post_build(env):
files = []
per_file_attr = []
repo_filter = lambda scope: scope.repository == repo
inv_repo_filter = lambda scope: scope.repository != repo
repo_flags = env.query("::collect_flags")(env, repo_filter)

warning_pattern = re.compile("^-W")
Expand Down Expand Up @@ -174,6 +175,9 @@ def post_build(env):
files.append( (sfile, profiles) )

include_paths = env.collector_values("::path.include", filterfunc=repo_filter)
private_include_paths = env.collector_values(
"::path.include", filterfunc=inv_repo_filter
)
libary_paths = env.collector_values("::path.library", filterfunc=repo_filter)
libaries = env.collector_values("::library", filterfunc=repo_filter)
packages = env.collector_values("::pkg-config", filterfunc=repo_filter)
Expand All @@ -188,6 +192,7 @@ def post_build(env):
"libraries": libaries,
"library_paths": libary_paths,
"include_paths": include_paths,
"private_include_paths": private_include_paths,
"packages": packages,
"is_modm": repo == "modm",
"per_file_attr": file_attrs,
Expand Down
36 changes: 31 additions & 5 deletions tools/build_script_generator/cmake/resources/CMakeLists.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
# This file was autogenerated by the modm cmake builder. Do not modify!

cmake_minimum_required(VERSION 3.15)
%% if is_modm
include(cmake/ModmConfiguration.cmake)
%% endif


%% if asm_sources | length
set_source_files_properties(
Expand All @@ -22,12 +25,13 @@ set_source_files_properties(
%% endif

%% if sources | length
add_library(modm OBJECT
add_library({{ repo }} OBJECT
%% for file, flags in sources | sort
{{ file | relocate | modm.posixify }}
%% endfor
)

%% else
add_library({{ repo }} INTERFACE )
%% endif

%% if per_file_attr | length
Expand All @@ -37,25 +41,47 @@ add_library(modm OBJECT

%% endif

%% if is_modm
add_library(modm_warnings INTERFACE)
add_library(modm_options INTERFACE)
add_library(modm_arch_options INTERFACE)

modm_target_config_create(modm modm_arch_options modm_options modm_warnings)
%% endif
salkinium marked this conversation as resolved.
Show resolved Hide resolved

%% if include_paths | length
target_include_directories(modm SYSTEM PUBLIC
target_include_directories({{ repo }} SYSTEM
%% if sources | length
PUBLIC
%% else
INTERFACE
%% endif
%% for path in include_paths | sort
{{ path | relocate | modm.posixify }}
%% endfor
%% if sources | length
PRIVATE
%% for path in private_include_paths | sort
{{ path | relocate | modm.posixify }}
%% endfor
%% endif
)

%% endif

target_link_libraries(modm


target_link_libraries({{ repo }}
%% if sources | length
PUBLIC
%% else
INTERFACE
%%endif
modm_arch_options
%% if sources | length
PRIVATE
project_options
modm_options
modm_warnings)
modm_warnings
%% endif
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

# This file was autogenerated by the modm cmake builder. Do not modify!

find_program(PYTHON3_EXECUTABLE python3 REQUIRED)

# This function will prevent in-source builds
function(assure_out_of_source_builds)
# make sure the user doesn't play dirty with symlinks
Expand Down Expand Up @@ -164,6 +162,8 @@ set({{ name | upper }}{{ "_" ~ (profile | upper) if profile | length else "" }}
endfunction()

function(modm_targets_create project_name)
find_package(Python3 COMPONENTS Interpreter REQUIRED)

set_target_properties(${project_name}
PROPERTIES SUFFIX ".elf")

Expand All @@ -175,132 +175,132 @@ function(modm_targets_create project_name)
%% if core.startswith("cortex-m")
add_custom_command(TARGET ${project_name}
POST_BUILD
COMMAND PYTHONPATH=${PROJECT_SOURCE_DIR}/modm ${PYTHON3_EXECUTABLE} -m modm_tools.size ${project_name}.elf \"{{ memories }}\")
COMMAND cmake -E env PYTHONPATH=${PROJECT_SOURCE_DIR}/modm ${Python3_EXECUTABLE} -m modm_tools.size ${project_name}.elf \"{{ memories }}\")
%% endif

add_custom_target(size DEPENDS ${project_name}.elf)
add_custom_command(TARGET size
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.size ${PROJECT_BINARY_DIR}/src/${project_name}.elf \"{{ memories }}\"
COMMAND cmake -E env PYTHONPATH=modm ${Python3_EXECUTABLE} -m modm_tools.size ${PROJECT_BINARY_DIR}/src/${project_name}.elf \"{{ memories }}\"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(program DEPENDS ${project_name}.elf)
add_custom_command(TARGET program
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.openocd -f modm/openocd.cfg
COMMAND cmake -E env PYTHONPATH=modm ${Python3_EXECUTABLE} -m modm_tools.openocd -f modm/openocd.cfg
${PROJECT_BINARY_DIR}/src/${project_name}.elf
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(program-bmp DEPENDS ${project_name}.elf)
add_custom_command(TARGET program-bmp
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.bmp -p ${MODM_BMP_PORT}
COMMAND cmake -E env PYTHONPATH=modm ${Python3_EXECUTABLE} -m modm_tools.bmp -p ${MODM_BMP_PORT}
${PROJECT_BINARY_DIR}/src/${project_name}.elf
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(program-jlink DEPENDS ${project_name}.elf)
add_custom_command(TARGET program-jlink
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.jlink -device {{ jlink_partname }}
COMMAND cmake -E env PYTHONPATH=modm ${Python3_EXECUTABLE} -m modm_tools.jlink -device {{ jlink_partname }}
${PROJECT_BINARY_DIR}/src/${project_name}.elf
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(debug DEPENDS ${project_name}.elf)
add_custom_command(TARGET debug
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.gdb -x modm/gdbinit -x modm/openocd_gdbinit
COMMAND cmake -E env PYTHONPATH=modm ${Python3_EXECUTABLE} -m modm_tools.gdb -x modm/gdbinit -x modm/openocd_gdbinit
--elf ${PROJECT_BINARY_DIR}/src/${project_name}.elf --ui=${MODM_DBG_UI}
openocd -f modm/openocd.cfg
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(debug-bmp DEPENDS ${project_name}.elf)
add_custom_command(TARGET debug-bmp
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.gdb -x modm/gdbinit -x modm/openocd_bmp
COMMAND cmake -E env PYTHONPATH=modm ${Python3_EXECUTABLE} -m modm_tools.gdb -x modm/gdbinit -x modm/openocd_bmp
--elf ${PROJECT_BINARY_DIR}/src/${project_name}.elf --ui=${MODM_DBG_UI}
bmp -p ${MODM_BMP_PORT}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(debug-jlink DEPENDS ${project_name}.elf)
add_custom_command(TARGET debug-jlink
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.gdb -x modm/gdbinit -x modm/openocd_jlink
COMMAND cmake -E env PYTHONPATH=modm ${Python3_EXECUTABLE} -m modm_tools.gdb -x modm/gdbinit -x modm/openocd_jlink
--elf ${PROJECT_BINARY_DIR}/src/${project_name}.elf --ui=${MODM_DBG_UI}
jlink -device {{ jlink_partname }}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(debug-coredump DEPENDS ${project_name}.elf)
add_custom_command(TARGET debug-coredump
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.gdb -x modm/gdbinit
COMMAND cmake -E env PYTHONPATH=modm ${Python3_EXECUTABLE} -m modm_tools.gdb -x modm/gdbinit
--elf ${PROJECT_BINARY_DIR}/src/${project_name}.elf --ui=${MODM_DBG_UI}
crashdebug
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(coredump)
add_custom_command(TARGET coredump
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.gdb -x modm/gdbinit
COMMAND cmake -E env PYTHONPATH=modm ${Python3_EXECUTABLE} -m modm_tools.gdb -x modm/gdbinit
-ex "modm_coredump" -ex "modm_build_id" -ex "quit"
openocd -f modm/openocd.cfg
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(coredump-bmp)
add_custom_command(TARGET coredump-bmp
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.gdb -x modm/gdbinit
COMMAND cmake -E env PYTHONPATH=modm ${Python3_EXECUTABLE} -m modm_tools.gdb -x modm/gdbinit
-ex "modm_coredump" -ex "modm_build_id" -ex "quit"
bmp -p ${MODM_BMP_PORT}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(coredump-jlink)
add_custom_command(TARGET coredump-jlink
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.gdb -x modm/gdbinit
COMMAND cmake -E env PYTHONPATH=modm ${Python3_EXECUTABLE} -m modm_tools.gdb -x modm/gdbinit
-ex "modm_coredump" -ex "modm_build_id" -ex "quit"
jlink -device {{ jlink_partname }}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(reset)
add_custom_command(TARGET reset
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.openocd -f modm/openocd.cfg --reset
COMMAND cmake -E env PYTHONPATH=modm ${Python3_EXECUTABLE} -m modm_tools.openocd -f modm/openocd.cfg --reset
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(reset-bmp)
add_custom_command(TARGET reset-bmp
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.bmp -p ${MODM_BMP_PORT} --reset
COMMAND cmake -E env PYTHONPATH=modm ${Python3_EXECUTABLE} -m modm_tools.bmp -p ${MODM_BMP_PORT} --reset
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(reset-jlink)
add_custom_command(TARGET reset-jlink
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.jlink -device {{ jlink_partname }} --reset
COMMAND cmake -E env PYTHONPATH=modm ${Python3_EXECUTABLE} -m modm_tools.jlink -device {{ jlink_partname }} --reset
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(log-itm)
add_custom_command(TARGET log-itm
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.itm openocd -f modm/openocd.cfg --fcpu ${MODM_ITM_FCPU}
COMMAND cmake -E env PYTHONPATH=modm ${Python3_EXECUTABLE} -m modm_tools.itm openocd -f modm/openocd.cfg --fcpu ${MODM_ITM_FCPU}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(log-itm-jlink)
add_custom_command(TARGET log-itm-jlink
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.itm jlink -device {{ jlink_partname }}
COMMAND cmake -E env PYTHONPATH=modm ${Python3_EXECUTABLE} -m modm_tools.itm jlink -device {{ jlink_partname }}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(log-rtt)
add_custom_command(TARGET log-rtt
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.rtt --channel ${MODM_RTT_CHANNEL} openocd -f modm/openocd.cfg
COMMAND cmake -E env PYTHONPATH=modm ${Python3_EXECUTABLE} -m modm_tools.rtt --channel ${MODM_RTT_CHANNEL} openocd -f modm/openocd.cfg
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(log-rtt-jlink)
add_custom_command(TARGET log-rtt-jlink
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.rtt --channel ${MODM_RTT_CHANNEL} jlink -device {{ jlink_partname }}
COMMAND cmake -E env PYTHONPATH=modm ${Python3_EXECUTABLE} -m modm_tools.rtt --channel ${MODM_RTT_CHANNEL} jlink -device {{ jlink_partname }}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
endfunction()

Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

add_library(project_options INTERFACE)

# Compile modm
add_subdirectory(modm)
# Compile libraries
%% for repo in generated_paths | sort
add_subdirectory({{ repo }})
%% endfor

# Find application sources: Never do this, file changes are not detected by make.
file(GLOB APP_SOURCE_FILES *.c *.cpp */*.c */*.cpp)
Expand All @@ -57,9 +59,11 @@ add_executable(${CMAKE_PROJECT_NAME} ${APP_SOURCE_FILES})
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC include)

target_link_libraries(${CMAKE_PROJECT_NAME}
%% for repo in generated_paths | sort
{{ repo }}
%% endfor
modm_options
modm_warnings
modm)
modm_warnings)

# Outputs hex and bin files.
modm_targets_create(${CMAKE_PROJECT_NAME})