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

Fix Clang/MSVC compile options handling #210

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MEhrn00
Copy link

@MEhrn00 MEhrn00 commented Aug 31, 2024

I noticed an issue with Lexy where it will fail to build on Windows using Clang with the GNU-like command-line.

PS C:\Users\User\Documents\lexy> $env:CXX = 'C:\Program Files\LLVM\bin\clang++.exe'
PS C:\Users\User\Documents\lexy> cmake -G Ninja -B build
-- The CXX compiler identification is Clang 18.1.8 with GNU-like command-line
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Fetching doctest
CMake Deprecation Warning at build/_deps/doctest-src/CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- Configuring done (3.3s)
-- Generating done (0.2s)
-- Build files have been written to: C:/Users/User/Documents/lexy/build
PS C:\Users\User\Documents\lexy> cmake --build .\build\
[0/2] Re-checking globbed directories...
[1/398] Building CXX object tests/CMakeFiles/lexy_test_base.dir/doctest_main.cpp.obj
FAILED: tests/CMakeFiles/lexy_test_base.dir/doctest_main.cpp.obj
C:\PROGRA~1\LLVM\bin\CLANG_~1.EXE -DLEXY_HAS_UNICODE_DATABASE=1 -DLEXY_TEST -IC:/Users/User/Documents/lexy/src/../include -IC:/Users/User/Documents/lexy/build/_deps/doctest-src -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -std=gnu++20 /WX /W3 /D _CRT_SECURE_NO_WARNINGS -Wno-shift-op-parentheses -Wno-parentheses-equality -MD -MT tests/CMakeFiles/lexy_test_base.dir/doctest_main.cpp.obj -MF tests\CMakeFiles\lexy_test_base.dir\doctest_main.cpp.obj.d -o tests/CMakeFiles/lexy_test_base.dir/doctest_main.cpp.obj -c C:/Users/User/Documents/lexy/tests/doctest_main.cpp
clang++: error: no such file or directory: '/WX'
clang++: error: no such file or directory: '/W3'
clang++: error: no such file or directory: '/D'
clang++: error: no such file or directory: '_CRT_SECURE_NO_WARNINGS'
[2/398] Building CXX object src/CMakeFiles/lexy_file.dir/input/file.cpp.obj

This is due to the src/CMakeLists.txt#L180 using CMAKE_CXX_SIMULATE_ID for checking what compile options to add which does not reflect how the command line options are handled.

The CMAKE_CXX_COMPILER_FRONTEND_VARIANT variable has the correct information for determining this.

More information on detecting the differences between clang with the GNU-like command-line and clang-cl with the MSVC-like command-line can be found in this CMake issue https://gitlab.kitware.com/cmake/cmake/-/issues/19724. It looks like these variables were undocumented for a while and only recently added to the CMake documentation.

The changes in this PR should correctly handle Lexy being built using clang or clang-cl on Windows.

Use `CMAKE_LANG_COMPILER_FRONTEND_VARIANT` instead of
`CMAKE_LANG_SIMULATE_ID` for specifying compile flags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant