Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake error relating to REGEX and CORRADE_CXX_FLAGS #457

Closed
TimYorke opened this issue Jul 15, 2020 · 6 comments
Closed

cmake error relating to REGEX and CORRADE_CXX_FLAGS #457

TimYorke opened this issue Jul 15, 2020 · 6 comments

Comments

@TimYorke
Copy link

TimYorke commented Jul 15, 2020

After installing Magnum using vcpkg (x64-windows), I got this error when trying to configure my cmake project:

CMake Error at C:/Users/timyo/dev/libs/vcpkg/installed/x64-windows/share/cmake/Corrade/UseCorrade.cmake:302 (string): string sub-command REGEX, mode REPLACE needs at least 6 arguments total to command. Call Stack (most recent call first): C:/Users/timyo/dev/libs/vcpkg/installed/x64-windows/share/cmake/Corrade/FindCorrade.cmake:592 (include) C:/Users/timyo/dev/libs/vcpkg/installed/x64-windows/share/cmake/Corrade/CorradeConfig.cmake:26 (include) C:/Users/timyo/dev/libs/vcpkg/scripts/buildsystems/vcpkg.cmake:439 (_find_package) C:/Users/timyo/dev/libs/vcpkg/installed/x64-windows/share/cmake/Magnum/FindMagnum.cmake:233 (find_package) C:/Users/timyo/dev/libs/vcpkg/installed/x64-windows/share/cmake/Magnum/MagnumConfig.cmake:26 (include) C:/Users/timyo/dev/libs/vcpkg/scripts/buildsystems/vcpkg.cmake:439 (_find_package) CMakeLists.txt:6 (find_package)

I guessed that it was because CORRADE_CXX_FLAGS wasn't set, and worked around it by adding a check for this before the REGEX command.

@mosra mosra added this to the 2020.0b milestone Jul 16, 2020
@mosra mosra added this to TODO in Platforms via automation Jul 16, 2020
@mosra
Copy link
Owner

mosra commented Jul 16, 2020

Hi!

I looked into UseCorrade.cmake and can't find a code path that would result in empty/unset CORRADE_CXX_FLAGS. Are you using a compiler other than MSVC or clang-cl?

In any case, I think the following patch should make it work without an additional check -- can you confirm?

diff --git a/modules/UseCorrade.cmake b/modules/UseCorrade.cmake
index 8276c71a..34188016 100644
--- a/modules/UseCorrade.cmake
+++ b/modules/UseCorrade.cmake
@@ -299,7 +299,7 @@ if(CORRADE_BUILD_DEPRECATED)
     string(REPLACE ";" " " CORRADE_CXX_FLAGS "${CORRADE_CXX_FLAGS}${CORRADE_PEDANTIC_COMPILER_OPTIONS}")
 
     # Remove generator expressions that distinct between C and C++
-    string(REGEX REPLACE "\\$<\\$<STREQUAL:\\$<TARGET_PROPERTY:LINKER_LANGUAGE>,CXX>:([^>]+)>" "\\1" CORRADE_CXX_FLAGS ${CORRADE_CXX_FLAGS})
+    string(REGEX REPLACE "\\$<\\$<STREQUAL:\\$<TARGET_PROPERTY:LINKER_LANGUAGE>,CXX>:([^>]+)>" "\\1" CORRADE_CXX_FLAGS "${CORRADE_CXX_FLAGS}")
 endif()
 
 # Provide a way to distinguish between debug and release builds via

@TimYorke
Copy link
Author

Hi Mosra. I can confirm your patch works fine. As for why CORRADE_CXX_FLAGS is empty, I haven't investigated, but this is my CMakeLists.txt if it helps (I'm using MSVC):

cmake_minimum_required(VERSION 3.0.0)
cmake_policy(SET CMP0054 OLD)
project(LearnOpenGL VERSION 0.1.0 LANGUAGES CXX)  
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

find_package(Magnum CONFIG REQUIRED Sdl2Application Shaders GL Trade MeshTools Primitives AnySceneImporter)
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${MAGNUM_INCLUDE_DIR})
set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS ON)

file(GLOB_RECURSE SOURCES
    src/*.cpp
)

add_executable(LearnOpenGL ${SOURCES})
set_property(TARGET LearnOpenGL PROPERTY CXX_STANDARD 20)
SET_PROPERTY (TARGET LearnOpenGL PROPERTY CXX_STANDARD_REQUIRED ON)

target_link_libraries(LearnOpenGL PRIVATE Magnum::Magnum Magnum::Application Magnum::Shaders Magnum::GL Magnum::Trade Magnum::MeshTools Magnum::Primitives Magnum::AnySceneImporter)

@mosra
Copy link
Owner

mosra commented Jul 16, 2020

Oh, the CMP0054 might actually be the culprit. Can you try with

cmake_minimum_required(VERSION 3.4) # minimum required by Magnum
# no cmake_policy(SET CMP0054 OLD)

instead? That way it should work even without the above patch.

@TimYorke
Copy link
Author

Okay. First I tried the configure step without setting the CMP0054 policy but that made no difference except for also producing a lot of CMP0054-related warnings.
Then I tried changing the minimum cmake version from 3.0 to 3.4 and that stopped both the CMP0054 warnings and the REGEX error in one hit.
It was my mistake - I didn't know that the cmake_minimum_required() command actually changes cmake's behaviour by implicitly invoking cmake_policy().

Sorry for the false alarm and thanks for your help.

@TimYorke
Copy link
Author

The problem was caused by calling cmake_minimum_required() with the wrong version

Platforms automation moved this from TODO to Done Jul 16, 2020
@mosra
Copy link
Owner

mosra commented Jul 16, 2020

No problem -- I think this error could still happen with unrecognized compilers (such as ICC), so I commited the patch as mosra/corrade@5aa75d4. Thanks for testing it! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Platforms
  
Done
Development

No branches or pull requests

2 participants