[CMake] FindCUDA discard any previous value of CUDA_USE_STATIC_CUDA_RUNTIME

James Bigler jamesbigler at gmail.com
Tue Oct 13 11:10:08 EDT 2015


Yeah, I thought about this method yesterday, but I'm not really excited
about this approach.  It adds yet another variable for the configuration
that doesn't really match the others.  Granted the behavior of the other
FindCUDA options allow setting it before the first FindCUDA invocation, so
there is already the loss of symmetry.

If you were to do this from the GUI, you would configure once, change the
defaults to your liking and configure a second time.  You would only need
this FORCED version of the variable to bypass the default behavior and only
on the first configure.

I'll need to consider this some more.

I'm not trying to dissuade you from wanting the shared version of cudart,
but why isn't the static library desirable in your case?  You can reply
just to me if you want.

On Tue, Oct 13, 2015 at 8:51 AM Thibaut Neiger <thibaut.neiger at gmail.com>
wrote:

> Maybe we could make the FindCUDA script check if the caller defined that
> variable prior to any inclusion. If the user did, then FindCUDA should
> respect the caller choice.
> Something like that would make the trick:
>
> if(NOT DEFINED CUDA_USE_STATIC_CUDA_RUNTIME_FORCED)
>   if(DEFINED CUDA_USE_STATIC_CUDA_RUNTIME)
>     set(CUDA_USE_STATIC_CUDA_RUNTIME_FORCED TRUE CACHE INTERNAL "If user
> forced static cuda runtime variable.")
>   else()
>     set(CUDA_USE_STATIC_CUDA_RUNTIME_FORCED FALSE CACHE INTERNAL "If user
> forced static cuda runtime variable.")
>   endif()
> endif()
> ...
> macro(cuda_unset_include_and_libraries)
>   ...
>   if(NOT CUDA_USE_STATIC_CUDA_RUNTIME_FORCED )
>     unset(CUDA_USE_STATIC_CUDA_RUNTIME CACHE)
>   endif()
> endmacro()
>
>
> Le lun. 12 oct. 2015 à 14:32, James Bigler <jamesbigler at gmail.com> a
> écrit :
>
>> Whether you can use the static runtime is based on the toolkit found, so
>> if you change the toolkit (checked with the CUDA_TOOLKIT_ROOT_DIR_INTERNAL
>> variable) we need to reset all dependent values.
>>
>> I don't see a clean way to get this to work in the way you want.  The
>> script can't tell the difference between you setting the value, and the
>> value being there from a previous toolkit.
>>
>> I don't see the problem of this code:
>>
>>
>> set(CUDA_TOOLKIT_ROOT_DIR "d:/work/CUDAToolkit")
>> find_package(CUDA)
>> unset(CUDA_USE_STATIC_CUDA_RUNTIME CACHE)
>> option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
>> find_package(CUDA)
>>
>> Or you could set the internal version of the
>> CUDA_TOOLKIT_ROOT_DIR_INTERNAL at the same time you set the
>> CUDA_TOOLKIT_ROOT_DIR:
>>
>> option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
>> set(CUDA_TOOLKIT_ROOT_DIR "d:/work/CUDAToolkit")
>> set(CUDA_TOOLKIT_ROOT_DIR_INTERNAL "${CUDA_TOOLKIT_ROOT_DIR}")
>>
>> message(STATUS CUDA_USE_STATIC_CUDA_RUNTIME=$
>> {CUDA_USE_STATIC_CUDA_RUNTIME})
>> find_package(CUDA)
>>
>> James
>>
>> On Tue, Oct 6, 2015 at 11:49 AM, Thibaut Neiger <thibaut.neiger at gmail.com
>> > wrote:
>>
>>> Hello.
>>> I am using cmake 3.3.2.
>>> The following script sets the CUDA_USE_STATIC_CUDA_RUNTIME option, then
>>> finds the CUDA package.
>>>
>>> cmake_minimum_required(VERSION 3.3)
>>> option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
>>> set(CUDA_TOOLKIT_ROOT_DIR "d:/work/CUDAToolkit")
>>> message(STATUS
>>> CUDA_USE_STATIC_CUDA_RUNTIME=${CUDA_USE_STATIC_CUDA_RUNTIME})
>>> find_package(CUDA)
>>> message(STATUS
>>> CUDA_USE_STATIC_CUDA_RUNTIME=${CUDA_USE_STATIC_CUDA_RUNTIME})
>>>
>>> In the find_package, the variable CUDA_TOOLKIT_ROOT_DIR is compared to
>>> the variable CUDA_TOOLKIT_ROOT_DIR_INTERNAL (line 556). Since this variable
>>> is not defined, the cuda_unset_include_and_libraries function is called.
>>> This function wipes the CUDA_USE_STATIC_CUDA_RUNTIME option from the cache.
>>>
>>> In order to correctly set this variable, I need to restart change it
>>> back to OFF, then the FindCUDA script doesn't call
>>> cuda_unset_include_and_libraries function.
>>> Thibaut.
>>>
>> --
>>>
>>> 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
>>>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20151013/e7243bfa/attachment.html>


More information about the CMake mailing list