Merge pull request #390 from google/fix_cmake_var_handling

Require Android NDK path in environment.
This commit is contained in:
FrankGalligan 2018-05-14 12:46:52 -07:00 committed by GitHub
commit d83342256e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 13 deletions

View File

@ -321,11 +321,8 @@ It's sometimes useful to build Draco command line tools and run them directly on
Android devices via adb.
~~~~~ bash
# all targets require CMAKE_ANDROID_NDK. It can be set in the environment or
# within CMake. For example, this would set it in your environment.
# All targets require CMAKE_ANDROID_NDK. It must be set in the environment.
$ export CMAKE_ANDROID_NDK=path/to/ndk
# To set it within CMake, add -DCMAKE_ANDROID_NDK=path/to/ndk to your CMake
# command.
# arm
$ cmake path/to/draco -DCMAKE_TOOLCHAIN_FILE=path/to/draco/cmake/toolchains/armv7-android-ndk-libcpp.cmake

View File

@ -51,21 +51,19 @@ function (set_compiler_launcher launcher_flag launcher_name)
endif ()
endfunction ()
# Terminates CMake execution when $var_name is unset in CMake and environment,
# and then calls set_variable_if_unset() to ensure variable is set for caller.
# Terminates CMake execution when $var_name is unset in the environment. Sets
# CMake variable to the value of the environment variable when the variable is
# present in the environment.
macro(require_variable var_name)
if ((NOT DEFINED ${var_name}) AND ("$ENV{${var_name}}" STREQUAL ""))
message(FATAL_ERROR "${var_name} must be set in cmake or environment.")
if ("$ENV{${var_name}}" STREQUAL "")
message(FATAL_ERROR "${var_name} must be set in environment.")
endif ()
set_variable_if_unset(${var_name} "")
endmacro ()
# Sets $var_name to $default_value if not already set in CMake or the
# environment.
# Sets $var_name to $default_value if not already set in the environment.
macro (set_variable_if_unset var_name default_value)
if (DEFINED ${var_name})
return ()
elseif (NOT "$ENV{${var_name}}" STREQUAL "")
if (NOT "$ENV{${var_name}}" STREQUAL "")
set(${var_name} $ENV{${var_name}})
else ()
set(${var_name} ${default_value})