MantisBT - CMake
View Issue Details
0015723CMakeCMakepublic2015-09-02 06:312016-02-01 09:10
Adam Strzelecki 
Rolf Eike Beer 
normalmajoralways
closedfixed 
CMake 3.3.1 
CMake 3.4CMake 3.4 
0015723: Regression: FindCUDA fails for C++ only projects in CMake 3.3.1 due find_package(Threads), while it works well in CMake 3.2.3
CUDA language is C++ superset, so developers may prefer using C++ only project together with CUDA. FindCUDA already supports such case (1) when neither CUDA_HOST_COMPILER nor CMAKE_C_COMPILER is defined, just skips adding --ccbin.

Another case (2) is that user defined its own CUDA_HOST_COMPILER that is different than CMAKE_C_COMPILER, then custom host compiler is passed to --ccbin.

The problem is that recently CUDA_USE_STATIC_CUDA_RUNTIME (default ON) started calling find_package(Threads REQUIRED) that tries to lookup pthread using CMAKE_C_COMPILER which is invalid in both cases (1) (2).

However I don't see any clear solution here. I understand that linking CUDA static rt requires pthread linkage, but maybe we should just check if current linker can either link -lpthread or -pthread, rather falling back to C compiler that may be undefined for the project?
# CMakeList.txt
cmake_minimum_required(VERSION 2.6)
project(OnlyCXXCUDA CXX)
find_package(CUDA)


$ cmake .
-- The CXX compiler identification is AppleClang 7.0.0.7000059
-- Check for working CXX compiler: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for include file pthread.h
CMake Error at /Applications/CMake.app/Contents/share/cmake-3.3/Modules/CheckIncludeFiles.cmake:79 (try_compile):
  Unknown extension ".c" for file

    /Users/ono/Documents/Bugs/CMake/FindCUDA/CMakeFiles/CMakeTmp/CheckIncludeFiles.c

  try_compile() works only for enabled languages. Currently these are:

    CXX

  See project() command to enable other languages.
Call Stack (most recent call first):
  /Applications/CMake.app/Contents/share/cmake-3.3/Modules/FindThreads.cmake:123 (CHECK_INCLUDE_FILES)
  /Applications/CMake.app/Contents/share/cmake-3.3/Modules/FindCUDA.cmake:741 (find_package)
  CMakeLists.txt:3 (find_package)


-- Looking for include file pthread.h - not found
CMake Error at /Applications/CMake.app/Contents/share/cmake-3.3/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
  Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
  /Applications/CMake.app/Contents/share/cmake-3.3/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
  /Applications/CMake.app/Contents/share/cmake-3.3/Modules/FindThreads.cmake:204 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  /Applications/CMake.app/Contents/share/cmake-3.3/Modules/FindCUDA.cmake:741 (find_package)
  CMakeLists.txt:3 (find_package)


-- Configuring incomplete, errors occurred!
See also "/Users/ono/Documents/Bugs/CMake/FindCUDA/CMakeFiles/CMakeOutput.log".
See also "/Users/ono/Documents/Bugs/CMake/FindCUDA/CMakeFiles/CMakeError.log".
No tags attached.
related to 0015482closed James Bigler CUDA - Support Static Linked Binaries. 
related to 0014905closed Rolf Eike Beer FindThreads doesn't clearly express it requires C language enabled. 
Issue History
2015-09-02 06:31Adam StrzeleckiNew Issue
2015-09-02 09:04Brad KingRelationship addedrelated to 0015482
2015-09-02 09:05Brad KingNote Added: 0039363
2015-09-02 09:06Brad KingTarget Version => CMake 3.4
2015-09-02 09:13Brad KingNote Added: 0039364
2015-09-10 14:12Thiago M.Note Added: 0039399
2015-09-10 14:16Thiago M.Note Edited: 0039399bug_revision_view_page.php?bugnote_id=39399#r1889
2015-09-10 14:18Brad KingRelationship addedrelated to 0014905
2015-09-14 14:07Brad KingTarget VersionCMake 3.4 =>
2015-09-23 05:42Rolf Eike BeerNote Added: 0039473
2015-09-25 10:14Brad KingNote Added: 0039479
2015-09-25 10:14Brad KingAssigned To => Rolf Eike Beer
2015-09-25 10:14Brad KingStatusnew => resolved
2015-09-25 10:14Brad KingResolutionopen => fixed
2015-09-25 10:14Brad KingFixed in Version => CMake 3.4
2015-09-25 10:14Brad KingTarget Version => CMake 3.4
2016-02-01 09:10Robert MaynardNote Added: 0040418
2016-02-01 09:10Robert MaynardStatusresolved => closed

Notes
(0039363)
Brad King   
2015-09-02 09:05   
For issue 0015482 this change was made:

 FindCUDA: Use the static CUDA runtime library if available
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7fea2b77 [^]

That also hard-codes use of CMAKE_C_FLAGS.
(0039364)
Brad King   
2015-09-02 09:13   
FindThreads should be fixed to work when C is not enabled. It could also be taught to fail with a nicer message when neither C nor CXX is enabled.
(0039399)
Thiago M.   
2015-09-10 14:12   
(edited on: 2015-09-10 14:16)
The fix to FindThreads to work when C is not enabled is suggested in issue 0014905.

(0039473)
Rolf Eike Beer   
2015-09-23 05:42   
The limitation to C should be gone now, there are patches in next that should make FindThreads.cmake work in projects where only C++ is enabled.
(0039479)
Brad King   
2015-09-25 10:14   
Eike's topic to fix FindThreads with only CXX enabled has been merged to 'master' here:

 Merge topic 'Threads-CXX'
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=910ea210 [^]
(0040418)
Robert Maynard   
2016-02-01 09:10   
Closing resolved issues that have not been updated in more than 4 months.