Static runtime library

I need to compile executable with static runtime library for compilers msvc, gcc, clang. For msvc I do and it completely work

set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
        set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
        set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
        set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")

For mingw gcc I do

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -static-libgcc -static-libstdc++"

And with this I still have dependency of msvcrt.dll
For clang I do

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static"

With this I still have a lot of dependencies. I tried to remove flag -D_DLL and it didn’t worked

So what is the best solution to get rid of all dependencies?

I don’t know if it will resolve your problem of dependency (should be related to used generator, I guess), but uoutd use add_compile_options():

add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/MP>)
add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/MTd>)

Ideally you have the targets defined as STATIC in any of the find_package, find_library, add_library, then it should be automatically handled when you use target_link_libraries. If that is nit the case, it seems like a bug in the language definition section for the specific compiler.