如何使用 cmake 和 gcc 生成 PDB 文件?
How do I generate PDB files using cmake and gcc?
我想使用 OpenCppCoverage 通过我的单元测试来检查我的源文件的覆盖率。但是,我似乎需要生成 .pdb 文件才能使 OpenCppCoverage 正常工作。
问题是我无法从我的构建中生成此类文件。这是我的 CmakeLists.txt
cmake_minimum_required(VERSION 3.17) # version can be different
project(GUnitTestingVSCode) #name of your project
add_subdirectory(googletest) # add googletest subdirectory
add_compile_definitions(TELEMETRY_DIAGNOSTICS)
add_compile_definitions(GTEST)
set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/")
include_directories(googletest/include/) # this is so we can #include <gtest/gtest.h>
include_directories(googletest/googlemock/include/gmock/) # this is so we can #include <gmock/gmock.h>
include_directories("${CMAKE_SOURCE_DIR}/"
"${CMAKE_SOURCE_DIR}/inc/"
"${CMAKE_SOURCE_DIR}/mocks/"
"${CMAKE_SOURCE_DIR}/../submodule/library/inc"
"${CMAKE_SOURCE_DIR}/../submodule/library/inc/Application"
"${CMAKE_SOURCE_DIR}/../submodule/library/inc/Datalink/"
"${CMAKE_SOURCE_DIR}/../submodule/library/inc/Demodulation"
"${CMAKE_SOURCE_DIR}/../submodule/library/inc/Modulation"
"${CMAKE_SOURCE_DIR}/../inc/Peripherals/"
"${CMAKE_SOURCE_DIR}/../inc/Protocol/"
"${CMAKE_SOURCE_DIR}/../inc/Diagnostics/")
file(GLOB_RECURSE SOURCES RELATIVE
${CMAKE_SOURCE_DIR} "../src/Peripherals/DMA.c" "../src/Diagnostics.c"
${CMAKE_SOURCE_DIR} "../src/Protocol/DataLink.c"
"src/*.cpp" "googletest/*.cpp" "mocks/*.c"
"../submodule/library/src/*.c")
add_executable(gUnitTest ${SOURCES}) # add this executable
set(CMAKE_BUILD_TYPE RelWithDebInfo)
set_target_properties(gUnitTest PROPERTIES
COMPILE_PDB_NAME "gUnitTestCompiled"
COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/"
PDB_NAME "gUnitTestLinker"
PDB_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/")
target_link_libraries(gUnitTest PUBLIC gtest gmock) # link google test to this executable
但是,当我在 RelWithDebInfo 模式下构建我的测试文件夹时(我也试过调试),我在构建文件夹中没有得到任何 .pdb 文件。有人可以帮助我了解我做错了什么吗?
使用的编译器是GCC 9.2.0 (mingw32)
我想使用 OpenCppCoverage 通过我的单元测试来检查我的源文件的覆盖率。但是,我似乎需要生成 .pdb 文件才能使 OpenCppCoverage 正常工作。
问题是我无法从我的构建中生成此类文件。这是我的 CmakeLists.txt
cmake_minimum_required(VERSION 3.17) # version can be different
project(GUnitTestingVSCode) #name of your project
add_subdirectory(googletest) # add googletest subdirectory
add_compile_definitions(TELEMETRY_DIAGNOSTICS)
add_compile_definitions(GTEST)
set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/")
include_directories(googletest/include/) # this is so we can #include <gtest/gtest.h>
include_directories(googletest/googlemock/include/gmock/) # this is so we can #include <gmock/gmock.h>
include_directories("${CMAKE_SOURCE_DIR}/"
"${CMAKE_SOURCE_DIR}/inc/"
"${CMAKE_SOURCE_DIR}/mocks/"
"${CMAKE_SOURCE_DIR}/../submodule/library/inc"
"${CMAKE_SOURCE_DIR}/../submodule/library/inc/Application"
"${CMAKE_SOURCE_DIR}/../submodule/library/inc/Datalink/"
"${CMAKE_SOURCE_DIR}/../submodule/library/inc/Demodulation"
"${CMAKE_SOURCE_DIR}/../submodule/library/inc/Modulation"
"${CMAKE_SOURCE_DIR}/../inc/Peripherals/"
"${CMAKE_SOURCE_DIR}/../inc/Protocol/"
"${CMAKE_SOURCE_DIR}/../inc/Diagnostics/")
file(GLOB_RECURSE SOURCES RELATIVE
${CMAKE_SOURCE_DIR} "../src/Peripherals/DMA.c" "../src/Diagnostics.c"
${CMAKE_SOURCE_DIR} "../src/Protocol/DataLink.c"
"src/*.cpp" "googletest/*.cpp" "mocks/*.c"
"../submodule/library/src/*.c")
add_executable(gUnitTest ${SOURCES}) # add this executable
set(CMAKE_BUILD_TYPE RelWithDebInfo)
set_target_properties(gUnitTest PROPERTIES
COMPILE_PDB_NAME "gUnitTestCompiled"
COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/"
PDB_NAME "gUnitTestLinker"
PDB_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/")
target_link_libraries(gUnitTest PUBLIC gtest gmock) # link google test to this executable
但是,当我在 RelWithDebInfo 模式下构建我的测试文件夹时(我也试过调试),我在构建文件夹中没有得到任何 .pdb 文件。有人可以帮助我了解我做错了什么吗?
使用的编译器是GCC 9.2.0 (mingw32)