0

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?

Yulia
  • 31
  • 8

1 Answers1

1

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.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • If I do the above it is not detecting the riscv64 compiler at all. It is skipping to else condition directly. I tried everything mentioned above. – Yulia Jul 07 '20 at 15:16
  • It works for me if compiler is `foo-riscv64-unknown-elf-g++`. Which compiler do you use, so it doesn't match the regular expression? – Tsyvarev Jul 07 '20 at 15:31
  • (base) k:~ riscv64-unknown-elf-g++ --version riscv64-unknown-elf-g++ (GCC) 9.2.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. – Yulia Jul 07 '20 at 15:33
  • `riscv64-unknown-elf-g++` matches for me too, e.g. using the second approach with `[+]`. Are you sure that `CMAKE_CXX_COMPILER` variable is assigned exactly this value? You may print the value of the variable using `message` command. – Tsyvarev Jul 07 '20 at 15:36
  • To be frank I am new to Linux and just using at the moment to compiler cpp code using riscv64 compiler for a project. But I am unable to compile the code successfully. But when I try this echo $CMAKE_CXX_COMPILER the ouput is nothing. – Yulia Jul 07 '20 at 15:45
  • `CMAKE_CXX_COMPILER` is a **CMake** variable, not an environment one. You may print value of this variable in `CMakeLists.txt` by `message("CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")`. It will be printed during the configuration of your project. Note, that variable `CMAKE_CXX_COMPILER` variable is set inside the `project()` call, so checking it before this call is useless. – Tsyvarev Jul 07 '20 at 15:50
  • I am using mac OS with g++ and riscv64-unknown-elf-g++ installed and trying to compile a cpp code and checking whether the code compiles successfully with riscv64-unknown-elf-g++ compiler. – Yulia Jul 07 '20 at 15:50
  • With that I got this message: CMAKE_CXX_COMPILER: /Library/Developer/CommandLineTools/usr/bin/c++ – Yulia Jul 07 '20 at 15:52
  • how can I assign the value to a CMAKE_CXX_COMPILER variable? – Yulia Jul 07 '20 at 15:53
  • "how can I assign the value to a CMAKE_CXX_COMPILER variable?" - Just google for "cmake set compiler". See e.g. that question: https://stackoverflow.com/questions/13054451/unable-to-specify-the-compiler-with-cmake – Tsyvarev Jul 07 '20 at 15:57
  • Thank you will take a look at it. – Yulia Jul 07 '20 at 15:59