cmake ignores -D CMAKE_BUILD_TYPE=Debug

前端 未结 3 1890
夕颜
夕颜 2021-02-19 08:28

I\'m just trying to build a cmake project in debug-mode to enable asserts. I tried the following versions:

cmake -D CMAKE_BUILD_TYPE:STRING=Debug -L ../../
cmake         


        
相关标签:
3条回答
  • 2021-02-19 08:49

    I assume that there is something wrong with your config..

    I wrote a complete, simple example here: 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)
    

    When you execute cmake with

    cmake -DCMAKE_BUILD_TYPE=Debug ../../
    

    It gives the following output:

    $ ./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
    

    It shows that CMAKE_BUILD_TYPE is being set from the command line and it being recognized in the CMakeLists.txt config.

    What happens when you run it on your system using your version of CMake?

    0 讨论(0)
  • 2021-02-19 08:54

    This works for me:

    IF(${CMAKE_BUILD_TYPE} MATCHES Debug)
    ...
    ENDIF()
    
    0 讨论(0)
  • 2021-02-19 09:07

    Ok, fgrep -R "CMAKE_BUILD_TYPE" finally found the problem for me. In some CMakeLists.txt-file I found something like that:

    SET( CMAKE_BUILD_TYPE Release ... FORCE )
    

    That overrides every user defined parameters (because of the FORCE).

    What works for me is that:

    IF( NOT CMAKE_BUILD_TYPE )
       SET( CMAKE_BUILD_TYPE Release ... FORCE )
    ENDIF()
    

    Thank's for your hints!

    0 讨论(0)
提交回复
热议问题