Specify compiler when using CUDA

I try to build a project which uses CUDA. The CUDA on my machine is the newest 9.1. The following error is reported:

In file included from /opt/cuda/include/host_config.h:50:0,
                 from /opt/cuda/include/cuda_runtime.h:78,
                 from <command-line>:0:
/opt/cuda/include/crt/host_config.h:121:2: error: #error -- unsupported GNU version! gcc versions later than 6 are not supported!
 #error -- unsupported GNU version! gcc versions later than 6 are not supported!
  ^~~~~

Check /opt/cuda/include/crt/host_config.h:

#if __GNUC__ > 6

#error -- unsupported GNU version! gcc versions later than 6 are not supported!

#endif /* __GNUC__ > 6 */

The solution is to specify the gcc-6 compiler during running cmake command:

# cmake -DCMAKE_C_COMPILER=gcc-6 -DCMAKE_CXX_COMPILER=g++-6 ..

The reference is here.

Install make before using cmake

Today I tried to build a project, but running “cmake” gave me a strange output:

# cmake ..
CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage

After referring this discussion: CMAKE_MAKE_PROGRAM not found, I suddenly realized that this a new setup server, so make program may not be installed. As expected:

# make
-bash: make: command not found

After installing make, the cmake flow works normally.

Use more instructions in building CMake ExternalProject

When use CMake to build ExternalProject:

ExternalProject_Add(
    ......
)

It seems you can’t add multiple same command, for example, PATCH_COMMAND:

ExternalProject_Add(
    ......
    PATCH_COMMAND ......
    PATCH_COMMAND ......
    ......
)

You may get errors like following:

......
File /usr/bin/patch is read-only; trying to patch anyway
/usr/bin/patch: **** Can't create temporary file /usr/bin/patch.oLnbOsk : Permission denied
......

Instead you can COMMAND to add more instructions:

ExternalProject_Add(
    ......
    PATCH_COMMAND ......
    COMMAND ......
    ......
)

References:
CMake ExternalProject_Add: How to build multiple msbuild targets?;
ExternalProject.