Skip to content

Commit

Permalink
cmake: add per-workspace flags
Browse files Browse the repository at this point in the history
Add support for per-worktree cached Zig build options.

On load of Zig `CMakeLists.txt` shell env is probed for
`ZIG_LOCAL_CMAKE_CACHE_DIR` and then
`$ZIG_LOCAL_CMAKE_CACHE_DIR/CMakeLists.txt` is loaded.

This makes it a little more convenient to have a different set of
Zig build options for different worktrees.

example setup:

    export ZIG_LOCAL_CMAKE_CACHE_DIR=local

example contents of `$WORKTREE/local/CMakeLists.txt`:

    CMAKE_BUILD_TYPE:STRING=Debug
    CMAKE_INSTALL_PREFIX:PATH=/opt/zig
    CMAKE_PREFIX_PATH:PATH=/opt/llvm-9.0.1
    ZIG_SKIP_INSTALL_LIB_FILES:BOOL=ON
    ZIG_ENABLE_MEM_PROFILE:BOOL=OFF
  • Loading branch information
mikdusan committed Jan 13, 2020
1 parent 2be12b2 commit 908b4ca
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions CMakeLists.txt
@@ -1,5 +1,21 @@
cmake_minimum_required(VERSION 2.8.5)

# load local cmake cache if present in SRCDIR/local/CMakeCache.txt
if(DEFINED ENV{ZIG_LOCAL_CMAKE_CACHE_DIR})
if (IS_ABSOLUTE ENV{ZIG_LOCAL_CMAKE_CACHE_DIR})
set(ZIG_LOCAL_CMAKE_CACHE_DIR "$ENV{ZIG_LOCAL_CMAKE_CACHE_DIR}")
else()
set(ZIG_LOCAL_CMAKE_CACHE_DIR "${CMAKE_SOURCE_DIR}/$ENV{ZIG_LOCAL_CMAKE_CACHE_DIR}")
endif()
if(EXISTS "${ZIG_LOCAL_CMAKE_CACHE_DIR}/CMakeCache.txt")
message("-- Loading Zig local cmake cache: ${ZIG_LOCAL_CMAKE_CACHE_DIR}/CMakeCache.txt")
load_cache(${ZIG_LOCAL_CMAKE_CACHE_DIR} INCLUDE_INTERNALS)
else()
message(SEND_ERROR "unable to load Zig local cmake cache: ${ZIG_LOCAL_CMAKE_CACHE_DIR}/CMakeCache.txt")
message(FATAL_ERROR "please check or unset env var `ZIG_LOCAL_CMAKE_CACHE_DIR`")
endif()
endif()

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
Expand Down

0 comments on commit 908b4ca

Please sign in to comment.