我的CMakeLists.txt中有以下CMake代码段:
cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)
message(STATUS "Before setting - ${MY_VARIABLE}")
# first check
if(NOT DEFINED ${MY_VARIABLE})
set(MY_VARIABLE true)
endif(NOT DEFINED ${MY_VARIABLE})
message(STATUS "After setting - ${MY_VARIABLE}")
# second check
if(NOT DEFINED ${MY_VARIABLE})
message(STATUS "What - ${MY_VARIABLE}")
endif(NOT DEFINED ${MY_VARIABLE})
Run Code Online (Sandbox Code Playgroud)
CMake配置的输出是:
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/local/bin/cc
-- Check for working C compiler: /usr/local/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/local/bin/c++
-- Check for working CXX compiler: /usr/local/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Before setting -
-- After setting - true
-- What - true
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/build
Run Code Online (Sandbox Code Playgroud)
问题:为什么第二次检查变量定义报告变量未定义,即使它已定义?令人惊讶的是,变量的值也正确打印!
| 归档时间: |
|
| 查看次数: |
11842 次 |
| 最近记录: |