Skip to content

Commit

Permalink
🧑‍💻 Make platform files optional
Browse files Browse the repository at this point in the history
If they do not exist, they will simply be excluded from the list of
start up files for demo builds.
  • Loading branch information
Khalil Estell authored and kammce committed Dec 14, 2023
1 parent b70cdec commit fe91be9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions cmake/build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,21 @@ function(libhal_build_demos)
"must be defined. Make sure you are using the correct profile!")
endif()

set(platform_link_library libhal::$ENV{LIBHAL_PLATFORM_LIBRARY})

find_package(libhal-$ENV{LIBHAL_PLATFORM_LIBRARY} REQUIRED)

foreach(PACKAGE ${DEMO_ARGS_PACKAGES})
find_package(${PACKAGE} REQUIRED)
endforeach()

add_library(startup_code
main.cpp
platforms/$ENV{LIBHAL_PLATFORM}.cpp
${DEMO_ARGS_SOURCES})
set(startup_source_files main.cpp ${DEMO_ARGS_SOURCES})

# Makes the platform/<platform_name>.cpp file optional
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/platforms/$ENV{LIBHAL_PLATFORM}.cpp")
list(APPEND startup_source_files platforms/$ENV{LIBHAL_PLATFORM}.cpp)
endif()

add_library(startup_code ${startup_source_files})

target_compile_features(startup_code PRIVATE cxx_std_20)
target_include_directories(startup_code PUBLIC ${DEMO_ARGS_INCLUDES})
target_compile_options(startup_code PRIVATE
Expand All @@ -250,7 +253,7 @@ function(libhal_build_demos)
)
target_link_libraries(startup_code PRIVATE
${DEMO_ARGS_LINK_LIBRARIES}
${platform_link_library}
libhal::$ENV{LIBHAL_PLATFORM_LIBRARY}
)

if(NOT ${DEMO_ARGS_DISABLE_CLANG_TIDY})
Expand All @@ -273,7 +276,7 @@ function(libhal_build_demos)
target_link_libraries(${elf} PRIVATE
startup_code
${DEMO_ARGS_LINK_LIBRARIES}
${platform_link_library}
libhal::$ENV{LIBHAL_PLATFORM_LIBRARY}
)

if(${CMAKE_CROSSCOMPILING})
Expand Down
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

class libhal_cmake_util_conan(ConanFile):
name = "libhal-cmake-util"
version = "4.0.0"
version = "4.0.1"
license = "Apache-2.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://libhal.github.io/libhal-armcortex"
Expand Down

0 comments on commit fe91be9

Please sign in to comment.