A while ago I did an experiment along the same lines, using something like this 
in CMake/MTflags.cmake.  (What we really needed was forcing /MT 
/D_HAS_ITERATOR_DEBUGGING=0 even on debug builds, because we were using an 
external library only available in /MT format.  So I might have accidentally 
broken it while adapting it here.)

add_library(MTflags INTERFACE)
target_compile_options(MTflags INTERFACE "/MT$<$<CONFIG:Debug>:d>")
set_property(TARGET MTflags
    PROPERTY INTERFACE_MSVC_MT ON)
set_property(TARGET MTflags
    APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL MSVC_MT)

# Example usage:
# include(MTflags)
# add_library(A STATIC src1.cpp src2.cpp...)
# target_link_libraries(A PUBLIC MTflags)

That almost did what we wanted.  The biggest problem (and the one annoying 
enough to make me abandon the experiment for the time being) was: if you 
configured using the "NMake Makefiles" generator, then the compiler would give 
a warning on each source file because the build system was passing both the 
default /MD[d] and the additional /MT.
--
Daniel Schepler
________________________________
From: CMake [cmake-boun...@cmake.org] on behalf of Walter Gray 
[chrysal...@gmail.com]
Sent: Thursday, June 09, 2016 1:58 PM
To: Cmake Mailing List
Subject: [CMake] MSVC /M[TD]<d> as a compatible interface property?

Setting /MT or /MD is pretty important, and is a transitive requirement. See: 
https://msdn.microsoft.com/en-us/library/2kzt1wy3(VS.80).aspx

The standard mechanism of using target_compile_options isn't quite appropriate 
because it will simply append the flags used by each library and use the last 
one with no complaint if there is a mismatch.

Example:
A uses /MT, B uses /MD, C Depends on both.
This will result in errors when compiling, but will configure just fine. I 
would like to make it so that if there is a mismatch between linked targets, 
cmake will either fail or issue a warning.

https://cmake.org/cmake/help/v3.5/manual/cmake-buildsystem.7.html#compatible-interface-properties
This seems to be meant to be used for exactly this type of thing, but because 
there is no specific property for specifying MSVC_RUNTIME, that system cannot 
be used in this case.

Any thoughts on how to address this?

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to