diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2024-10-15 19:16:43 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-15 19:16:43 +0800 |
| commit | be42eeed7d9e510fea93922c615f1801bc54f336 (patch) | |
| tree | 029aaa2fdfcbe628f0985a42edf2a7f47c6fc54d | |
| parent | 456df23cff531566dfe3a6ca7be998f1251b1774 (diff) | |
Lower minimum CMake version to 3.22 (#5295)
* Lower minimum CMake version to 3.22
Reverts https://github.com/shader-slang/slang/pull/4193
* Update build instructions to mention older CMake versions
| -rw-r--r-- | CMakeLists.txt | 6 | ||||
| -rw-r--r-- | docs/building.md | 22 | ||||
| -rw-r--r-- | external/CMakeLists.txt | 21 |
3 files changed, 39 insertions, 10 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c5003401..6a87a61ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.25) +cmake_minimum_required(VERSION 3.22) # Our module dir, include that now so that we can get the version automatically # from git describe @@ -15,7 +15,9 @@ set(PROJECT_VERSION "${SLANG_VERSION_FULL}") # # Global CMake options # -cmake_policy(SET CMP0135 OLD) +if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24") + cmake_policy(SET CMP0135 OLD) +endif() cmake_policy(SET CMP0077 NEW) set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.25") diff --git a/docs/building.md b/docs/building.md index fa18ef60f..551b14491 100644 --- a/docs/building.md +++ b/docs/building.md @@ -9,7 +9,7 @@ version of Slang. Please install: -- CMake +- CMake (3.25 preferred, but 3.22 works[^cmake-version]) - A C++ compiler with support for C++17. GCC, Clang and MSVC are supported - A CMake compatible backend, for example Visual Studio or Ninja @@ -32,6 +32,8 @@ git clone https://github.com/shader-slang/slang --recursive ## Configure and build +> This section assumes cmake 3.25 or greater, if you're on a lower version please see [building with an older cmake](#older-cmake) + For a Ninja based build system (all platforms) run: ```bash cmake --preset default @@ -217,3 +219,21 @@ rm -rf build # The Visual Studio generator will complain if this is left over fr cmake --preset vs2022 --fresh -A arm64 -DSLANG_GENERATORS_PATH=generators/bin cmake --build --preset release ``` + +## Building with an older CMake {#older-cmake} + +Because older CMake versions don't support all the features we want to use in +CMakePresets, you'll have to do without the presets. Something like the following + +```bash +cmake -B build -G Ninja +cmake --build build -j +``` + +## Notes + +[^cmake-version] below 3.25, CMake lacks the ability to mark directories as being system +directories +(https://cmake.org/cmake/help/latest/prop_tgt/SYSTEM.html#prop_tgt:SYSTEM), +this leads to an inability to suppress warnings originating in the dependencies +in `./external`, so be prepared for some additional warnings. diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index ebbfefb4a..4f861c759 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -8,6 +8,13 @@ if(NOT CMAKE_MESSAGE_LOG_LEVEL) set(CMAKE_MESSAGE_LOG_LEVEL NOTICE) endif() +if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.25") + set(system SYSTEM) +else() + message(STATUS "CMake 3.25 is required to suppress warnings originating in headers in external/ but you are using ${CMAKE_VERSION}, be prepared for some warnings") + set(system) +endif() + # Similarly, disable warnings for external projects if(NOT SLANG_ENABLE_EXTERNAL_COMPILER_WARNINGS) if(MSVC) @@ -18,12 +25,12 @@ if(NOT SLANG_ENABLE_EXTERNAL_COMPILER_WARNINGS) endif() if (NOT ${SLANG_USE_SYSTEM_UNORDERED_DENSE}) - add_subdirectory(unordered_dense EXCLUDE_FROM_ALL SYSTEM) + add_subdirectory(unordered_dense EXCLUDE_FROM_ALL ${system}) endif() # Miniz if (NOT ${SLANG_USE_SYSTEM_MINIZ}) - add_subdirectory(miniz EXCLUDE_FROM_ALL SYSTEM) + add_subdirectory(miniz EXCLUDE_FROM_ALL ${system}) set_property(TARGET miniz PROPERTY POSITION_INDEPENDENT_CODE ON) # Work around https://github.com/richgel999/miniz/pull/292 get_target_property(miniz_c_launcher miniz C_COMPILER_LAUNCHER) @@ -36,7 +43,7 @@ endif() # LZ4 if (NOT ${SLANG_USE_SYSTEM_LZ4}) set(LZ4_BUNDLED_MODE ON) - add_subdirectory(lz4/build/cmake EXCLUDE_FROM_ALL SYSTEM) + add_subdirectory(lz4/build/cmake EXCLUDE_FROM_ALL ${system}) if(MSVC) target_compile_options( lz4_static @@ -47,7 +54,7 @@ endif() # Vulkan headers if (NOT ${SLANG_USE_SYSTEM_VULKAN_HEADERS}) - add_subdirectory(vulkan EXCLUDE_FROM_ALL SYSTEM) + add_subdirectory(vulkan EXCLUDE_FROM_ALL ${system}) endif() # metal-cpp headers @@ -56,7 +63,7 @@ target_include_directories(metal-cpp INTERFACE "${CMAKE_CURRENT_LIST_DIR}/metal- # SPIRV-Headers if (NOT ${SLANG_USE_SYSTEM_SPIRV_HEADERS}) - add_subdirectory(spirv-headers EXCLUDE_FROM_ALL SYSTEM) + add_subdirectory(spirv-headers EXCLUDE_FROM_ALL ${system}) endif() if(SLANG_ENABLE_SLANG_GLSLANG) @@ -65,13 +72,13 @@ if(SLANG_ENABLE_SLANG_GLSLANG) set(SPIRV_WERROR OFF) set(SPIRV_HEADER_DIR "${CMAKE_CURRENT_LIST_DIR}/spirv-headers/") set(SPIRV_SKIP_TESTS ON) - add_subdirectory(spirv-tools EXCLUDE_FROM_ALL SYSTEM) + add_subdirectory(spirv-tools EXCLUDE_FROM_ALL ${system}) # glslang set(SKIP_GLSLANG_INSTALL ON) set(ENABLE_OPT ON) set(ENABLE_PCH OFF) - add_subdirectory(glslang EXCLUDE_FROM_ALL SYSTEM) + add_subdirectory(glslang EXCLUDE_FROM_ALL ${system}) endif() # imgui |
