我认为您的配置有问题..
我在这里写了一个完整的简单示例:
https ://dl.dropboxusercontent.com/u/68798379/cmake-build-type.tar.bz2
cmake_minimum_required (VERSION 2.8)
project(playlib)
message("CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
IF(CMAKE_BUILD_TYPE MATCHES Debug)
message("Debug build.")
ELSEIF(CMAKE_BUILD_TYPE MATCHES Release)
message("Release build.")
ELSE()
message("Some other build type.")
ENDIF()
add_library(TESTLIB SHARED src/test.c)
当您执行 cmake 时
cmake -DCMAKE_BUILD_TYPE=Debug ../../
它提供以下输出:
$ ./gen-linux.sh
-- The C compiler identification is GNU 4.8.2
-- The CXX compiler identification is GNU 4.8.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMAKE_BUILD_TYPE = Debug
Debug build.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/wojci/stack-overflow/cmake-build-type/build/linux
它表明 CMAKE_BUILD_TYPE 是从命令行设置的,并且在 CMakeLists.txt 配置中被识别。
当您使用您的 CMake 版本在系统上运行它时会发生什么?