1

I have a static library which i am compiling using cmake. Now, when i comiple in debug mode i get pdb file generated but when release mode is compiled the pdb file is not generated. Following is the piece of code in cmake:

    if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
        set_target_properties(${PROJECT_NAME} PROPERTIES IMPORTED_CONFIGURATIONS "Debug")
        set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_PDB_NAME ${PROJECT_NAME} COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/bin_debug" )
    elseif("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
        set_target_properties(${PROJECT_NAME} PROPERTIES IMPORTED_CONFIGURATIONS "Release")
        set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_PDB_NAME ${PROJECT_NAME} COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/bin_release" )

I want to have pdb files for debug as well as release build. So,how can i have it? Suggestions are really required.

Learner
  • 453
  • 13
  • 29

2 Answers2

4

CMake does - as Visual Studio would do - generate a RelWithDebInfo configuration for your VS solution.

But you can add debug info to other configurations - like Release - also with the use of e.g. target_compile_options() and generator experssions to give the necessary /Zi or /Z7 command:

target_compile_options(
    ${PROJECT_NAME} 
    PRIVATE 
         "$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:RELEASE>>:/Zi>"
)

or you could just say you want it for all configurations and all targets with add_compile_options() (and without generator expressions for better readability):

project(...)
if (MSVC)
    add_compile_options("/Zi")
endif()

References

Community
  • 1
  • 1
Florian
  • 39,996
  • 9
  • 133
  • 149
0

I haven't used CMake but it looks like it generates Visual Studio project and solution files, so based on that...

By default VS doesn't generate .pdb's in release configurations. To do so, you need a few properties in your project file. So you'll need to get CMake to output something similar to below in the .xxproj file that it generates:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <DefineDebug>false</DefineDebug>
    <Optimize>true</Optimize>
</PropertyGroup>

These properties give you an otherwise release/optimized build with the only difference that it also generates the .pdb.

PropertyGroup can vary based on your configuration, but you'll need the active (being compiled) configuration to have the child properties.

modal_dialog
  • 733
  • 5
  • 12
  • inside .xxproj i can see: C:\repo\Release\minizip.pdb but there is only Release folder being created and that is all empty :( – Learner Nov 23 '15 at 07:41
  • Perusing the CMake docs, looks like there is a "target variable" called: VS_GLOBAL_, where you replace with the name of the variable as it should be in the project file. https://cmake.org/cmake/help/v2.8.8/cmake.html#prop_tgt:VS_GLOBAL_variable You could try defining DebugType=pdbonly that way. – modal_dialog Nov 23 '15 at 07:53