首页 文章

具有多个项目的一个构建的Cmake Debug标志条件

提问于
浏览
0

我需要帮助用debug flag编译我的项目 .

我在build文件夹中编译了 -DCMAKE_BUILD_TYPE=Debug .. .

我能够在编译后运行二进制文件 . 但是,Debug标志未打开 . 我有点陷入困境 . 任何善良的人都愿意对此提出一些建议或指示?

我的构建树是这样的:

project
|------ CMakeLists.txt (The main Cmake)
|------ ProjectA
|          |----- src
                   |.c files
|          |----- include
                   |.h files
|          |----- CMakeList.txt
|------ ProjectB
|          |----- src
                   |.c files
|          |----- include
                   |.h files
|          |----- CMakeList.txt
| 
|------ build
|         |-----  ...
|------ bin
|        |---- executables

我在项目A和B中设置了我的cmake标志:

#cmake output directory
...
#compiler
...
set(CMAKE_C_FLAGS "... -DDEBUG ...")
#Linking
...
#add executables
...

我的顶级CMakeLists.text是这样的:

project(..)
...

add_subdirectory(ProjectA)
add_subdirectory(ProjectB)

1 回答

  • 1

    在主CMakeLists.txt中添加以下行

    ## Configure debug flag to enable debug log
    
    set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall")
    

    生成Makefile:

    cmake ..... -DCMAKE_ARCH="x86_64" -DCMAKE_BUILD_TYPE=Debug
    

相关问题