4

I have a cmake project that uses an external project using CMake's ExternalProject_Add feature. Is there a way to set policy and property on the external project?

I would like following policy and property that is set in my project to be forwarded also to external project so that static multi-threaded windows runtime libraries are used instead of dynamic ones.

cmake_policy(SET CMP0091 NEW)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
harish
  • 1,836
  • 3
  • 21
  • 26
  • 2
    Did you already tried to add them to the `CMAKE_ARGS` variable on the `ExternalProject_Add` command, e.g. `-DCMAKE_POLICY_DEFAULT_CMP0091:STRING=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY:STRING=MultiThreaded$<$:Debug>` ? – vre Feb 25 '20 at 16:29
  • 1
    was not aware policy can be set this way. Tested this now and worked perfectly! can you add this as answer so I can mark as accepted answer. thanks! – harish Feb 25 '20 at 17:18

1 Answers1

5

You can simply add those settings to the CMAKE_ARGS variable of the ExternalProject_Add command, e.g.

ExternalProject_Add(<you_name_it>
  ...
  CMAKE_ARGS
           -DCMAKE_POLICY_DEFAULT_CMP0091:STRING=NEW 
           -DCMAKE_MSVC_RUNTIME_LIBRARY:STRING=MultiThreaded$<$<CONFIG:Debug>:Debug>
           ...
)
vre
  • 6,041
  • 1
  • 25
  • 39