title: Use CMake to set Cuda runtime library (e.g. to MTd instead of MDd)
body: <p>Is there a CMake command that can be used to set the Cuda runtime library (in visual studio under Cuda C/C++ -&gt; Host -&gt; Runtime Library)? For instance I would need to set it to MTd rather than MDd in debug mode, and MT rather than MD in release mode. I can do this manually in visual studio after building, but it would be great to have this be automatic using my CMakeLists.txt file.
  Thanks!</p>
  <p>P.S. I know how to set this for the normal runtime library (not Cuda); this question is specific to the Cuda runtime library.</p>
  <p><strong>UPDATE 2022-01-24</strong>:
  The helpful input has lead me to the CMake variable CMAKE_CUDA_FLAGS_RELEASE which seems to control this. I need to set it like so:
  set(CMAKE_CUDA_FLAGS_RELEASE &quot; -Xcompiler=\&quot;-MT -O2 -Ob2\&quot; -DNDEBUG&quot;)</p>
  <p>But unfortunately it seems to get overwritten for some reason, back to -MD.</p>
  <p><strong>UPDATE 2022-01-25</strong>:
  Example code:</p>
  <pre><code>cmake_minimum_required(VERSION 3.8)
  
  #set(CMAKE_CUDA_RUNTIME_LIBRARY Shared)
  #string(APPEND CMAKE_CUDA_FLAGS_RELEASE_INIT &quot; -Xcompiler=\&quot;-MT -O2 -Ob2\&quot; -DNDEBUG&quot;)
  #set(CMAKE_CUDA_FLAGS_RELEASE_INIT &quot; -Xcompiler=\&quot;-MT -O2 -Ob2\&quot; -DNDEBUG&quot;)
  set(CMAKE_CUDA_FLAGS_RELEASE &quot; -Xcompiler=\&quot;-MT -O2 -Ob2\&quot; -DNDEBUG&quot;)
  
  project(cuda_test_integrated LANGUAGES CUDA CXX)
  
  # multi-threaded
  set(CMAKE_CXX_FLAGS_RELEASE &quot;${CMAKE_CXX_FLAGS_RELEASE} /MT&quot;)
  set(CMAKE_CXX_FLAGS_DEBUG &quot;${CMAKE_CXX_FLAGS_DEBUG} /MTd&quot;)
  
  find_package(CUDAToolkit REQUIRED)
  set(CMAKE_CUDA_ARCHITECTURES OFF)
  
  set(CMAKE_CUDA_FLAGS_RELEASE &quot; -Xcompiler=\&quot;-MT -O2 -Ob2\&quot; -DNDEBUG&quot;)
  
  
  # modules
  include_directories(&quot;../cuda_module_example&quot;)
  add_subdirectory(&quot;../cuda_module_example&quot; &quot;${CMAKE_CURRENT_BINARY_DIR}/cuda_module_example&quot;)
  
  
  include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
  add_executable(cuda_test_integrated main.cxx)
  
  set(CMAKE_CUDA_FLAGS_RELEASE &quot; -Xcompiler=\&quot;-MT -O2 -Ob2\&quot; -DNDEBUG&quot;)
  
  set_target_properties(cuda_test_integrated PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
  
  target_link_libraries(cuda_test_integrated CUDA::cudart)
  target_link_libraries(cuda_test_integrated cuda_module_example)
  
  set(CMAKE_CUDA_FLAGS_RELEASE &quot; -Xcompiler=\&quot;-MT -O2 -Ob2\&quot; -DNDEBUG&quot;)
  </code></pre>