Skip to content

Commit

Permalink
Abstract out CAN Gen from CMAkeLists (#187)
Browse files Browse the repository at this point in the history
* Abstract out CAN Gen from CMAkeLists

* Add add_dependencies(main generated_can) to .cmake file
  • Loading branch information
Jinwoo-H authored Sep 16, 2024
1 parent 416da58 commit 38d3e51
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 189 deletions.
26 changes: 26 additions & 0 deletions firmware/cmake/cangen.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
find_package(Python3 COMPONENTS Interpreter)
message(${Python3_EXECUTABLE})

if(NOT ${Python3_FOUND})
message(FATAL_ERROR "Python 3 executable not found")
endif()

FILE(GLOB_RECURSE CAN_DEPENDENCIES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/../scripts/cangen/*" "${CMAKE_SOURCE_DIR}/dbcs/*")

list(APPEND CAN_DEPENDENCIES "${CMAKE_CURRENT_SOURCE_DIR}/config.yaml")

cmake_language(GET_MESSAGE_LOG_LEVEL LOG_LEVEL)

add_custom_target(
generated_can
COMMAND ${Python3_EXECUTABLE} "${CMAKE_SOURCE_DIR}/../scripts/cangen/main.py" "--project=\"${CMAKE_CURRENT_SOURCE_DIR}\"" "--log-level=${LOG_LEVEL}"
DEPENDS ${CAN_DEPENDENCIES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT Generating CAN code from DBCs
)

add_dependencies(main generated_can)

# Link ETL which is needed for generated/can/msg_registry.h
add_subdirectory(${CMAKE_SOURCE_DIR}/third-party/etl ${CMAKE_BINARY_DIR}/third-party)
target_link_libraries(main PRIVATE etl)
25 changes: 1 addition & 24 deletions firmware/projects/Demo/CAN/Bar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,17 @@
# The target executable 'main' is created in the master CMakeLists. Do not change its name.
# We only need to add the source code files and include directories.

find_package(Python3 COMPONENTS Interpreter)
message(${Python3_EXECUTABLE})

if(NOT ${Python3_FOUND})
message(FATAL_ERROR "Python 3 executable not found")
endif()

FILE(GLOB_RECURSE CAN_DEPENDENCIES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/../scripts/cangen/*" "${CMAKE_SOURCE_DIR}/dbcs/*")

list(APPEND CAN_DEPENDENCIES "${CMAKE_CURRENT_SOURCE_DIR}/config.yaml")

add_custom_target(
generated_can
COMMAND ${Python3_EXECUTABLE} "${CMAKE_SOURCE_DIR}/../scripts/cangen/main.py" "--project=\"Demo/CAN/Bar\""
DEPENDS ${CAN_DEPENDENCIES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT Generating CAN code from DBCs
)
include("${CMAKE_SOURCE_DIR}/cmake/cangen.cmake")

target_sources(main
PRIVATE
main.cc
)
add_dependencies(main generated_can)


target_include_directories(main
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/inc
)

# Link ETL which is needed for generated/can/msg_registry.h
add_subdirectory(${CMAKE_SOURCE_DIR}/third-party/etl ${CMAKE_BINARY_DIR}/third-party)
target_link_libraries(main PRIVATE etl)

# Notice that we don't include any mcal/ subdirectory in this CMake file.
# The master CMakeLists handles platform selection and library linking.
25 changes: 1 addition & 24 deletions firmware/projects/Demo/CAN/Foo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,17 @@
# The target executable 'main' is created in the master CMakeLists. Do not change its name.
# We only need to add the source code files and include directories.

find_package(Python3 COMPONENTS Interpreter)
message(${Python3_EXECUTABLE})

if(NOT ${Python3_FOUND})
message(FATAL_ERROR "Python 3 executable not found")
endif()

FILE(GLOB_RECURSE CAN_DEPENDENCIES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/../scripts/cangen/*" "${CMAKE_SOURCE_DIR}/dbcs/*")

list(APPEND CAN_DEPENDENCIES "${CMAKE_CURRENT_SOURCE_DIR}/config.yaml")

add_custom_target(
generated_can
COMMAND ${Python3_EXECUTABLE} "${CMAKE_SOURCE_DIR}/../scripts/cangen/main.py" "--project=\"Demo/CAN/Foo\""
DEPENDS ${CAN_DEPENDENCIES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT Generating CAN code from DBCs
)
include("${CMAKE_SOURCE_DIR}/cmake/cangen.cmake")

target_sources(main
PRIVATE
main.cc
)
add_dependencies(main generated_can)


target_include_directories(main
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/inc
)

# Link ETL which is needed for generated/can/msg_registry.h
add_subdirectory(${CMAKE_SOURCE_DIR}/third-party/etl ${CMAKE_BINARY_DIR}/third-party)
target_link_libraries(main PRIVATE etl)

# Notice that we don't include any mcal/ subdirectory in this CMake file.
# The master CMakeLists handles platform selection and library linking.
23 changes: 1 addition & 22 deletions firmware/projects/EV5/FrontController/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,12 @@
# The target executable 'main' is created in the master CMakeLists. Do not change its name.
# We only need to add the source code files and include directories.

find_package(Python3 COMPONENTS Interpreter)
message(${Python3_EXECUTABLE})

if(NOT ${Python3_FOUND})
message(FATAL_ERROR "Python 3 executable not found")
endif()

FILE(GLOB_RECURSE CAN_DEPENDENCIES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/../scripts/cangen/*" "${CMAKE_SOURCE_DIR}/dbcs/*")

list(APPEND CAN_DEPENDENCIES "${CMAKE_CURRENT_SOURCE_DIR}/config.yaml")

add_custom_target(
generated_can
COMMAND ${Python3_EXECUTABLE} "${CMAKE_SOURCE_DIR}/../scripts/cangen/main.py" "--project=\"EV5/FrontController\""
DEPENDS ${CAN_DEPENDENCIES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT Generating CAN code from DBCs
)
include("${CMAKE_SOURCE_DIR}/cmake/cangen.cmake")

target_sources(main
PRIVATE
main.cc
)
add_dependencies(main generated_can)

target_include_directories(main
PRIVATE
Expand All @@ -52,9 +34,6 @@ PUBLIC

target_link_libraries(main PUBLIC controls)

# Link ETL which is needed for generated/can/msg_registry.h
add_subdirectory(${CMAKE_SOURCE_DIR}/third-party/etl ${CMAKE_BINARY_DIR}/third-party)
target_link_libraries(main PRIVATE etl)

# Notice that we don't include any mcal/ subdirectory in this CMake file.
# The master CMakeLists handles platform selection and library linking.
29 changes: 2 additions & 27 deletions firmware/projects/EV5/LVController/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,12 @@
# The target executable 'main' is created in the master CMakeLists. Do not change its name.
# We only need to add the source code files and include directories.

find_package(Python3 COMPONENTS Interpreter)
message(${Python3_EXECUTABLE})

if(NOT ${Python3_FOUND})
message(FATAL_ERROR "Python 3 executable not found")
endif()

FILE(GLOB_RECURSE CAN_DEPENDENCIES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/../scripts/cangen/*" "${CMAKE_SOURCE_DIR}/dbcs/*")

list(APPEND CAN_DEPENDENCIES "${CMAKE_CURRENT_SOURCE_DIR}/config.yaml")

cmake_language(GET_MESSAGE_LOG_LEVEL LOG_LEVEL)

add_custom_target(
generated_can
COMMAND ${Python3_EXECUTABLE} "${CMAKE_SOURCE_DIR}/../scripts/cangen/main.py" "--project=\"EV5/LVController\"" "--log-level=${LOG_LEVEL}"
DEPENDS ${CAN_DEPENDENCIES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT Generating CAN code from DBCs
)

# Link ETL which is needed for generated/can/msg_registry.h
add_subdirectory(${CMAKE_SOURCE_DIR}/third-party/etl ${CMAKE_BINARY_DIR}/third-party)
target_link_libraries(main PRIVATE etl)
include("${CMAKE_SOURCE_DIR}/cmake/cangen.cmake")

target_sources(main
PRIVATE
PRIVATE
main.cc
)
add_dependencies(main generated_can)


target_include_directories(main
PRIVATE
Expand Down
24 changes: 1 addition & 23 deletions firmware/projects/EV5/TMS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,7 @@
# The target executable 'main' is created in the master CMakeLists. Do not change its name.
# We only need to add the source code files and include directories.

find_package(Python3 COMPONENTS Interpreter)
message(${Python3_EXECUTABLE})

if(NOT ${Python3_FOUND})
message(FATAL_ERROR "Python 3 executable not found")
endif()

FILE(GLOB_RECURSE CAN_DEPENDENCIES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/../scripts/cangen/*" "${CMAKE_SOURCE_DIR}/dbcs/*")

list(APPEND CAN_DEPENDENCIES "${CMAKE_CURRENT_SOURCE_DIR}/config.yaml")

add_custom_target(
generated_can
COMMAND ${Python3_EXECUTABLE} "${CMAKE_SOURCE_DIR}/../scripts/cangen/main.py" "--project=\"EV5/TMS\""
DEPENDS ${CAN_DEPENDENCIES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT Generating CAN code from DBCs
)
include("${CMAKE_SOURCE_DIR}/cmake/cangen.cmake")

target_sources(main
PRIVATE
Expand All @@ -33,11 +16,6 @@ target_include_directories(main
${CMAKE_CURRENT_SOURCE_DIR}/inc
${CMAKE_CURRENT_SOURCE_DIR}/generated/can
)
add_dependencies(main generated_can)

# Link ETL which is needed for generated/can/msg_registry.h
add_subdirectory(${CMAKE_SOURCE_DIR}/third-party/etl ${CMAKE_BINARY_DIR}/third-party)
target_link_libraries(main PRIVATE etl)

# Notice that we don't include any mcal/ subdirectory in this CMake file.
# The master CMakeLists handles platform selection and library linking.
24 changes: 1 addition & 23 deletions firmware/projects/EV5/debug/FrontControllerSimple/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,12 @@
# The target executable 'main' is created in the master CMakeLists. Do not change its name.
# We only need to add the source code files and include directories.

find_package(Python3 COMPONENTS Interpreter)
message(${Python3_EXECUTABLE})

if(NOT ${Python3_FOUND})
message(FATAL_ERROR "Python 3 executable not found")
endif()

FILE(GLOB_RECURSE CAN_DEPENDENCIES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/../scripts/cangen/*" "${CMAKE_SOURCE_DIR}/dbcs/*")

list(APPEND CAN_DEPENDENCIES "${CMAKE_CURRENT_SOURCE_DIR}/config.yaml")

add_custom_target(
generated_can
COMMAND ${Python3_EXECUTABLE} "${CMAKE_SOURCE_DIR}/../scripts/cangen/main.py" "--project=\"EV5/debug/FrontControllerSimple\""
DEPENDS ${CAN_DEPENDENCIES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT Generating CAN code from DBCs
)
include("${CMAKE_SOURCE_DIR}/cmake/cangen.cmake")

target_sources(main
PRIVATE
main.cc
)
add_dependencies(main generated_can)

target_include_directories(main
PRIVATE
Expand All @@ -52,9 +34,5 @@ PUBLIC

target_link_libraries(main PUBLIC controls)

# Link ETL which is needed for generated/can/msg_registry.h
add_subdirectory(${CMAKE_SOURCE_DIR}/third-party/etl ${CMAKE_BINARY_DIR}/third-party)
target_link_libraries(main PRIVATE etl)

# Notice that we don't include any mcal/ subdirectory in this CMake file.
# The master CMakeLists handles platform selection and library linking.
24 changes: 1 addition & 23 deletions firmware/projects/EV5/debug/IoCheckoutFc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,17 @@
# The target executable 'main' is created in the master CMakeLists. Do not change its name.
# We only need to add the source code files and include directories.

find_package(Python3 COMPONENTS Interpreter)
message(${Python3_EXECUTABLE})

if(NOT ${Python3_FOUND})
message(FATAL_ERROR "Python 3 executable not found")
endif()

FILE(GLOB_RECURSE CAN_DEPENDENCIES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/../scripts/cangen/*" "${CMAKE_SOURCE_DIR}/dbcs/*")

list(APPEND CAN_DEPENDENCIES "${CMAKE_CURRENT_SOURCE_DIR}/config.yaml")

add_custom_target(
generated_can
COMMAND ${Python3_EXECUTABLE} "${CMAKE_SOURCE_DIR}/../scripts/cangen/main.py" "--project=\"EV5/debug/IoCheckoutFc\""
DEPENDS ${CAN_DEPENDENCIES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT Generating CAN code from DBCs
)
include("${CMAKE_SOURCE_DIR}/cmake/cangen.cmake")

target_sources(main
PRIVATE
main.cc
)
add_dependencies(main generated_can)

target_include_directories(main
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/inc
)

# Link ETL which is needed for generated/can/msg_registry.h
add_subdirectory(${CMAKE_SOURCE_DIR}/third-party/etl ${CMAKE_BINARY_DIR}/third-party)
target_link_libraries(main PRIVATE etl)

# Notice that we don't include any mcal/ subdirectory in this CMake file.
# The master CMakeLists handles platform selection and library linking.
24 changes: 1 addition & 23 deletions firmware/projects/EV5/debug/MotorDebug/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,12 @@
# The target executable 'main' is created in the master CMakeLists. Do not change its name.
# We only need to add the source code files and include directories.

find_package(Python3 COMPONENTS Interpreter)
message(${Python3_EXECUTABLE})

if(NOT ${Python3_FOUND})
message(FATAL_ERROR "Python 3 executable not found")
endif()

FILE(GLOB_RECURSE CAN_DEPENDENCIES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/../scripts/cangen/*" "${CMAKE_SOURCE_DIR}/dbcs/*")

list(APPEND CAN_DEPENDENCIES "${CMAKE_CURRENT_SOURCE_DIR}/config.yaml")

add_custom_target(
generated_can
COMMAND ${Python3_EXECUTABLE} "${CMAKE_SOURCE_DIR}/../scripts/cangen/main.py" "--project=\"EV5/debug/MotorDebug\""
DEPENDS ${CAN_DEPENDENCIES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT Generating CAN code from DBCs
)
include("${CMAKE_SOURCE_DIR}/cmake/cangen.cmake")

target_sources(main
PRIVATE
main.cc
)
add_dependencies(main generated_can)

# Link ETL which is needed for generated/can/msg_registry.h
add_subdirectory(${CMAKE_SOURCE_DIR}/third-party/etl ${CMAKE_BINARY_DIR}/third-party)
target_link_libraries(main PRIVATE etl)

# Notice that we don't include any mcal/ subdirectory in this CMake file.
# The master CMakeLists handles platform selection and library linking.

0 comments on commit 38d3e51

Please sign in to comment.