Timo
Timo

Reputation: 121

Ninja: No CMAKE_RC_COMPILER could be found

CMake is not finding the clang rc compiler. It is possible to set it for cmake, which makes it run successfully, but ninja will fail while trying to compile gtest.

Hello, i am trying to set up a simple test project using Ninja, CMake and Clang.

I am running a windows 10 pro enviroment and have the following versions installed:

I have tried to:

This lets me pass the first cmake run, but when running ninja it internally calls cmake for a second time on the gtest project and fails with the same error.

I do not want to fork the gtest project or change the cmakecache file.

CMakeFile.txt

cmake_minimum_required (VERSION 3.1)

# this does not fix it.
# set("RC" "llvm-rc")

# running cmake with -D CMAKE_RC_COMPILER="llvm-rc"

project (ExampleProject)

# setup cmake extensions.
include(ExternalProject)

# setup project configuration.

set (ExampleProject_VERSION_MAJOR 0)
set (ExampleProject_VERSION_MINOR 0)

set (CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# configure cmake variables.

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)
set(EXTERNAL_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/external)

# install gtest.

ExternalProject_Add(googletest
    GIT_REPOSITORY https://github.com/google/googletest
    CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
)

# include extensions.
include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)

add_executable(run main.cxx)

main.cxx

#include <iostream>

int main(int arcv, char** argv) {
    std::cout << "Hello world!" << std::endl;
}

To build it i currently use the following commands:

cmake -G Ninja -B build .
cd build
ninja

I expect the compiler chain to compile the project successfully and to create a binary file which will output: "Hello world!".

Currently it fails with not finding the rc compiler in main project or while building gtest.

It outputs the following message:

C:\Users\HP\Desktop\projekte\testproject>cmake -GNinja -Bbuild .
-- The C compiler identification is Clang 8.0.0 with GNU-like command-line
-- The CXX compiler identification is Clang 8.0.0 with GNU-like command-line
CMake Error at C:/Program Files/CMake/share/cmake-3.15/Modules/Platform/Windows-Clang.cmake:81 (enable_language):
  No CMAKE_RC_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "RC" or the CMake cache entry CMAKE_RC_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.15/Modules/Platform/Windows-Clang.cmake:121 (__windows_compiler_clang_gnu)
  C:/Program Files/CMake/share/cmake-3.15/Modules/Platform/Windows-Clang-C.cmake:2 (__windows_compiler_clang)
  C:/Program Files/CMake/share/cmake-3.15/Modules/CMakeCInformation.cmake:48 (include)
  CMakeLists.txt:8 (project)


-- Configuring incomplete, errors occurred!
See also "C:/Users/HP/Desktop/projekte/testproject/build/CMakeFiles/CMakeOutput.log".

Or it outputs with the rc compiler set:

C:\Users\HP\Desktop\projekte\testproject>cmake -GNinja -Bbuild . -DCMAKE_RC_COMPILER=llvm-rc
-- The C compiler identification is Clang 8.0.0 with GNU-like command-line
-- The CXX compiler identification is Clang 8.0.0 with GNU-like command-line
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang.exe
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/HP/Desktop/projekte/testproject/build

C:\Users\HP\Desktop\projekte\testproject>cd build

C:\Users\HP\Desktop\projekte\testproject\build>ninja
[4/10] Performing download step (git clone) for 'googletest'
Cloning into 'googletest'...
Already on 'master'
Your branch is up to date with 'origin/master'.
[6/10] Performing update step for 'googletest'
Current branch master is up to date.
[7/10] Performing configure step for 'googletest'
FAILED: googletest-prefix/src/googletest-stamp/googletest-configure
cmd.exe /C "cd /D C:\Users\HP\Desktop\projekte\testproject\build\googletest-prefix\src\googletest-build && "C:\Program Files\CMake\bin\cmake.exe" -DCMAKE_INSTALL_PREFIX=C:/Users/HP/Desktop/projekte/testproject/build/external -GNinja C:/Users/HP/Desktop/projekte/testproject/build/googletest-prefix/src/googletest && "C:\Program Files\CMake\bin\cmake.exe" -E touch C:/Users/HP/Desktop/projekte/testproject/build/googletest-prefix/src/googletest-stamp/googletest-configure"
-- The C compiler identification is Clang 8.0.0 with GNU-like command-line
-- The CXX compiler identification is Clang 8.0.0 with GNU-like command-line
CMake Error at C:/Program Files/CMake/share/cmake-3.15/Modules/Platform/Windows-Clang.cmake:81 (enable_language):
  No CMAKE_RC_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "RC" or the CMake cache entry CMAKE_RC_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.15/Modules/Platform/Windows-Clang.cmake:121 (__windows_compiler_clang_gnu)
  C:/Program Files/CMake/share/cmake-3.15/Modules/Platform/Windows-Clang-C.cmake:2 (__windows_compiler_clang)
  C:/Program Files/CMake/share/cmake-3.15/Modules/CMakeCInformation.cmake:48 (include)
  CMakeLists.txt:10 (project)


-- Configuring incomplete, errors occurred!
See also "C:/Users/HP/Desktop/projekte/testproject/build/googletest-prefix/src/googletest-build/CMakeFiles/CMakeOutput.log".
ninja: build stopped: subcommand failed.

C:\Users\HP\Desktop\projekte\testproject\build>

Upvotes: 7

Views: 5771

Answers (1)

Timo
Timo

Reputation: 121

Its really simple. You can set the cmake_args in the externalProject_Add command.

ExternalProject_Add(
googletest
GIT_REPOSITORY https://github.com/google/googletest
CMAKE_ARGS -DCMAKE_RC_COMPILER=${CMAKE_RC_COMPILER}
)

How to specify the compiler for CMAKE external project?

I refered for more information to the manual located at: https://cmake.org/cmake/help/latest/module/ExternalProject.html

Upvotes: 2

Related Questions