how cmake Error in compiling for riscv64-unknown-elf-g++

620 Views Asked by At

The error looks like the below when I cmake .. from the terminal:

(base) k:~ cd /Users/yuli/Documents/version3/cpp/
(base) k:~ ls
CMakeLists.txt      src
riscv-gnu-toolchain test
(base) k:~ mkdir build
(base) k:~ cd build
(base) k:~ cmake ..
-- The C compiler identification is AppleClang 11.0.3.11030032
-- The CXX compiler identification is AppleClang 11.0.3.11030032
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- 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: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
RegularExpression::compile(): Nested *?+.
RegularExpression::compile(): Error in compile.
CMake Error at CMakeLists.txt:10 (if):
  if given arguments:

    "/Library/Developer/CommandLineTools/usr/bin/c++" "MATCHES" ".*riscv64-unknown-elf-g++"

  Regular expression ".*riscv64-unknown-elf-g++" cannot compile


-- Configuring incomplete, errors occurred!
See also "/Users/yuli/Documents/version3/cpp/build/CMakeFiles/CMakeOutput.log".

I tried "STREQUAL" instead of MATCHES but didn't work. any idea what might be wrong in here?

CMakeLists.txt as follows:

cmake_minimum_required(VERSION 3.13)
project(ofdmchain)

set(CMAKE_CXX_FLAGS "-std=c++14")

add_definitions(-DCOMPILES_ON_PC -Wall -Wextra)

configure_file(${CMAKE_SOURCE_DIR}/src/config.hpp.in ${CMAKE_BINARY_DIR}/config.hpp)

if("${CMAKE_CXX_COMPILER}" MATCHES ".*riscv64-unknown-elf-g++")
  message(STATUS "Compiling RISCV")
  SET(RISCV 1)
else()
  message(STATUS "Compiling X86")
  SET(RISCV 0)
endif()

add_library(ofdm
  src/transmitter.cpp
  src/configuration.cpp

  src/ofdm.hpp
  src/datatypes.hpp
  )
target_include_directories(ofdm PRIVATE ${CMAKE_SOURCE_DIR}/../reference_matlab)
target_include_directories(ofdm PRIVATE ${CMAKE_SOURCE_DIR}/src/)

if (NOT ${RISCV})
  add_executable(unit_tests
    test/catch_main.cpp
    test/test_sanity.cpp
    test/test_utilities.cpp
    test/test_transmitter.cpp
    )
  target_include_directories(unit_tests PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
  target_include_directories(unit_tests PUBLIC ${CMAKE_SOURCE_DIR}/src)
  target_link_libraries(unit_tests ofdm)
endif()

I have also tried adding ++ where g++ exits as well as - where - exists. And also have tired "STREQUAL" instead of "MATCHES" it didn't work either. It could be the problem of c++ in the PATH?

1

There are 1 best solutions below

11
On

CMake "internal error"

RegularExpression::compile(): Nested *?+.

is about the last two + characters: in regular expressions such characters has special meaning.

Ways for make + character (and other special characters) to be treated literally:

  1. Escape the character with \. Note, that escape character by itself should be escaped in CMake string, so you need to write it twice:

    if("${CMAKE_CXX_COMPILER}" MATCHES ".*riscv64-unknown-elf-g\\+\\+")
    
  2. Put the character into square brackets ([]). Inside [] all special characters loose their special meaning:

    if("${CMAKE_CXX_COMPILER}" MATCHES ".*riscv64-unknown-elf-g[+][+]")
    

Note also, that in certain if conditions one doesn't need to explicitly dereference the variable: CMake does that by itself.

So, it is possible to write

if(CMAKE_CXX_COMPILER MATCHES ".*riscv64-unknown-elf-g[+][+]")

See more in the documentation for if command.