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 Hardening options and LTO for multi-configuration generators #260

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

FeignClaims
Copy link
Contributor

fix #259 by using generator expressions and CMAKE_INTERPROCEDURAL_OPTIMIZATION_<CONFIG>.

@FeignClaims
Copy link
Contributor Author

FeignClaims commented May 19, 2024

From my personal test on MacOS M1 (unfortunately not implementable in Github Actions yet), check_ipo_supported() falsely failed because it can't find clang-scan-deps for "" -format=p1689.

The problem is that CMake 3.23 and below run the check with the current environment and toolchain settings. Since we specify cmake_minimum_required(VERSION 3.20) in Index.cmake, it performs as if cmake is v3.20, but CMake supports C++ Modules only after 3.28.

Here're two possible solutions:

  • (chosen) In Index.cmake, use cmake_minimum_required(VERSION 3.24) instead of cmake_minimum_required(VERSION 3.20), which makes check_ipo_supported() prefer to honor the calling project's flags.
  • Instead of calling enable_interprocedural_optimization() inside Index.cmake, force users to call enable_interprocedural_optimization(<prefix>_project_options) themselves in their project.
error log
CMake Warning at build/clang/_deps/_sample_project_project_options-src/src/Optimization.cmake:20 (message):
  Interprocedural Optimization is not supported.  Not using it.  Here is the
  error log: Change Dir:
  '/Users/feignclaims/code/cpp/cpp_conan_template/build/clang/CMakeFiles/_CMakeLTOTest-CXX/bin'




  Run Build Command(s): /opt/homebrew/bin/ninja -v

  [1/8] "" -format=p1689 -- /opt/homebrew/opt/llvm/bin/clang++
  -DCMAKE_INTDIR=\"Debug\" -stdlib=libc++ -L/opt/homebrew/opt/llvm/lib/c++
  -Wno-unused-command-line-argument -g -std=c++26 -flto=thin -arch arm64
  -isysroot
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk
  -fPIC -x c++
  /Users/feignclaims/code/cpp/cpp_conan_template/build/clang/CMakeFiles/_CMakeLTOTest-CXX/src/foo.cpp
  -c -o CMakeFiles/foo.dir/Debug/foo.cpp.o -resource-dir
  "/opt/homebrew/Cellar/llvm/18.1.5/lib/clang/18" -MT
  CMakeFiles/foo.dir/Debug/foo.cpp.o.ddi -MD -MF
  CMakeFiles/foo.dir/Debug/foo.cpp.o.ddi.d >
  CMakeFiles/foo.dir/Debug/foo.cpp.o.ddi.tmp && mv
  CMakeFiles/foo.dir/Debug/foo.cpp.o.ddi.tmp
  CMakeFiles/foo.dir/Debug/foo.cpp.o.ddi

  FAILED: CMakeFiles/foo.dir/Debug/foo.cpp.o.ddi

  "" -format=p1689 -- /opt/homebrew/opt/llvm/bin/clang++
  -DCMAKE_INTDIR=\"Debug\" -stdlib=libc++ -L/opt/homebrew/opt/llvm/lib/c++
  -Wno-unused-command-line-argument -g -std=c++26 -flto=thin -arch arm64
  -isysroot
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk
  -fPIC -x c++
  /Users/feignclaims/code/cpp/cpp_conan_template/build/clang/CMakeFiles/_CMakeLTOTest-CXX/src/foo.cpp
  -c -o CMakeFiles/foo.dir/Debug/foo.cpp.o -resource-dir
  "/opt/homebrew/Cellar/llvm/18.1.5/lib/clang/18" -MT
  CMakeFiles/foo.dir/Debug/foo.cpp.o.ddi -MD -MF
  CMakeFiles/foo.dir/Debug/foo.cpp.o.ddi.d >
  CMakeFiles/foo.dir/Debug/foo.cpp.o.ddi.tmp && mv
  CMakeFiles/foo.dir/Debug/foo.cpp.o.ddi.tmp
  CMakeFiles/foo.dir/Debug/foo.cpp.o.ddi

  /bin/sh: : command not found

  [2/8] "" -format=p1689 -- /opt/homebrew/opt/llvm/bin/clang++
  -DCMAKE_INTDIR=\"Debug\" -stdlib=libc++ -L/opt/homebrew/opt/llvm/lib/c++
  -Wno-unused-command-line-argument -g -std=c++26 -flto=thin -arch arm64
  -isysroot
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk
  -fPIE -x c++
  /Users/feignclaims/code/cpp/cpp_conan_template/build/clang/CMakeFiles/_CMakeLTOTest-CXX/src/main.cpp
  -c -o CMakeFiles/boo.dir/Debug/main.cpp.o -resource-dir
  "/opt/homebrew/Cellar/llvm/18.1.5/lib/clang/18" -MT
  CMakeFiles/boo.dir/Debug/main.cpp.o.ddi -MD -MF
  CMakeFiles/boo.dir/Debug/main.cpp.o.ddi.d >
  CMakeFiles/boo.dir/Debug/main.cpp.o.ddi.tmp && mv
  CMakeFiles/boo.dir/Debug/main.cpp.o.ddi.tmp
  CMakeFiles/boo.dir/Debug/main.cpp.o.ddi

  FAILED: CMakeFiles/boo.dir/Debug/main.cpp.o.ddi

  "" -format=p1689 -- /opt/homebrew/opt/llvm/bin/clang++
  -DCMAKE_INTDIR=\"Debug\" -stdlib=libc++ -L/opt/homebrew/opt/llvm/lib/c++
  -Wno-unused-command-line-argument -g -std=c++26 -flto=thin -arch arm64
  -isysroot
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk
  -fPIE -x c++
  /Users/feignclaims/code/cpp/cpp_conan_template/build/clang/CMakeFiles/_CMakeLTOTest-CXX/src/main.cpp
  -c -o CMakeFiles/boo.dir/Debug/main.cpp.o -resource-dir
  "/opt/homebrew/Cellar/llvm/18.1.5/lib/clang/18" -MT
  CMakeFiles/boo.dir/Debug/main.cpp.o.ddi -MD -MF
  CMakeFiles/boo.dir/Debug/main.cpp.o.ddi.d >
  CMakeFiles/boo.dir/Debug/main.cpp.o.ddi.tmp && mv
  CMakeFiles/boo.dir/Debug/main.cpp.o.ddi.tmp
  CMakeFiles/boo.dir/Debug/main.cpp.o.ddi

  /bin/sh: : command not found

  ninja: build stopped: subcommand failed.



Call Stack (most recent call first):
  build/clang/_deps/_sample_project_project_options-src/src/Index.cmake:212 (enable_interprocedural_optimization)
  build/clang/_deps/_sample_project_project_options-src/src/DynamicProjectOptions.cmake:257 (project_options)
  cmake/sample_project_custom_project_options.cmake:30 (dynamic_project_options)
  CMakeLists.txt:12 (include)

@FeignClaims FeignClaims marked this pull request as ready for review May 19, 2024 08:15
@FeignClaims
Copy link
Contributor Author

FeignClaims commented May 19, 2024

All vcpkg-related cross tests failed after requiring CMake 3.24 as the minium version.

I compared the logs from the last test with this one. Maybe this is caused by github action caches... or something else

Help wanted. Fixed after setting the POLICY CMP0138 instead of bumping cmake to 3.24.

@FeignClaims FeignClaims marked this pull request as draft June 7, 2024 03:14
@ddassie-texa
Copy link
Contributor

You can set a POLICY without the need to bump the minimum version:

if(POLICY CMP0138)
  cmake_policy(SET CMP0138 NEW)
endif()

@FeignClaims
Copy link
Contributor Author

You can set a POLICY without the need to bump the minimum version:您可以设置 POLICY 而无需提高最低版本:

if(POLICY CMP0138)
  cmake_policy(SET CMP0138 NEW)
endif()

I forgot this solution, thanks.

@FeignClaims
Copy link
Contributor Author

ci on Test (macos-13, gcc, true, true) fails, which refers to the known issue of github runners actions/runner-images#9997. Therefore, it's not related to this pr.

Given that the pull request performs well in other tests, I believe it is now suitable for review and possibly ready for merging.

@FeignClaims FeignClaims marked this pull request as ready for review June 10, 2024 08:56
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.

Hardening and LTO are not set correctly when using a multi-configuration generator
2 participants