Skip to content
Permalink
Browse files

cmake: Fix path handling for ZEPHYR_BASE

With the addition of a local CMake variable ZEPHYR_BASE that mirrors the
value of the environment variable the documentation build broke on
Windows. This is because CMake was incorrectly interpreting backslashes
present in the Windows path as escaping characters. In order to avoid
this, use CMake's built-in file(TO_CMAKE_PATH) functionality, which
converts the path to a canonical version using forward slashes only.
At the same time rework boilerplate.cmake to use the same mechanism
instead of manually replacing backslashes and removing trailing ones.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
  • Loading branch information...
carlescufi committed May 23, 2019
1 parent 4828dab commit b73790b6296ad27e9813069c9169524d321d14e1
Showing with 2 additions and 8 deletions.
  1. +1 −7 cmake/app/boilerplate.cmake
  2. +1 −1 doc/CMakeLists.txt
@@ -72,13 +72,7 @@ add_custom_target(code_data_relocation_target)
# and its associated variables, e.g. PROJECT_SOURCE_DIR.
# It is recommended to always use ZEPHYR_BASE instead of PROJECT_SOURCE_DIR
# when trying to reference ENV${ZEPHYR_BASE}.
set(PROJECT_SOURCE_DIR $ENV{ZEPHYR_BASE})

# Convert path to use the '/' separator
string(REPLACE "\\" "/" PROJECT_SOURCE_DIR ${PROJECT_SOURCE_DIR})

# Remove trailing '/', it results in ugly paths and also exposes some bugs
string(REGEX REPLACE "\/+$" "" PROJECT_SOURCE_DIR ${PROJECT_SOURCE_DIR})
file(TO_CMAKE_PATH "$ENV{ZEPHYR_BASE}" PROJECT_SOURCE_DIR)

set(ZEPHYR_BINARY_DIR ${PROJECT_BINARY_DIR})
set(ZEPHYR_BASE ${PROJECT_SOURCE_DIR})
@@ -12,7 +12,7 @@ if(${WEST} STREQUAL WEST-NOTFOUND)
unset(WEST)
endif()

set(ZEPHYR_BASE $ENV{ZEPHYR_BASE})
file(TO_CMAKE_PATH "$ENV{ZEPHYR_BASE}" ZEPHYR_BASE)

message(STATUS "Zephyr base: ${ZEPHYR_BASE}")

0 comments on commit b73790b

Please sign in to comment.
You can’t perform that action at this time.