Skip to content

Commit

Permalink
Added logic for selecting which board to compile
Browse files Browse the repository at this point in the history
  • Loading branch information
bsutherland333 committed Jan 3, 2024
1 parent 8be7e65 commit 9887a07
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
18 changes: 9 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()

add_compile_options(-Wall)


### git ###

# clone mavlink submodule if it is missing
Expand Down Expand Up @@ -41,7 +38,6 @@ if("${GIT_VERSION_HASH}" STREQUAL "")
set(GIT_VERSION_HASH "0")
endif()


### source files ###

include_directories(
Expand All @@ -60,13 +56,17 @@ file(GLOB_RECURSE ROSFLIGHT_SOURCES
"comms/mavlink/mavlink.cpp"
)


### select boards to compile ###

option(BUILD_VARMINT "Build the varmint board target" ON)
option(BUILD_VARMINT "Build the varmint board target" OFF)
option(BUILD_TEST "Build the test board target" OFF)

if(BUILD_VARMINT)
message(STATUS "Selecting varmint board target")
message("===== Selecting varmint board target. =====")
add_subdirectory(boards/varmint)
endif()

elseif(BUILD_TEST)
message("===== Selecting test board target. ======")
# add_subdirectory()
else()
message(FATAL_ERROR "No board selected! Please select the varmint or test board with -DBUILD_VARMINT=true or -DBUILD_TEST=true.")
endif ()
2 changes: 1 addition & 1 deletion boards/varmint
26 changes: 18 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,22 @@
******************************************************************************
**/

#include <Varmint.h>
#include <mavlink.h>
#include <rosflight.h>

extern Varmint varmint;
// Select which board implementation to include based on cmake variable
#ifdef BUILD_VARMINT_BOARD
#include <Varmint.h>
extern Varmint varmint; // TODO: Eliminate global variable
#endif
#ifdef BUILD_TEST_BOARD
#include <test.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

int main(void);

#ifdef __cplusplus
}
#endif
Expand All @@ -57,12 +61,18 @@ int main(void);
*/
int main(void)
{
// Rosflight board code
varmint.init_board();
// Select which board implementation to instantiate based on cmake variable
#ifdef BUILD_VARMINT_BOARD
rosflight_firmware::Board * board = &varmint;
#endif
#ifdef BUILD_TEST_BOARD
return 0;
#endif

// Rosflight base code
rosflight_firmware::Mavlink mavlink(varmint);
rosflight_firmware::ROSflight firmware(varmint, mavlink);
board->init_board();
rosflight_firmware::Mavlink mavlink(* board);
rosflight_firmware::ROSflight firmware(* board, mavlink);

firmware.init();

Expand Down

0 comments on commit 9887a07

Please sign in to comment.