2

I have a CMakeLists.txt that specifies multiple executables. For only one of these projects, I'm wanting to use the Static Runtime.

I found this solution here: Setting the MSVC runtime in CMake

This involves changed the CMAKE_CXX_FLAGS and CMAKE_C_FLAGS (as well as others).

However, doing something like this will change the runtime library for every project. With my testing, doesn't matter where you set these, it changes it for everything.

Is there any way to do this for just one project?

Community
  • 1
  • 1
AdmiralJonB
  • 2,038
  • 3
  • 23
  • 27

1 Answers1

2

You'd be able to do this if you give your "Static Runtime" executable its own CMakeLists.txt file and include it from the parent one via add_subdirectory.

Variables set in the subdirectory CMakeLists.txt don't affect similar ones in the parent scope, so you can have the /MD or /MDd flags in the parent CMAKE_<LANG>_FLAGS_<BUILD>, and replace these with /MT or /MTd in the subdirectory.

Note that even though the command is called add_subdirectory, it need not refer to an actual subdirectory in the filesystem sense - just some other directory with its own CMakeLists.txt.

Fraser
  • 74,704
  • 20
  • 238
  • 215
  • Sorry for not replying earlier, I've had mountains of problems with my computer pretty much as soon as I posted this message. Just getting it up and running so I'll test this soon. While I'm sure this will work, seems a bit of a work around to me. One Question: If I do use a seperate CMakeLists.txt file, can I access that target in the parent? I have included directories etc. in the parent. – AdmiralJonB Mar 21 '13 at 09:28
  • @AdmiralJonB - Yes, the target will be available in the parent CMakeList scope. – Fraser Mar 21 '13 at 10:49