JochenKalmbach / StackWalker

Walking the callstack in windows applications
BSD 2-Clause "Simplified" License
831 stars 182 forks source link

Possibly could remove $<BUILD_INTERFACE: from cmakelists.txt #50

Open Sebanisu opened 3 years ago

Sebanisu commented 3 years ago

https://github.com/JochenKalmbach/StackWalker/blob/53320512bd2fe1097b85e38262191d7c55210990/CMakeLists.txt#L82

$<BUILD_INTERFACE: prevent including StackWalker.h when using FetchContent to download and link to the library from inside CMake.

If this were removed I could use target_link_libraries(... PRIVATE StackWalker) and then the compiler would know where to look for the StackWalker.h.

My fetch content code with my workaround.

I also had to force the MSVC_RUNTIME_LIBRARY because linker errors in my current setup. Basically all the third party libraries and the main library need to use the same runtime library.

I'm hoping once I have everything dynamically downloading and building I can remove hacks like MSVC_RUNTIME_LIBRARY.

include(FetchContent)
#options for FetchContent are at https://cmake.org/cmake/help/latest/module/ExternalProject.html
FetchContent_Declare(
        stackwalker_fetch
        GIT_REPOSITORY https://github.com/JochenKalmbach/StackWalker.git
        GIT_TAG origin/master
        GIT_REMOTE_UPDATE_STRATEGY CHECKOUT
)
#FetchContent_MakeAvailable(StackWalker)
FetchContent_GetProperties(stackwalker_fetch)
if (NOT stackwalker_fetch_POPULATED)
    FetchContent_Populate(stackwalker_fetch)
    #add_subdirectory(${stackwalker_fetch_SOURCE_DIR} ${stackwalker_fetch_BINARY_DIR} EXCLUDE_FROM_ALL)
    #their cmakelists.txt isn't friendly to including via fetch content.-
    add_library(stackwalker_paths STATIC
            ${stackwalker_fetch_SOURCE_DIR}/Main/StackWalker/StackWalker.cpp
            )
    target_include_directories(stackwalker_paths
            PUBLIC ${stackwalker_fetch_SOURCE_DIR}/Main/StackWalker
            )
    set_target_properties(stackwalker_paths PROPERTIES
            MSVC_RUNTIME_LIBRARY "MultiThreadedDebug" # cl : Command line warning D9025 : overriding '/MD' with '/MTd'
            )
endif ()