Skip to content

build: Add ClangCL profiles #791

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

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
60e1e5b
build: Add ClangCL profiles
alichraghi Nov 21, 2024
114c549
build: one liner ifs and some fixes
alichraghi Nov 21, 2024
ff5513b
update dxc submodule
alichraghi Nov 21, 2024
44acfcf
build: simplify if
alichraghi Nov 22, 2024
dbff78d
Merge branch 'ali_clang' of github.com:Devsh-Graphics-Programming/Nabla
AnastaZIuk Apr 4, 2025
616f7d7
fixing CLang build, save work
AnastaZIuk Apr 8, 2025
aad8bb1
make Nabla Clang build work
AnastaZIuk Apr 8, 2025
7b8cb61
bad typo
AnastaZIuk Apr 8, 2025
062b5ba
update profiles & flags check handle, take care of Clang profile; ent…
AnastaZIuk Apr 11, 2025
39bb3e1
update dxc submodule with fixed clang 19.1.1 build, upgrade & correct…
AnastaZIuk Apr 11, 2025
cbb4db1
update GLI (use custom location for GLM + fix with templates) and GLM…
AnastaZIuk Apr 11, 2025
c1cc48b
explicitly set limits for Clang toolset, correct some of backend opti…
AnastaZIuk Apr 13, 2025
16088b9
Reduce device_capabilities_traits_jit.h instructions & use std::ostri…
AnastaZIuk Apr 14, 2025
8f454a9
update bzip2 submodule to latest *official* revision, adjust build sy…
AnastaZIuk Apr 14, 2025
b4e722a
remove `-Xclang=-fincremental-extensions` which causes funny compile …
AnastaZIuk Apr 14, 2025
eda05ee
adjust MSVC profile + correct incremental link options, update NBL_RE…
AnastaZIuk Apr 15, 2025
25e0120
get rid of MSVC Release linker fallback with /LTCG due to /GL - manua…
AnastaZIuk Apr 16, 2025
b5d6795
Create vendor/template/frontend/MSVC.cmake, update profiles, respect …
AnastaZIuk Apr 17, 2025
d1bb5c6
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla …
AnastaZIuk Apr 18, 2025
a1b9b99
ah DXC needs to point to devshFixes_clang_19_1_1
AnastaZIuk Apr 18, 2025
77ed416
keep designated initializers for ISwapchain's SSharedCreationParams, …
AnastaZIuk Apr 18, 2025
a2a7e72
for my sanity - add -DNDEBUG to Clang profile (Unix)
AnastaZIuk Apr 18, 2025
cde9e79
correct CMAKE_MSVC_DEBUG_INFORMATION_FORMAT logic hence make it work …
AnastaZIuk Apr 18, 2025
8246891
pull master & resolve conflicts
AnastaZIuk Apr 22, 2025
6e4392e
add more NEW policies, leave TODO comment for `cmake_policy`
AnastaZIuk Apr 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -496,11 +496,7 @@ if (NBL_BUILD_IMGUI)
endif()

foreach(trgt IN LISTS NBL_3RDPARTY_TARGETS)
if(NBL_DYNAMIC_MSVC_RUNTIME)
set_property(TARGET ${trgt} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
else()
set_property(TARGET ${trgt} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
set_property(TARGET ${trgt} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<BOOL:${NBL_COMPILER_DYNAMIC_RUNTIME}>:DLL>")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK in Clang and GCC there are options about static linking of libstd-c++

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes there are and this property has effect only if MSVC ABI is the target


if(MSVC AND NBL_SANITIZE_ADDRESS)
set_property(TARGET ${trgt} PROPERTY COMPILE_OPTIONS /fsanitize=address)
Expand Down
6 changes: 1 addition & 5 deletions 3rdparty/dxc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ if(WIN32)
endif()
endif()

if(NBL_DYNAMIC_MSVC_RUNTIME)
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DCMAKE_MSVC_RUNTIME_LIBRARY:STATIC=MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
else()
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DCMAKE_MSVC_RUNTIME_LIBRARY:STATIC=MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DCMAKE_MSVC_RUNTIME_LIBRARY:STATIC=MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<BOOL:${NBL_COMPILER_DYNAMIC_RUNTIME}>:DLL>")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as with the general nabla comment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


# perform DXC compile standard requirement test
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
14 changes: 4 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ if(MSVC)
endif()

option(NBL_STATIC_BUILD "" OFF) # ON for static builds, OFF for shared
option(NBL_DYNAMIC_MSVC_RUNTIME "" ON)
option(NBL_COMPILER_DYNAMIC_RUNTIME "" ON)
option(NBL_SANITIZE_ADDRESS OFF)

if(MSVC)
if(CMAKE_CXX_COMPILER_ID STREQUAL MSVC)
if(NBL_SANITIZE_ADDRESS)
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>")
else()
Expand All @@ -35,14 +35,8 @@ endif()
if(NBL_STATIC_BUILD)
message(STATUS "Static Nabla build enabled!")
else()
if(MSVC)
if(NBL_DYNAMIC_MSVC_RUNTIME)
message(STATUS "Shared Nabla build enabled!")
else()
message(FATAL_ERROR "Turn NBL_DYNAMIC_MSVC_RUNTIME on! For dynamic Nabla builds dynamic MSVC runtime is mandatory!")
endif()
else()
message(FATAL_ERROR "Nabla can't be built with shared libraries! Please make sure you are targetting Windows OS and MSVC compiler!")
if(NOT NBL_COMPILER_DYNAMIC_RUNTIME)
message(FATAL_ERROR "Turn NBL_COMPILER_DYNAMIC_RUNTIME on! For dynamic Nabla builds dynamic runtime is mandatory!")
endif()
Comment on lines +37 to 39

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aah ok so we want to ban compiling with static-libstdc++

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes we agreed it must match

endif()

Expand Down
24 changes: 20 additions & 4 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"hidden": true,
"inherits": "ci-configure-static-base",
"cacheVariables": {
"NBL_DYNAMIC_MSVC_RUNTIME": "OFF"
"NBL_COMPILER_DYNAMIC_RUNTIME": "OFF"
},
"condition": {
"type": "allOf",
Expand All @@ -69,7 +69,7 @@
"hidden": true,
"inherits": "ci-configure-dynamic-base",
"cacheVariables": {
"NBL_DYNAMIC_MSVC_RUNTIME": "ON"
"NBL_COMPILER_DYNAMIC_RUNTIME": "ON"
},
"condition": {
"type": "allOf",
Expand Down Expand Up @@ -156,7 +156,7 @@
"hidden": true,
"inherits": "user-configure-static-base",
"cacheVariables": {
"NBL_DYNAMIC_MSVC_RUNTIME": "OFF"
"NBL_COMPILER_DYNAMIC_RUNTIME": "OFF"
},
"condition": {
"type": "equals",
Expand All @@ -169,7 +169,7 @@
"hidden": true,
"inherits": "user-configure-dynamic-base",
"cacheVariables": {
"NBL_DYNAMIC_MSVC_RUNTIME": "ON"
"NBL_COMPILER_DYNAMIC_RUNTIME": "ON"
},
"condition": {
"type": "equals",
Expand All @@ -193,6 +193,22 @@
"generator": "Visual Studio 17 2022",
"toolset": "v143"
},
{
"name": "user-configure-static-clangcl",
"inherits": "user-configure-static-windows-base",
"displayName": "[USER]: Static library target, Visual Studio 17 2022 generator, ClangCL toolset",
"description": "Configure as static library with Visual Studio 17 2022 generator and ClangCL toolset",
"generator": "Visual Studio 17 2022",
"toolset": "ClangCL"
},
{
"name": "user-configure-dynamic-clangcl",
"inherits": "user-configure-dynamic-windows-base",
"displayName": "[USER]: Dynamic library target, Visual Studio 17 2022 generator, ClangCL toolset",
"description": "Configure as dynamic library with Visual Studio 17 2022 generator and ClangCL toolset",
"generator": "Visual Studio 17 2022",
"toolset": "ClangCL"
},
{
"name": "user-configure-static-ninja-multi",
"inherits": "user-configure-static-windows-base",
Expand Down
143 changes: 114 additions & 29 deletions cmake/adjust/flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,130 @@ define_property(TARGET PROPERTY NBL_CONFIGURATION_MAP
BRIEF_DOCS "Stores configuration map for a target, it will evaluate to the configuration it's mapped to"
)

function(NBL_REQUEST_COMPILE_OPTION_SUPPORT _NBL_COMPILE_OPTION_)
set(NBL_COMPILE_OPTION "${_NBL_COMPILE_OPTION_}")
# Usage: NBL_REQUEST_COMPILE_OPTION_SUPPORT(LANG <LANG;...> CONFIG <CONFIG;...> OPTIONS <OPTIONS;...> )
# LANG, CONFIG - optional, OPTIONS - required
function(NBL_REQUEST_COMPILE_OPTION_SUPPORT)
cmake_parse_arguments(IMPL "" "REQUEST_VAR;REQUIRED" "LANG;CONFIG;OPTIONS" ${ARGN})

foreach(COMPILER IN ITEMS c cxx)
set(DEFAULT_COMPILERS c cxx)
set(REQUEST_ALL_OPTIONS_PRESENT True)

if(NOT IMPL_LANG)
list(APPEND IMPL_LANG ${DEFAULT_COMPILERS})
endif()

if(NOT IMPL_OPTIONS)
message(FATAL_ERROR "NBL_REQUEST_COMPILE_OPTION_SUPPORT's OPTIONS empty!")
endif()

foreach(COMPILER IN ITEMS ${IMPL_LANG})
string(TOUPPER "${COMPILER}" COMPILER_UPPER)

string(REGEX REPLACE "[-=:;/.]" "_" flag_signature "${NBL_COMPILE_OPTION}")
set(flag_var "__${COMPILER_UPPER}_Flag_${flag_signature}")
if(COMPILER_UPPER STREQUAL C)
macro(VALIDATE_FLAG)
check_c_compiler_flag(${ARGV})
endmacro()
elseif(COMPILER_UPPER STREQUAL CXX)
macro(VALIDATE_FLAG)
check_cxx_compiler_flag(${ARGV})
endmacro()
endif()

foreach(COMPILE_OPTION ${IMPL_OPTIONS})
string(REGEX REPLACE "[-=:;/.]" "_" FLAG_SIGNATURE "${COMPILE_OPTION}")
set(FLAG_VAR "NBL_${COMPILER_UPPER}_COMPILER_HAS_${FLAG_SIGNATURE}_FLAG")

if(COMPILER STREQUAL "c")
check_c_compiler_flag("${NBL_COMPILE_OPTION}" ${flag_var})
elseif(COMPILER STREQUAL "cxx")
check_cxx_compiler_flag("${NBL_COMPILE_OPTION}" ${flag_var})
endif()
VALIDATE_FLAG("${COMPILE_OPTION}" "${FLAG_VAR}")

if(${flag_var})
message(STATUS "Enabled \"${NBL_COMPILE_OPTION}\" ${COMPILER_UPPER} compile option for Nabla projects!")
set(NBL_${COMPILER_UPPER}_COMPILE_OPTIONS "${NBL_${COMPILER_UPPER}_COMPILE_OPTIONS};${NBL_COMPILE_OPTION}" PARENT_SCOPE)
else()
message(STATUS "Disabled \"${NBL_COMPILE_OPTION}\" ${COMPILER_UPPER} compile option for Nabla projects! (no support)")
endif()
if(${FLAG_VAR})
if(IMPL_CONFIG)
foreach(CONFIG ${IMPL_CONFIG})
# TODO: validate (${CONFIG} \in ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER "${CONFIG}" CONFIG_UPPER)
set(NBL_${COMPILER_UPPER}_${CONFIG_UPPER}_COMPILE_OPTIONS "${NBL_${COMPILER_UPPER}_${CONFIG_UPPER}_COMPILE_OPTIONS};${COMPILE_OPTION}")
endforeach()
else()
set(NBL_${COMPILER_UPPER}_COMPILE_OPTIONS "${NBL_${COMPILER_UPPER}_COMPILE_OPTIONS};${COMPILE_OPTION}")
endif()
else()
if(IMPL_REQUIRED)
message(FATAL_ERROR "Terminating, NBL_REQUEST_COMPILE_OPTION_SUPPORT was invoked with REQUIRED qualifier!")
endif()

set(REQUEST_ALL_OPTIONS_PRESENT False)
endif()
endforeach()

if(IMPL_CONFIG)
foreach(CONFIG ${IMPL_CONFIG})
string(TOUPPER "${CONFIG}" CONFIG_UPPER)
set(NBL_${COMPILER_UPPER}_${CONFIG_UPPER}_COMPILE_OPTIONS ${NBL_${COMPILER_UPPER}_${CONFIG_UPPER}_COMPILE_OPTIONS} PARENT_SCOPE)
endforeach()
else()
set(NBL_${COMPILER_UPPER}_COMPILE_OPTIONS ${NBL_${COMPILER_UPPER}_COMPILE_OPTIONS} PARENT_SCOPE)
endif()
endforeach()

if(IMPL_REQUEST_VAR)
set(${IMPL_REQUEST_VAR} ${REQUEST_ALL_OPTIONS_PRESENT} PARENT_SCOPE)
endif()
endfunction()

option(NBL_REQUEST_SSE_4_2 "Request compilation with SSE 4.2 instruction set enabled for Nabla projects" ON)
option(NBL_REQUEST_SSE_AXV2 "Request compilation with SSE Intel Advanced Vector Extensions 2 for Nabla projects" ON)
option(NBL_REQUEST_SSE_AVX2 "Request compilation with SSE Intel Advanced Vector Extensions 2 for Nabla projects" ON)

# profiles
if(MSVC)
include("${CMAKE_CURRENT_LIST_DIR}/template/windows/msvc.cmake")
elseif(ANDROID)
include("${CMAKE_CURRENT_LIST_DIR}/template/unix/android.cmake")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
include("${CMAKE_CURRENT_LIST_DIR}/template/unix/gnu.cmake")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
include("${CMAKE_CURRENT_LIST_DIR}/template/unix/clang.cmake")
else()
message(WARNING "UNTESTED COMPILER DETECTED, EXPECT WRONG OPTIMIZATION FLAGS! SUBMIT ISSUE ON GITHUB https://github.com/Devsh-Graphics-Programming/Nabla/issues")
endif()
foreach(NBL_COMPILER_LANGUAGE IN ITEMS C CXX)
# all list of all known by CMake vendors:
# https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html
set(NBL_COMPILER_VENDOR "${CMAKE_${NBL_COMPILER_LANGUAGE}_COMPILER_ID}")
set(NBL_PROFILE_NAME "${NBL_COMPILER_LANGUAGE}_${NBL_COMPILER_VENDOR}") # eg. "cxx_MSVC.cmake"
set(NBL_PROFILE_PATH "${CMAKE_CURRENT_LIST_DIR}/template/vendor/${NBL_PROFILE_NAME}.cmake")

include("${NBL_PROFILE_PATH}" RESULT_VARIABLE _NBL_FOUND_)

if(NOT _NBL_FOUND_)
message(WARNING "UNSUPPORTED \"${NBL_COMPILER_LANGUAGE}\" COMPILER LANGUAGE FOR \"${NBL_COMPILER_VENDOR}\" DETECTED, CMAKE CONFIGURATION OR BUILD MAY FAIL AND COMPILE OPTIONS FLAGS WILL NOT BE SET! SUBMIT ISSUE ON GITHUB https://github.com/Devsh-Graphics-Programming/Nabla/issues")
continue()
endif()

# a profile MUST define
# - "NBL_${NBL_COMPILER_LANGUAGE}_${CONFIGURATION}_COMPILE_OPTIONS" (configuration dependent)
# - "NBL_${NBL_COMPILER_LANGUAGE}_COMPILE_OPTIONS" (global)

# a profile MUST NOT define
# - NBL_COMPILE_OPTIONS

set(NBL_COMPILE_OPTIONS_VAR_NAME NBL_${NBL_COMPILER_LANGUAGE}_COMPILE_OPTIONS)
set(NBL_COMPILE_OPTIONS_VAR_VALUE ${${NBL_COMPILE_OPTIONS_VAR_NAME}})

if(NOT DEFINED ${NBL_COMPILE_OPTIONS_VAR_NAME})
message(FATAL_ERROR "\"${NBL_PROFILE_PATH}\" did not define \"${NBL_COMPILE_OPTIONS_VAR_NAME}\"!")
endif()

# update map with configuration dependent compile options
foreach(CONFIGURATION IN ITEMS RELEASE RELWITHDEBINFO DEBUG)
set(NBL_CONFIGURATION_COMPILE_OPTIONS_VAR_NAME NBL_${NBL_COMPILER_LANGUAGE}_${CONFIGURATION}_COMPILE_OPTIONS)
set(NBL_CONFIGURATION_COMPILE_OPTIONS_VAR_VALUE ${${NBL_CONFIGURATION_COMPILE_OPTIONS_VAR_NAME}})

if(NOT DEFINED ${NBL_CONFIGURATION_COMPILE_OPTIONS_VAR_NAME})
message(FATAL_ERROR "\"${NBL_PROFILE_PATH}\" did not define \"${NBL_CONFIGURATION_COMPILE_OPTIONS_VAR_NAME}\"!")
endif()

list(APPEND NBL_${CONFIGURATION}_COMPILE_OPTIONS
# note that "${NBL_CONFIGURATION_COMPILE_OPTIONS_VAR_VALUE}" MUST NOT contain ANY
# $<$<CONFIG:<>> generator expression in order to support our configuration mapping features
$<$<COMPILE_LANGUAGE:${NBL_COMPILER_LANGUAGE}>:${NBL_CONFIGURATION_COMPILE_OPTIONS_VAR_VALUE}>
)

set(NBL_${CONFIGURATION}_COMPILE_OPTIONS ${NBL_${CONFIGURATION}_COMPILE_OPTIONS})
endforeach()

# update map with global compile options
list(APPEND NBL_COMPILE_OPTIONS $<$<COMPILE_LANGUAGE:${NBL_COMPILER_LANGUAGE}>:${NBL_${NBL_COMPILER_LANGUAGE}_COMPILE_OPTIONS}>)

set(NBL_COMPILE_OPTIONS ${NBL_COMPILE_OPTIONS})
endforeach()

function(NBL_EXT_P_APPEND_COMPILE_OPTIONS NBL_LIST_NAME MAP_RELEASE MAP_RELWITHDEBINFO MAP_DEBUG)
macro(NBL_MAP_CONFIGURATION NBL_CONFIG_FROM NBL_CONFIG_TO)
Expand Down Expand Up @@ -173,7 +258,7 @@ function(nbl_adjust_flags)

set(MAPPED_CONFIG $<TARGET_GENEX_EVAL:${NBL_TARGET_ITEM},$<TARGET_PROPERTY:${NBL_TARGET_ITEM},NBL_CONFIGURATION_MAP>>)

if(MSVC)
if(CMAKE_CXX_COMPILER_ID STREQUAL MSVC)
if(NBL_SANITIZE_ADDRESS)
set(NBL_TARGET_MSVC_DEBUG_INFORMATION_FORMAT "$<$<OR:$<STREQUAL:${MAPPED_CONFIG},DEBUG>,$<STREQUAL:${MAPPED_CONFIG},RELWITHDEBINFO>>:ProgramDatabase>")
else()
Expand Down
5 changes: 5 additions & 0 deletions cmake/adjust/template/vendor/CXX_Clang.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include_guard(GLOBAL)

set(LANG CXX)
include("${CMAKE_CURRENT_LIST_DIR}/impl/Clang.cmake")
# append unique CXX options here
5 changes: 5 additions & 0 deletions cmake/adjust/template/vendor/CXX_MSVC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include_guard(GLOBAL)

set(LANG CXX)
include("${CMAKE_CURRENT_LIST_DIR}/impl/MSVC.cmake")
# append unique CXX options here
5 changes: 5 additions & 0 deletions cmake/adjust/template/vendor/C_Clang.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include_guard(GLOBAL)

set(LANG C)
include("${CMAKE_CURRENT_LIST_DIR}/impl/Clang.cmake")
# append unique C options here
5 changes: 5 additions & 0 deletions cmake/adjust/template/vendor/C_MSVC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include_guard(GLOBAL)

set(LANG C)
include("${CMAKE_CURRENT_LIST_DIR}/impl/MSVC.cmake")
# append unique C options here
Loading