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

work around bug in CMake 3.22.1 bug in CMP0128 policy, for compiling SPIRV-Tools tests #1350

Open
dneto0 opened this issue Jul 19, 2023 · 2 comments

Comments

@dneto0
Copy link
Collaborator

dneto0 commented Jul 19, 2023

This bug in the OLD implementation in CMake 3.22.1 is causing SPIR-V Tools test code to compile with tailing -std=c++11 when it really needs -std=c++17 to take effect.

A fix is
cmake_policy(SET CMP0128 NEW)

The bug is fixed in CMake 3.22.2

When the bug is present, I get a build.ninja lines like this:

build third_party/spirv-tools/test/CMakeFiles/test_spirv_unit_tests.dir/binary_destroy_test.cpp.o: CXX_COMPILER__test_spirv_unit_tests_Release /build/ndk/external/shaderc/spirv-tools/test/binary_destroy_test.cpp || cmake_object_order_depends_target_test_spirv_unit_tests
DEFINES = -DSPIRV_COLOR_TERMINAL -DSPIRV_LINUX -DSPIRV_TIMER_ENABLED
DEP_FILE = third_party/spirv-tools/test/CMakeFiles/test_spirv_unit_tests.dir/binary_destroy_test.cpp.o.d
FLAGS = --target=x86_64-linux-gnu --sysroot=/project/ndk/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/sysroot -L/project/ndk/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/lib/gcc/x86_64-linux/4.8.3 -B/project/ndk/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/lib/gcc/x86_64-linux/4.8.3 -L/project/ndk/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/x86_64-linux/lib64 -B/project/ndk/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/x86_64-linux/lib64 -L/project/ndk/prebuilts/clang/host/linux-x86/clang-r498229/lib64 -B/project/ndk/prebuilts/clang/host/linux-x86/clang-r498229/lib64 -Os -fomit-frame-pointer -s -fuse-ld=lld -Wno-unused-command-line-argument -fno-rtti -fno-exceptions -stdlib=libc++ -Wimplicit-fallthrough -O3 -DNDEBUG -fPIE -Wextra-semi -w -Wall -Wextra -Wnon-virtual-dtor -Wno-missing-field-initializers -Wno-self-assign -Werror -Wno-long-long -Wshadow -Wundef -Wconversion -Wno-sign-conversion -fno-exceptions -ftemplate-depth=1024 -Wno-undef -Wno-shadow -std=c++11 -pthread
INCLUDES = -I/build/ndk/external/shaderc/spirv-tools -I/project/ndk/external/shaderc/spirv-headers/include -I/build/ndk/external/shaderc/spirv-tools/include -I/build/ndk/external/shaderc/spirv-tools/test -I/build/ndk/out/linux/shader-tools/build/third_party/spirv-tools -I/build/ndk/external/effcee -I/build/ndk/external/effcee/effcee/.. -I/build/ndk/external/regex-re2 -isystem /build/ndk/external/googletest/googletest/include -isystem /build/ndk/external/googletest/googlemock/include -isystem /build/ndk/external/googletest/googlemock -isystem /build/ndk/external/googletest/googletest
OBJECT_DIR = third_party/spirv-tools/test/CMakeFiles/test_spirv_unit_tests.dir
OBJECT_FILE_DIR = third_party/spirv-tools/test/CMakeFiles/test_spirv_unit_tests.dir

When I set the policy to NEW, and in 3.22.2 and later, I get a configuration line like this for one particular object compilation. I have bolded the operative parts, which is at the end of the FLAGS line.

build third_party/spirv-tools/test/CMakeFiles/test_spirv_unit_tests.dir/binary_destroy_test.cpp.o: CXX_COMPILER__test_spirv_unit_tests_Release /build/ndk/external/shaderc/spirv-tools/test/binary_destroy_test.cpp || cmake_object_order_depends_target_test_spirv_unit_tests
DEFINES = -DSPIRV_COLOR_TERMINAL -DSPIRV_LINUX -DSPIRV_TIMER_ENABLED
DEP_FILE = third_party/spirv-tools/test/CMakeFiles/test_spirv_unit_tests.dir/binary_destroy_test.cpp.o.d
FLAGS = --target=x86_64-linux-gnu --sysroot=/project/ndk/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/sysroot -L/project/ndk/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/lib/gcc/x86_64-linux/4.8.3 -B/project/ndk/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/lib/gcc/x86_64-linux/4.8.3 -L/project/ndk/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/x86_64-linux/lib64 -B/project/ndk/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/x86_64-linux/lib64 -L/project/ndk/prebuilts/clang/host/linux-x86/clang-r498229/lib64 -B/project/ndk/prebuilts/clang/host/linux-x86/clang-r498229/lib64 -Os -fomit-frame-pointer -s -fuse-ld=lld -Wno-unused-command-line-argument -fno-rtti -fno-exceptions -stdlib=libc++ -Wimplicit-fallthrough -O3 -DNDEBUG -fPIE -Wextra-semi -w -Wall -Wextra -Wnon-virtual-dtor -Wno-missing-field-initializers -Wno-self-assign -Werror -Wno-long-long -Wshadow -Wundef -Wconversion -Wno-sign-conversion -fno-exceptions -ftemplate-depth=1024 -Wno-undef -Wno-shadow -std=c++11 -pthread -std=c++17
INCLUDES = -I/build/ndk/external/shaderc/spirv-tools -I/project/ndk/external/shaderc/spirv-headers/include -I/build/ndk/external/shaderc/spirv-tools/include -I/build/ndk/external/shaderc/spirv-tools/test -I/build/ndk/out/linux/shader-tools/build/third_party/spirv-tools -I/build/ndk/external/effcee -I/build/ndk/external/effcee/effcee/.. -I/build/ndk/external/regex-re2 -isystem /build/ndk/external/googletest/googletest/include -isystem /build/ndk/external/googletest/googlemock/include -isystem /build/ndk/external/googletest/googlemock -isystem /build/ndk/external/googletest/googletest
OBJECT_DIR = third_party/spirv-tools/test/CMakeFiles/test_spirv_unit_tests.dir
OBJECT_FILE_DIR = third_party/spirv-tools/test/CMakeFiles/test_spirv_unit_tests.dir

The correct compilation has the -std=c++17 option which is required for the target.

@dneto0
Copy link
Collaborator Author

dneto0 commented Jul 19, 2023

I found this when building the Android NDK with updated sources for Shaderc and SPIRV-Tools.
The Android NDK uses a prebuild of CMake 3.22.1. Neither Shaderc or SPIRV-Tools sets the CMP0128 policy, so by default it gets the old behaviour, and the bug appears. This prevents building, and in particular prevents updates of shader-tools in the NDK.

dneto0 added a commit to dneto0/shaderc that referenced this issue Jul 19, 2023
Work around a problem in CMake 3.22.1 in setting -std=c++17.
Instead -std=c++11 is in effect for targets in test/*, but those targets require C++17.

Fixes compiling SPIRV-Tools test targets in with certain Clang
and CMake combinations.  Fixes a problem when trying to refresh
shader-tools in the Android NDK.

Fixes: google#1350
@dneto0
Copy link
Collaborator Author

dneto0 commented Jul 19, 2023

This can only be fixed in SPIRV-Tools.

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 a pull request may close this issue.

1 participant