Skip to content

Commit 60e1e5b

Browse files
committed
build: Add ClangCL profiles
Also fix some compilation errors catched by clang Signed-off-by: Ali Cheraghi <[email protected]>
1 parent 22e86a7 commit 60e1e5b

18 files changed

+231
-67
lines changed

3rdparty/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ if(ENABLE_HLSL)
493493
endif()
494494

495495
foreach(trgt IN LISTS NBL_3RDPARTY_TARGETS)
496-
if(NBL_DYNAMIC_MSVC_RUNTIME)
496+
if(NBL_COMPILER_DYNAMIC_RUNTIME)
497497
set_property(TARGET ${trgt} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
498498
else()
499499
set_property(TARGET ${trgt} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

3rdparty/dxc/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ if(WIN32)
6262
endif()
6363
endif()
6464

65-
if(NBL_DYNAMIC_MSVC_RUNTIME)
65+
if(NBL_COMPILER_DYNAMIC_RUNTIME)
6666
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DCMAKE_MSVC_RUNTIME_LIBRARY:STATIC=MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
6767
else()
6868
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DCMAKE_MSVC_RUNTIME_LIBRARY:STATIC=MultiThreaded$<$<CONFIG:Debug>:Debug>")

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ if(MSVC)
2020
endif()
2121

2222
option(NBL_STATIC_BUILD "" OFF) # ON for static builds, OFF for shared
23-
option(NBL_DYNAMIC_MSVC_RUNTIME "" ON)
23+
option(NBL_COMPILER_DYNAMIC_RUNTIME "" ON)
2424
option(NBL_SANITIZE_ADDRESS OFF)
2525

26-
if(MSVC)
26+
if(MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL MSVC)
2727
if(NBL_SANITIZE_ADDRESS)
2828
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>")
2929
else()
@@ -35,10 +35,10 @@ if(NBL_STATIC_BUILD)
3535
message(STATUS "Static Nabla build enabled!")
3636
else()
3737
if(MSVC)
38-
if(NBL_DYNAMIC_MSVC_RUNTIME)
38+
if(NBL_COMPILER_DYNAMIC_RUNTIME)
3939
message(STATUS "Shared Nabla build enabled!")
4040
else()
41-
message(FATAL_ERROR "Turn NBL_DYNAMIC_MSVC_RUNTIME on! For dynamic Nabla builds dynamic MSVC runtime is mandatory!")
41+
message(FATAL_ERROR "Turn NBL_COMPILER_DYNAMIC_RUNTIME on! For dynamic Nabla builds dynamic MSVC runtime is mandatory!")
4242
endif()
4343
else()
4444
message(FATAL_ERROR "Nabla can't be built with shared libraries! Please make sure you are targetting Windows OS and MSVC compiler!")

CMakePresets.json

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"hidden": true,
4747
"inherits": "ci-configure-static-base",
4848
"cacheVariables": {
49-
"NBL_DYNAMIC_MSVC_RUNTIME": "OFF"
49+
"NBL_COMPILER_DYNAMIC_RUNTIME": "OFF"
5050
},
5151
"condition": {
5252
"type": "allOf",
@@ -69,7 +69,7 @@
6969
"hidden": true,
7070
"inherits": "ci-configure-dynamic-base",
7171
"cacheVariables": {
72-
"NBL_DYNAMIC_MSVC_RUNTIME": "ON"
72+
"NBL_COMPILER_DYNAMIC_RUNTIME": "ON"
7373
},
7474
"condition": {
7575
"type": "allOf",
@@ -156,7 +156,7 @@
156156
"hidden": true,
157157
"inherits": "user-configure-static-base",
158158
"cacheVariables": {
159-
"NBL_DYNAMIC_MSVC_RUNTIME": "OFF"
159+
"NBL_COMPILER_DYNAMIC_RUNTIME": "OFF"
160160
},
161161
"condition": {
162162
"type": "equals",
@@ -169,7 +169,7 @@
169169
"hidden": true,
170170
"inherits": "user-configure-dynamic-base",
171171
"cacheVariables": {
172-
"NBL_DYNAMIC_MSVC_RUNTIME": "ON"
172+
"NBL_COMPILER_DYNAMIC_RUNTIME": "ON"
173173
},
174174
"condition": {
175175
"type": "equals",
@@ -193,6 +193,22 @@
193193
"generator": "Visual Studio 17 2022",
194194
"toolset": "v143"
195195
},
196+
{
197+
"name": "user-configure-static-clangcl",
198+
"inherits": "user-configure-static-windows-base",
199+
"displayName": "[USER]: Static library target, Visual Studio 17 2022 generator, ClangCL toolset",
200+
"description": "Configure as static library with Visual Studio 17 2022 generator and ClangCL toolset",
201+
"generator": "Visual Studio 17 2022",
202+
"toolset": "ClangCL"
203+
},
204+
{
205+
"name": "user-configure-dynamic-clangcl",
206+
"inherits": "user-configure-dynamic-windows-base",
207+
"displayName": "[USER]: Dynamic library target, Visual Studio 17 2022 generator, ClangCL toolset",
208+
"description": "Configure as dynamic library with Visual Studio 17 2022 generator and ClangCL toolset",
209+
"generator": "Visual Studio 17 2022",
210+
"toolset": "ClangCL"
211+
},
196212
{
197213
"name": "user-configure-static-ninja-multi",
198214
"inherits": "user-configure-static-windows-base",

cmake/adjust/flags.cmake

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,57 @@ option(NBL_REQUEST_SSE_4_2 "Request compilation with SSE 4.2 instruction set ena
4040
option(NBL_REQUEST_SSE_AXV2 "Request compilation with SSE Intel Advanced Vector Extensions 2 for Nabla projects" ON)
4141

4242
# profiles
43-
if(MSVC)
44-
include("${CMAKE_CURRENT_LIST_DIR}/template/windows/msvc.cmake")
45-
elseif(ANDROID)
46-
include("${CMAKE_CURRENT_LIST_DIR}/template/unix/android.cmake")
47-
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
48-
include("${CMAKE_CURRENT_LIST_DIR}/template/unix/gnu.cmake")
49-
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
50-
include("${CMAKE_CURRENT_LIST_DIR}/template/unix/clang.cmake")
51-
else()
52-
message(WARNING "UNTESTED COMPILER DETECTED, EXPECT WRONG OPTIMIZATION FLAGS! SUBMIT ISSUE ON GITHUB https://github.com/Devsh-Graphics-Programming/Nabla/issues")
53-
endif()
43+
foreach(NBL_COMPILER_LANGUAGE IN ITEMS C CXX)
44+
# all list of all known by CMake vendors:
45+
# https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html
46+
set(NBL_COMPILER_VENDOR "${CMAKE_${NBL_COMPILER_LANGUAGE}_COMPILER_ID}")
47+
set(NBL_PROFILE_NAME "${NBL_COMPILER_LANGUAGE}_${NBL_COMPILER_VENDOR}") # eg. "cxx_MSVC.cmake"
48+
set(NBL_PROFILE_PATH "${CMAKE_CURRENT_LIST_DIR}/template/vendor/${NBL_PROFILE_NAME}.cmake")
49+
50+
include("${NBL_PROFILE_PATH}" RESULT_VARIABLE _NBL_FOUND_)
51+
52+
if(NOT _NBL_FOUND_)
53+
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")
54+
continue()
55+
endif()
56+
57+
# a profile MUST define
58+
# - "NBL_${NBL_COMPILER_LANGUAGE}_${CONFIGURATION}_COMPILE_OPTIONS" (configuration dependent)
59+
# - "NBL_${NBL_COMPILER_LANGUAGE}_COMPILE_OPTIONS" (global)
60+
61+
# a profile MUST NOT define
62+
# - NBL_COMPILE_OPTIONS
63+
64+
set(NBL_COMPILE_OPTIONS_VAR_NAME NBL_${NBL_COMPILER_LANGUAGE}_COMPILE_OPTIONS)
65+
set(NBL_COMPILE_OPTIONS_VAR_VALUE ${${NBL_COMPILE_OPTIONS_VAR_NAME}})
66+
67+
if(NOT DEFINED ${NBL_COMPILE_OPTIONS_VAR_NAME})
68+
message(FATAL_ERROR "\"${NBL_PROFILE_PATH}\" did not define \"${NBL_COMPILE_OPTIONS_VAR_NAME}\"!")
69+
endif()
70+
71+
# update map with configuration dependent compile options
72+
foreach(CONFIGURATION IN ITEMS RELEASE RELWITHDEBINFO DEBUG)
73+
set(NBL_CONFIGURATION_COMPILE_OPTIONS_VAR_NAME NBL_${NBL_COMPILER_LANGUAGE}_${CONFIGURATION}_COMPILE_OPTIONS)
74+
set(NBL_CONFIGURATION_COMPILE_OPTIONS_VAR_VALUE ${${NBL_CONFIGURATION_COMPILE_OPTIONS_VAR_NAME}})
75+
76+
if(NOT DEFINED ${NBL_CONFIGURATION_COMPILE_OPTIONS_VAR_NAME})
77+
message(FATAL_ERROR "\"${NBL_PROFILE_PATH}\" did not define \"${NBL_CONFIGURATION_COMPILE_OPTIONS_VAR_NAME}\"!")
78+
endif()
79+
80+
list(APPEND NBL_${CONFIGURATION}_COMPILE_OPTIONS
81+
# note that "${NBL_CONFIGURATION_COMPILE_OPTIONS_VAR_VALUE}" MUST NOT contain ANY
82+
# $<$<CONFIG:<>> generator expression in order to support our configuration mapping features
83+
$<$<COMPILE_LANGUAGE:${NBL_COMPILER_LANGUAGE}>:${NBL_CONFIGURATION_COMPILE_OPTIONS_VAR_VALUE}>
84+
)
85+
86+
set(NBL_${CONFIGURATION}_COMPILE_OPTIONS ${NBL_${CONFIGURATION}_COMPILE_OPTIONS})
87+
endforeach()
88+
89+
# update map with global compile options
90+
list(APPEND NBL_COMPILE_OPTIONS $<$<COMPILE_LANGUAGE:${NBL_COMPILER_LANGUAGE}>:${NBL_${NBL_COMPILER_LANGUAGE}_COMPILE_OPTIONS}>)
91+
92+
set(NBL_COMPILE_OPTIONS ${NBL_COMPILE_OPTIONS})
93+
endforeach()
5494

5595
function(NBL_EXT_P_APPEND_COMPILE_OPTIONS NBL_LIST_NAME MAP_RELEASE MAP_RELWITHDEBINFO MAP_DEBUG)
5696
macro(NBL_MAP_CONFIGURATION NBL_CONFIG_FROM NBL_CONFIG_TO)
@@ -173,7 +213,7 @@ function(nbl_adjust_flags)
173213

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

176-
if(MSVC)
216+
if(MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL MSVC)
177217
if(NBL_SANITIZE_ADDRESS)
178218
set(NBL_TARGET_MSVC_DEBUG_INFORMATION_FORMAT "$<$<OR:$<STREQUAL:${MAPPED_CONFIG},DEBUG>,$<STREQUAL:${MAPPED_CONFIG},RELWITHDEBINFO>>:ProgramDatabase>")
179219
else()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
include_guard(GLOBAL)
2+
3+
# Debug
4+
set(NBL_CXX_DEBUG_COMPILE_OPTIONS
5+
-ggdb3 -Wall -fno-omit-frame-pointer -fstack-protector-strong
6+
)
7+
8+
# Release
9+
set(NBL_CXX_RELEASE_COMPILE_OPTIONS
10+
-fexpensive-optimizations
11+
)
12+
13+
# RelWithDebInfo
14+
set(NBL_CXX_RELWITHDEBINFO_COMPILE_OPTIONS "")
15+
16+
# Global
17+
list(APPEND NBL_CXX_COMPILE_OPTIONS
18+
-Wextra
19+
-fno-strict-aliasing
20+
-msse4.2
21+
-mfpmath=sse
22+
-Wextra
23+
-Wno-sequence-point
24+
-Wno-unused-parameter
25+
-Wno-unused-but-set-parameter
26+
-Wno-error=ignored-attributes
27+
-Wno-error=unused-function
28+
-Wno-error=unused-variable
29+
-Wno-error=unused-parameter
30+
-Wno-error=ignored-attributes
31+
-Wno-error=non-pod-varargs
32+
-fno-exceptions
33+
)
34+
35+
if(NBL_SANITIZE_ADDRESS)
36+
list(APPEND NBL_CXX_COMPILE_OPTIONS -fsanitize=address)
37+
endif()
38+
39+
if(NBL_SANITIZE_THREAD)
40+
list(APPEND NBL_CXX_COMPILE_OPTIONS -fsanitize=thread)
41+
endif()
42+
43+
# our pervious flags-set function called this, does not affect flags nor configs so I will keep it here temporary
44+
# TODO: move it out from the profile
45+
link_libraries(-fuse-ld=gold)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
include_guard(GLOBAL)
2+
3+
# https://learn.microsoft.com/en-us/cpp/build/reference/arch-x64?view=msvc-170
4+
5+
# The default instruction set is SSE2 if no /arch option is specified.
6+
if(NBL_REQUEST_SSE_4_2)
7+
NBL_REQUEST_COMPILE_OPTION_SUPPORT("/arch:SSE4.2")
8+
endif()
9+
10+
# Enables Intel Advanced Vector Extensions 2.
11+
if(NBL_REQUEST_SSE_AXV2)
12+
NBL_REQUEST_COMPILE_OPTION_SUPPORT("/arch:AVX2")
13+
endif()
14+
15+
# Debug
16+
set(NBL_CXX_DEBUG_COMPILE_OPTIONS
17+
/Zc:__cplusplus /Ob0 /Od /MP${_NBL_JOBS_AMOUNT_} /fp:fast /Zc:wchar_t /INCREMENTAL
18+
)
19+
20+
if(NBL_SANITIZE_ADDRESS)
21+
list(APPEND NBL_CXX_DEBUG_COMPILE_OPTIONS /RTC1)
22+
endif()
23+
24+
set(NBL_DEBUG_CXX_COMPILE_OPTIONS
25+
$<$<COMPILE_LANGUAGE:CXX>:${NBL_CXX_DEBUG_COMPILE_OPTIONS}>
26+
)
27+
28+
# Release
29+
set(NBL_CXX_RELEASE_COMPILE_OPTIONS
30+
/Zc:__cplusplus /O2 /Ob2 /DNDEBUG /GL /MP${_NBL_JOBS_AMOUNT_} /Gy- /Zc:wchar_t /sdl- /GF /GS- /fp:fast
31+
)
32+
33+
# RelWithDebInfo
34+
set(NBL_CXX_RELWITHDEBINFO_COMPILE_OPTIONS
35+
/Zc:__cplusplus /O2 /Ob1 /DNDEBUG /GL /Zc:wchar_t /MP${_NBL_JOBS_AMOUNT_} /Gy /sdl- /Oy- /fp:fast
36+
)
37+
38+
if(NBL_SANITIZE_ADDRESS)
39+
list(APPEND NBL_CXX_COMPILE_OPTIONS /fsanitize=address)
40+
endif()
41+
42+
# this should also be not part of profile, pasting from old flags-set function temporary
43+
# TODO: use profile
44+
45+
#reason for INCREMENTAL:NO: https://docs.microsoft.com/en-us/cpp/build/reference/ltcg-link-time-code-generation?view=vs-2019 /LTCG is not valid for use with /INCREMENTAL.
46+
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /INCREMENTAL:NO /LTCG:incremental")
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
include_guard(GLOBAL)
2+
3+
# Debug
4+
set(NBL_C_DEBUG_COMPILE_OPTIONS
5+
-ggdb3 -Wall -fno-omit-frame-pointer -fstack-protector-strong
6+
)
7+
8+
# Release
9+
set(NBL_C_RELEASE_COMPILE_OPTIONS
10+
-fexpensive-optimizations
11+
)
12+
13+
# RelWithDebInfo
14+
set(NBL_C_RELWITHDEBINFO_COMPILE_OPTIONS "")
15+
16+
# Global
17+
list(APPEND NBL_C_COMPILE_OPTIONS
18+
-Wextra
19+
-fno-strict-aliasing
20+
-msse4.2
21+
-mfpmath=sse
22+
-maes
23+
-Wextra
24+
-Wno-sequence-point
25+
-Wno-unused-parameter
26+
-Wno-unused-but-set-parameter
27+
-Wno-error=ignored-attributes
28+
-Wno-error=unused-function
29+
-Wno-error=unused-variable
30+
-Wno-error=unused-parameter
31+
-Wno-error=ignored-attributes
32+
-Wno-error=non-pod-varargs
33+
-fno-exceptions
34+
)
35+
36+
if(NBL_SANITIZE_ADDRESS)
37+
list(APPEND NBL_C_COMPILE_OPTIONS -fsanitize=address)
38+
endif()
39+
40+
if(NBL_SANITIZE_THREAD)
41+
list(APPEND NBL_C_COMPILE_OPTIONS -fsanitize=thread)
42+
endif()
43+
44+
# our pervious flags-set function called this, does not affect flags nor configs so I will keep it here temporary
45+
# TODO: move it out from the profile
46+
link_libraries(-fuse-ld=gold)

cmake/adjust/template/windows/msvc.cmake renamed to cmake/adjust/template/vendor/C_MSVC.cmake

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,51 +21,20 @@ if(NBL_SANITIZE_ADDRESS)
2121
list(APPEND NBL_C_DEBUG_COMPILE_OPTIONS /RTC1)
2222
endif()
2323

24-
set(NBL_CXX_DEBUG_COMPILE_OPTIONS
25-
/Zc:__cplusplus ${NBL_C_DEBUG_COMPILE_OPTIONS}
26-
)
27-
28-
set(NBL_DEBUG_COMPILE_OPTIONS
29-
$<$<COMPILE_LANGUAGE:CXX>:${NBL_CXX_DEBUG_COMPILE_OPTIONS}>
30-
$<$<COMPILE_LANGUAGE:C>:${NBL_C_DEBUG_COMPILE_OPTIONS}>
31-
)
32-
3324
# Release
3425
set(NBL_C_RELEASE_COMPILE_OPTIONS
3526
/O2 /Ob2 /DNDEBUG /GL /MP${_NBL_JOBS_AMOUNT_} /Gy- /Zc:wchar_t /sdl- /GF /GS- /fp:fast
3627
)
37-
set(NBL_CXX_RELEASE_COMPILE_OPTIONS
38-
/Zc:__cplusplus ${NBL_C_RELEASE_COMPILE_OPTIONS}
39-
)
40-
41-
set(NBL_RELEASE_COMPILE_OPTIONS
42-
$<$<COMPILE_LANGUAGE:CXX>:${NBL_CXX_RELEASE_COMPILE_OPTIONS}>
43-
$<$<COMPILE_LANGUAGE:C>:${NBL_C_RELEASE_COMPILE_OPTIONS}>
44-
)
4528

4629
# RelWithDebInfo
4730
set(NBL_C_RELWITHDEBINFO_COMPILE_OPTIONS
4831
/O2 /Ob1 /DNDEBUG /GL /Zc:wchar_t /MP${_NBL_JOBS_AMOUNT_} /Gy /sdl- /Oy- /fp:fast
4932
)
50-
set(NBL_CXX_RELWITHDEBINFO_COMPILE_OPTIONS
51-
/Zc:__cplusplus ${NBL_C_RELWITHDEBINFO_COMPILE_OPTIONS}
52-
)
53-
54-
set(NBL_RELWITHDEBINFO_COMPILE_OPTIONS
55-
$<$<COMPILE_LANGUAGE:CXX>:${NBL_CXX_RELWITHDEBINFO_COMPILE_OPTIONS}>
56-
$<$<COMPILE_LANGUAGE:C>:${NBL_C_RELWITHDEBINFO_COMPILE_OPTIONS}>
57-
)
5833

5934
if(NBL_SANITIZE_ADDRESS)
6035
list(APPEND NBL_C_COMPILE_OPTIONS /fsanitize=address)
61-
list(APPEND NBL_CXX_COMPILE_OPTIONS ${NBL_C_COMPILE_OPTIONS})
6236
endif()
6337

64-
set(NBL_COMPILE_OPTIONS
65-
$<$<COMPILE_LANGUAGE:CXX>:${NBL_CXX_COMPILE_OPTIONS}>
66-
$<$<COMPILE_LANGUAGE:C>:${NBL_C_COMPILE_OPTIONS}>
67-
)
68-
6938
# this should also be not part of profile, pasting from old flags-set function temporary
7039
# TODO: use profile
7140

0 commit comments

Comments
 (0)