build: seed APP_VERSION and API_KEY from the environment
Fresh cmake configures pick up APP_VERSION/API_KEY from environment variables (as nix develop and CI provide them); -D still wins on reconfigure. Also normalizes indentation in the sd-bus blocks.
This commit is contained in:
@@ -30,7 +30,11 @@ the project version, or pass your own at configure time:
|
|||||||
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DAPP_VERSION="1.2.3"
|
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DAPP_VERSION="1.2.3"
|
||||||
```
|
```
|
||||||
|
|
||||||
The Nix package passes its flake version automatically via `cmakeFlags`.
|
The Nix package bakes `-DAPP_VERSION=<pkg version>` via `cmakeFlags` (version is
|
||||||
|
hardcoded `0.1.0` in `nix/package.nix`, not read from the flake). `nix develop`
|
||||||
|
sets `APP_VERSION=dev` and exports `API_KEY` from the ambient environment
|
||||||
|
(falling back to `RWT_LIVE_API_KEY`). CMake seeds a *fresh* configure from the
|
||||||
|
`APP_VERSION` / `API_KEY` env vars; `-D` wins on reconfigure.
|
||||||
|
|
||||||
The portal API key is also a build-time argument: `-DAPI_KEY="..."` (CMake) or
|
The portal API key is also a build-time argument: `-DAPI_KEY="..."` (CMake) or
|
||||||
`apiKey` on `callPackage` (Nix). It is compiled into the binary as the
|
`apiKey` on `callPackage` (Nix). It is compiled into the binary as the
|
||||||
|
|||||||
+23
-9
@@ -8,15 +8,29 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|||||||
# App version string shown at the top of the Home footer. Defaults to the
|
# App version string shown at the top of the Home footer. Defaults to the
|
||||||
# project version; override at configure time with:
|
# project version; override at configure time with:
|
||||||
# cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DAPP_VERSION="1.2.3"
|
# cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DAPP_VERSION="1.2.3"
|
||||||
set(APP_VERSION "${PROJECT_VERSION}" CACHE STRING
|
# or by exporting APP_VERSION in the environment (the `nix develop` shell does
|
||||||
"Version string shown in the Home footer (override at configure time)")
|
# this; the env var only seeds a fresh configure, -D wins on reconfigure).
|
||||||
|
if(DEFINED ENV{APP_VERSION})
|
||||||
|
set(APP_VERSION "$ENV{APP_VERSION}" CACHE STRING
|
||||||
|
"Version string shown in the Home footer (override at configure time)")
|
||||||
|
else()
|
||||||
|
set(APP_VERSION "${PROJECT_VERSION}" CACHE STRING
|
||||||
|
"Version string shown in the Home footer (override at configure time)")
|
||||||
|
endif()
|
||||||
|
|
||||||
# API bearer key baked into the binary and sent as `Authorization: Bearer <key>`
|
# API bearer key baked into the binary and sent as `Authorization: Bearer <key>`
|
||||||
# on every portal request. Leave empty to send no auth header. Never commit the
|
# on every portal request. Leave empty to send no auth header. Never commit the
|
||||||
# real value — inject it at CI build time from a secret, e.g.:
|
# real value — inject it at CI build time from a secret, e.g.:
|
||||||
# cmake ... -DAPI_KEY="${{ secrets.PORTAL_API_KEY }}"
|
# cmake ... -DAPI_KEY="${{ secrets.PORTAL_API_KEY }}"
|
||||||
set(API_KEY "" CACHE STRING
|
# The `nix develop` shell exports API_KEY from the ambient environment, which
|
||||||
"Portal API key baked into the binary (leave empty to skip auth)")
|
# seeds a fresh configure; -D wins on reconfigure.
|
||||||
|
if(DEFINED ENV{API_KEY})
|
||||||
|
set(API_KEY "$ENV{API_KEY}" CACHE STRING
|
||||||
|
"Portal API key baked into the binary (leave empty to skip auth)")
|
||||||
|
else()
|
||||||
|
set(API_KEY "" CACHE STRING
|
||||||
|
"Portal API key baked into the binary (leave empty to skip auth)")
|
||||||
|
endif()
|
||||||
|
|
||||||
find_package(SDL3 REQUIRED)
|
find_package(SDL3 REQUIRED)
|
||||||
find_package(SDL3_ttf REQUIRED)
|
find_package(SDL3_ttf REQUIRED)
|
||||||
@@ -31,8 +45,8 @@ include(GoogleTest)
|
|||||||
|
|
||||||
# Network manager dependencies (Linux only)
|
# Network manager dependencies (Linux only)
|
||||||
if(UNIX AND NOT APPLE)
|
if(UNIX AND NOT APPLE)
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_check_modules(SDBUS REQUIRED libsystemd)
|
pkg_check_modules(SDBUS REQUIRED libsystemd)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(radiantwave
|
add_executable(radiantwave
|
||||||
@@ -92,9 +106,9 @@ target_link_libraries(radiantwave PRIVATE
|
|||||||
)
|
)
|
||||||
|
|
||||||
if(UNIX AND NOT APPLE)
|
if(UNIX AND NOT APPLE)
|
||||||
target_link_libraries(radiantwave PRIVATE ${SDBUS_LIBRARIES} resolv)
|
target_link_libraries(radiantwave PRIVATE ${SDBUS_LIBRARIES} resolv)
|
||||||
target_include_directories(radiantwave PRIVATE ${SDBUS_INCLUDE_DIRS})
|
target_include_directories(radiantwave PRIVATE ${SDBUS_INCLUDE_DIRS})
|
||||||
target_compile_definitions(radiantwave PRIVATE HAS_DBUS=1)
|
target_compile_definitions(radiantwave PRIVATE HAS_DBUS=1)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
install(TARGETS radiantwave RUNTIME DESTINATION bin)
|
install(TARGETS radiantwave RUNTIME DESTINATION bin)
|
||||||
|
|||||||
@@ -39,8 +39,20 @@
|
|||||||
devShells.default = pkgs.mkShell {
|
devShells.default = pkgs.mkShell {
|
||||||
inputsFrom = [ self.packages.${system}.default ];
|
inputsFrom = [ self.packages.${system}.default ];
|
||||||
packages = [ ];
|
packages = [ ];
|
||||||
|
env = {
|
||||||
|
# APP_VERSION and API_KEY are CMake cache variables with no
|
||||||
|
# default; on a fresh configure cmake seeds their cache from
|
||||||
|
# environment variables of the same name, so a plain
|
||||||
|
# `cmake -S . -B build` bakes them into the binary.
|
||||||
|
APP_VERSION = "dev";
|
||||||
|
};
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
echo "RadiantWave dev shell"
|
# Never commit the real key. Export API_KEY (or the CI name
|
||||||
|
# RWT_LIVE_API_KEY) in your ambient environment and this shell
|
||||||
|
# picks it up; empty by default (no auth header).
|
||||||
|
export API_KEY="''${API_KEY:-''${RWT_LIVE_API_KEY:-}}"
|
||||||
|
|
||||||
|
echo "RadiantWave dev shell (APP_VERSION=dev, API_KEY=$([[ -n "$API_KEY" ]] && echo set || echo unset))"
|
||||||
echo " Configure: cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug"
|
echo " Configure: cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug"
|
||||||
echo " Build: cmake --build build"
|
echo " Build: cmake --build build"
|
||||||
echo " Run: ./build/radiantwave"
|
echo " Run: ./build/radiantwave"
|
||||||
|
|||||||
Reference in New Issue
Block a user