Home > Enterprise >  using cmake, build a visual studio project with dependencies, being able to debug also into the depe
using cmake, build a visual studio project with dependencies, being able to debug also into the depe

Time:03-19

I have a C project source code with several dependencies (C packages, compiled libs and source). I need to create a CMake file which will generate the Visual Studio solution and projects files in such a way that if I put a break point in one of the dependencies source code, the execution of the main project in debug mode would break and debug at that break point in the dependency. Any suggestion is highly appreciated.

[EDIT]

If I use the packages, with the provided ...config.cmake files, the source files are not included in the generated project.

If I generate the MS projects individually and use include_external_msproject to put them together in a solution, I have the source code, but it is executed from somewhere else (binaries), so my breakpoints are ignored.

On the other hand, there is overlap from duplicated targets, like DOCUMENTATION for example, which come from each dependency, if I want to use add_subdirectory to add the deps to the main project

CodePudding user response:

I ended up modifying the dependencies so that they implement unique target names for documentation, but if built individually to create the original named target: DOCUMENTATION.


    doxygen_add_docs(DOCUMENTATION_${PROJECT_NAME}
                     doc
                     src/component
                    )
    
    if (NOT (TARGET DOCUMENTATION))
        add_custom_target(DOCUMENTATION COMMENT "workaround for multi-dependencies project")
        add_dependencies(DOCUMENTATION DOCUMENTATION_${PROJECT_NAME})
    endif()

CodePudding user response:

You need to write a CMakeLists.txt with the appropriate compile options. To do that, you can set the following CMake values in the CMakeLists.txt file : set(CMAKE_CXX_FLAGS "your-msvc-debug-options") or set(CMAKE_CXX_DEBUG_FLAGS "your-msvc-debug-options"). You may also use add_compile_options() which will set values for all your project (dependencies included if you build them with CMake)

  • Related