make compilation better
This commit is contained in:
+26
-49
@@ -1,6 +1,13 @@
|
|||||||
cmake_minimum_required(VERSION 3.13)
|
cmake_minimum_required(VERSION 3.13)
|
||||||
|
|
||||||
option(BUILD_FOR_PICO "Build for Raspberry Pi Pico" ON)
|
set(BUILD_PLATFORM "Linux" CACHE STRING "Target platform: Pico or Linux")
|
||||||
|
set_property(CACHE BUILD_PLATFORM PROPERTY STRINGS Pico Linux)
|
||||||
|
|
||||||
|
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/platform_${BUILD_PLATFORM}_pre.cmake")
|
||||||
|
message(FATAL_ERROR "Unknown BUILD_PLATFORM '${BUILD_PLATFORM}' (no cmake/platform_${BUILD_PLATFORM}_pre.cmake found)")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
string(TOLOWER ${BUILD_PLATFORM} BUILD_PLATFORM_LOWER)
|
||||||
|
|
||||||
set(GEOGRAPHICLIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/geographiclib)
|
set(GEOGRAPHICLIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/geographiclib)
|
||||||
|
|
||||||
@@ -10,55 +17,25 @@ set(BUILD_DOCUMENTATION OFF CACHE BOOL "" FORCE)
|
|||||||
set(BUILD_BOTH_LIBRARIES OFF CACHE BOOL "" FORCE)
|
set(BUILD_BOTH_LIBRARIES OFF CACHE BOOL "" FORCE)
|
||||||
set(PACKAGE_DEBIAN OFF CACHE BOOL "" FORCE)
|
set(PACKAGE_DEBIAN OFF CACHE BOOL "" FORCE)
|
||||||
|
|
||||||
# Automatically collect core sources and platform-specific HAL files
|
# Pre-project platform setup (e.g. Pico's pico_sdk_import.cmake must run
|
||||||
|
# before project(), and it must set PROJECT_LANGUAGES).
|
||||||
|
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/platform_${BUILD_PLATFORM}_pre.cmake)
|
||||||
|
|
||||||
|
project(p-rad ${PROJECT_LANGUAGES})
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
# NOTE: don't use add_link_options/add_compile_options here - they apply to
|
||||||
|
# every target including pico-sdk's bs2_default, whose binary gets fully
|
||||||
|
# garbage-collected. Scope them to the p-rad target instead (see platform files).
|
||||||
|
|
||||||
|
# Automatically collect core sources and platform-specific HAL files.
|
||||||
|
# HAL files are matched by suffix convention: src/hal/*_<platform>.cpp
|
||||||
file(GLOB CORE_SOURCES CONFIGURE_DEPENDS "src/core/*.cpp" "src/core/*.c")
|
file(GLOB CORE_SOURCES CONFIGURE_DEPENDS "src/core/*.cpp" "src/core/*.c")
|
||||||
file(GLOB HAL_PICO_SOURCES CONFIGURE_DEPENDS "src/hal/*_pico.cpp")
|
file(GLOB HAL_SOURCES CONFIGURE_DEPENDS "src/hal/*_${BUILD_PLATFORM_LOWER}.cpp")
|
||||||
file(GLOB HAL_LINUX_SOURCES CONFIGURE_DEPENDS "src/hal/*_linux.cpp")
|
|
||||||
|
|
||||||
if(BUILD_FOR_PICO)
|
|
||||||
set(PICO_BOARD pico_w CACHE STRING "Board type")
|
|
||||||
include(pico_sdk_import.cmake)
|
|
||||||
project(p-rad C CXX ASM)
|
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 23)
|
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
||||||
|
|
||||||
pico_sdk_init()
|
|
||||||
|
|
||||||
add_subdirectory(${GEOGRAPHICLIB_DIR} EXCLUDE_FROM_ALL)
|
|
||||||
target_compile_options(GeographicLib INTERFACE -fexceptions -frtti)
|
|
||||||
|
|
||||||
add_executable(p-rad
|
|
||||||
src/main.cpp
|
|
||||||
${CORE_SOURCES}
|
|
||||||
${HAL_PICO_SOURCES}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_compile_definitions(p-rad PRIVATE PICO_BUILD)
|
|
||||||
target_include_directories(p-rad PRIVATE src)
|
|
||||||
target_link_libraries(p-rad pico_stdlib pico_cyw43_arch_lwip_threadsafe_background hardware_rtc GeographicLib)
|
|
||||||
|
|
||||||
pico_enable_stdio_usb(p-rad 1)
|
|
||||||
pico_enable_stdio_uart(p-rad 0)
|
|
||||||
|
|
||||||
pico_add_extra_outputs(p-rad)
|
|
||||||
else()
|
|
||||||
project(p-rad CXX)
|
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 23)
|
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
||||||
|
|
||||||
add_subdirectory(${GEOGRAPHICLIB_DIR} EXCLUDE_FROM_ALL)
|
add_subdirectory(${GEOGRAPHICLIB_DIR} EXCLUDE_FROM_ALL)
|
||||||
|
|
||||||
add_executable(p-rad
|
# Post-project platform setup: add_executable, link libraries, platform-specific calls.
|
||||||
src/main.cpp
|
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/platform_${BUILD_PLATFORM}.cmake)
|
||||||
${CORE_SOURCES}
|
|
||||||
${HAL_LINUX_SOURCES}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(p-rad PRIVATE src)
|
|
||||||
find_package(Threads REQUIRED)
|
|
||||||
find_package(SDL3 REQUIRED CONFIG)
|
|
||||||
find_package(CURL REQUIRED)
|
|
||||||
target_link_libraries(p-rad Threads::Threads SDL3::SDL3 CURL::libcurl GeographicLib)
|
|
||||||
endif()
|
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ all: linux pico
|
|||||||
|
|
||||||
linux: $(AUTOHEADER)
|
linux: $(AUTOHEADER)
|
||||||
mkdir -p build-linux
|
mkdir -p build-linux
|
||||||
(cd build-linux && cmake .. -DBUILD_FOR_PICO=OFF && make -j$(nproc))
|
(cd build-linux && cmake .. -DBUILD_PLATFORM=Linux && make -j$(nproc))
|
||||||
|
|
||||||
pico: $(AUTOHEADER)
|
pico: $(AUTOHEADER)
|
||||||
mkdir -p build-pico
|
mkdir -p build-pico
|
||||||
(cd build-pico && cmake .. -DBUILD_FOR_PICO=ON && make -j$(nproc))
|
(cd build-pico && cmake .. -DBUILD_PLATFORM=Pico && make -j$(nproc))
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# kconfig targets
|
# kconfig targets
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
add_executable(p-rad
|
||||||
|
src/main.cpp
|
||||||
|
${CORE_SOURCES}
|
||||||
|
${HAL_SOURCES}
|
||||||
|
)
|
||||||
|
target_compile_options(p-rad PRIVATE -ffunction-sections -fdata-sections)
|
||||||
|
target_link_options(p-rad PRIVATE -Wl,--gc-sections)
|
||||||
|
if(CMAKE_BUILD_TYPE EQUAL Release)
|
||||||
|
add_compile_options(-O3)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_include_directories(p-rad PRIVATE src)
|
||||||
|
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
find_package(SDL3 REQUIRED CONFIG)
|
||||||
|
find_package(CURL REQUIRED)
|
||||||
|
|
||||||
|
target_link_libraries(p-rad
|
||||||
|
Threads::Threads
|
||||||
|
SDL3::SDL3
|
||||||
|
CURL::libcurl
|
||||||
|
GeographicLib
|
||||||
|
)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
set(PROJECT_LANGUAGES CXX)
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
pico_sdk_init()
|
||||||
|
|
||||||
|
target_compile_options(GeographicLib INTERFACE -fexceptions -frtti)
|
||||||
|
|
||||||
|
add_executable(p-rad
|
||||||
|
src/main.cpp
|
||||||
|
${CORE_SOURCES}
|
||||||
|
${HAL_SOURCES}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_options(p-rad PRIVATE -ffunction-sections -fdata-sections)
|
||||||
|
target_link_options(p-rad PRIVATE -Wl,--gc-sections)
|
||||||
|
|
||||||
|
if(CMAKE_BUILD_TYPE EQUAL Release)
|
||||||
|
add_compile_options(-Os)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
target_compile_definitions(p-rad PRIVATE PICO_BUILD)
|
||||||
|
target_include_directories(p-rad PRIVATE src)
|
||||||
|
target_link_libraries(p-rad
|
||||||
|
pico_stdlib
|
||||||
|
pico_cyw43_arch_lwip_threadsafe_background
|
||||||
|
hardware_rtc
|
||||||
|
GeographicLib
|
||||||
|
)
|
||||||
|
|
||||||
|
pico_enable_stdio_usb(p-rad 1)
|
||||||
|
pico_enable_stdio_uart(p-rad 0)
|
||||||
|
|
||||||
|
pico_add_extra_outputs(p-rad)
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
set(PROJECT_LANGUAGES C CXX ASM)
|
||||||
|
|
||||||
|
set(PICO_BOARD pico_w CACHE STRING "Board type")
|
||||||
|
include(${CMAKE_SOURCE_DIR}/pico_sdk_import.cmake)
|
||||||
@@ -54,6 +54,8 @@ void circle(const uint16_t x_center, const uint16_t y_center,const uint16_t radi
|
|||||||
}
|
}
|
||||||
void rhombus(const uint16_t x_center, const uint16_t y_center, const uint16_t radius, const color_t color) {}
|
void rhombus(const uint16_t x_center, const uint16_t y_center, const uint16_t radius, const color_t color) {}
|
||||||
void line(const uint16_t x1, const uint16_t y1, const uint16_t x2, const uint16_t y2, const color_t color) {}
|
void line(const uint16_t x1, const uint16_t y1, const uint16_t x2, const uint16_t y2, const color_t color) {}
|
||||||
|
void arc(uint16_t start_x, uint16_t start_y, float start_angle, float speed /*in pps*/,float angular_speed, uint16_t duration, color_t color) {}
|
||||||
|
|
||||||
} // namespace draw
|
} // namespace draw
|
||||||
|
|
||||||
namespace net {
|
namespace net {
|
||||||
|
|||||||
Reference in New Issue
Block a user