44 lines
1.6 KiB
CMake
44 lines
1.6 KiB
CMake
# The following lines of boilerplate have to be in your project's
|
|
# CMakeLists in this exact order for cmake to work correctly
|
|
cmake_minimum_required(VERSION 3.16)
|
|
# target_compile_options(${COMPONENT_LIB} PRIVATE -std=c++23)
|
|
|
|
# Define the path to your .env file
|
|
set(ENV_FILE "${CMAKE_SOURCE_DIR}/.env")
|
|
|
|
# Check if the .env file exists
|
|
if(EXISTS ${ENV_FILE})
|
|
# Read the .env file line by line
|
|
file(STRINGS ${ENV_FILE} ENV_VARS)
|
|
|
|
foreach(VAR ${ENV_VARS})
|
|
# Use regex to extract the key and value
|
|
if (VAR MATCHES "([^=]+)=(.*)")
|
|
set(ENV{${CMAKE_MATCH_1}} ${CMAKE_MATCH_2})
|
|
message(STATUS "Loaded environment variable from .env: ${CMAKE_MATCH_1}")
|
|
endif()
|
|
endforeach()
|
|
else()
|
|
message(STATUS ".env file not found at ${ENV_FILE}")
|
|
endif()
|
|
|
|
# If build-time WiFi environment variables were loaded above, expose them
|
|
# as compile-time definitions so C++ can use them.
|
|
if(DEFINED ENV{WIFI_SSID})
|
|
add_compile_definitions(BUILD_WIFI_SSID="$ENV{WIFI_SSID}")
|
|
message(STATUS "Added BUILD_WIFI_SSID compile definition")
|
|
else()
|
|
message(STATUS "WIFI_SSID not defined; skipping BUILD_WIFI_SSID compile definition")
|
|
endif()
|
|
if(DEFINED ENV{WIFI_PASSWORD})
|
|
add_compile_definitions(BUILD_WIFI_PASSWORD="$ENV{WIFI_PASSWORD}")
|
|
message(STATUS "Added BUILD_WIFI_PASSWORD compile definition")
|
|
else()
|
|
message(STATUS "WIFI_PASSWORD not defined; skipping BUILD_WIFI_PASSWORD compile definition")
|
|
endif()
|
|
|
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
|
# "Trim" the build. Include the minimal set of components, main, and anything it depends on.
|
|
idf_build_set_property(MINIMAL_BUILD ON)
|
|
project(ink-board)
|