Skip to content

Commit 35b1842

Browse files
AnastaZIukdeprilula28
authored andcommitted
Require CMake 3.25 and add configure time validation for checking if given compiler CMake is processing with supports C++11 or C++14 standard in order to make sure DXC will be built correctly - throw an error if not. Check some of available CMake modules and decide to use try_compile for that because modules with simpler implementation of our check didn't work for some reason
1 parent 8e1f701 commit 35b1842

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

3rdparty/dxc/CMakeLists.txt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,32 @@ set(SPIRV_SKIP_TESTS ON CACHE INTERNAL "Skip SPIRV-Tools tests")
3737
set(SPIRV_SKIP_EXECUTABLES ON CACHE INTERNAL "Skip SPIRV-Tools executable build")
3838
set(HLSL_ENABLE_DEBUG_ITERATORS ON CACHE BOOL "Enable Debug iterators" FORCE)
3939

40-
set(CMAKE_CXX_STANDARD 11)
40+
nbl_adjust_flags()
41+
42+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
43+
set(CMAKE_CXX_STANDARD 11) # compiler must support exactly c++11 or c++14 standard in order to be able to build DXC libraries
4144
if(NBL_DYNAMIC_MSVC_RUNTIME)
4245
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
4346
else()
4447
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
4548
endif()
4649

47-
add_subdirectory(dxc dxc) # for dxcompiler target
50+
try_compile(DXC_COMPILE_TEST_PASSED
51+
SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/test/test.cpp"
52+
OUTPUT_VARIABLE DXC_COMPILE_RET_VAL
53+
CXX_STANDARD ${CMAKE_CXX_STANDARD}
54+
CXX_STANDARD_REQUIRED ON
55+
)
56+
57+
if(DXC_COMPILE_TEST_PASSED)
58+
set(DXC_COMPILE_TEST_DONE ON CACHE BOOL "")
59+
else()
60+
message(FATAL_ERROR "${DXC_COMPILE_RET_VAL}")
61+
endif()
62+
63+
add_subdirectory(dxc dxc)
4864
set(CMAKE_CXX_STANDARD 20) # it's mandatory
65+
unset(CMAKE_CXX_STANDARD_REQUIRED)
4966

5067
include(FetchContent)
5168
set(FC_EXTERNAL_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/external")

3rdparty/dxc/test/test.cpp

568 Bytes
Binary file not shown.

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This file is part of the "Nabla Engine".
33
# For conditions of distribution and use, see copyright notice in nabla.h.in or nabla.h
44

5-
cmake_minimum_required(VERSION 3.20)
5+
cmake_minimum_required(VERSION 3.25)
66
#policies
77
cmake_policy(SET CMP0072 OLD) #not yet, would need to get pointers to all OpenGL functions
88
set(OpenGL_GL_PREFERENCE LEGACY)

0 commit comments

Comments
 (0)