[CMake] In MSVC, how can I link my exe with my library with the same configuration (release, minsizerel) separately

Tyler Roscoe tyler at cryptio.net
Tue Nov 10 16:30:16 EST 2009


On Tue, Nov 10, 2009 at 10:43:49AM -0800, Meng Zhang wrote:
> target_link_libraries(A debug Debug/B)
> target_link_libraries(A optimized Release/B)
> 
>  Nevertheless, obviously, since optimized means all the other three
> configurations except "Debug",  project A won't find library B if I directly
> build "MinSizeRel" version because the compiler can not find library B in
> directory Release/.

If you give target_link_libraries() a "library" that's the name of a
target in your CMake system, CMake will automatically figure out where
it has built that target and will link to it for you.

Thus, all you need to do is:

target_link_libraries(A B)

When you do a Debug build, A will link against the debug B. When you do
a MinSizeRel build, A will link against the minsizerel B.

hth,
tyler


More information about the CMake mailing list