Skip to content

Commit dbff78d

Browse files
committed
Merge branch 'ali_clang' of github.com:Devsh-Graphics-Programming/Nabla
2 parents 23124c5 + 44acfcf commit dbff78d

18 files changed

+228
-90
lines changed

3rdparty/CMakeLists.txt

+1-5
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,7 @@ if (NBL_BUILD_IMGUI)
496496
endif()
497497

498498
foreach(trgt IN LISTS NBL_3RDPARTY_TARGETS)
499-
if(NBL_DYNAMIC_MSVC_RUNTIME)
500-
set_property(TARGET ${trgt} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
501-
else()
502-
set_property(TARGET ${trgt} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
503-
endif()
499+
set_property(TARGET ${trgt} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<BOOL:${NBL_COMPILER_DYNAMIC_RUNTIME}>:DLL>")
504500

505501
if(MSVC AND NBL_SANITIZE_ADDRESS)
506502
set_property(TARGET ${trgt} PROPERTY COMPILE_OPTIONS /fsanitize=address)

3rdparty/dxc/CMakeLists.txt

+1-5
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,7 @@ if(WIN32)
6363
endif()
6464
endif()
6565

66-
if(NBL_DYNAMIC_MSVC_RUNTIME)
67-
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DCMAKE_MSVC_RUNTIME_LIBRARY:STATIC=MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
68-
else()
69-
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DCMAKE_MSVC_RUNTIME_LIBRARY:STATIC=MultiThreaded$<$<CONFIG:Debug>:Debug>")
70-
endif()
66+
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DCMAKE_MSVC_RUNTIME_LIBRARY:STATIC=MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<BOOL:${NBL_COMPILER_DYNAMIC_RUNTIME}>:DLL>")
7167

7268
# perform DXC compile standard requirement test
7369
set(CMAKE_CXX_STANDARD_REQUIRED ON)

CMakeLists.txt

+4-10
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ if(MSVC)
2121
endif()
2222

2323
option(NBL_STATIC_BUILD "" OFF) # ON for static builds, OFF for shared
24-
option(NBL_DYNAMIC_MSVC_RUNTIME "" ON)
24+
option(NBL_COMPILER_DYNAMIC_RUNTIME "" ON)
2525
option(NBL_SANITIZE_ADDRESS OFF)
2626

27-
if(MSVC)
27+
if(CMAKE_CXX_COMPILER_ID STREQUAL MSVC)
2828
if(NBL_SANITIZE_ADDRESS)
2929
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>")
3030
else()
@@ -35,14 +35,8 @@ endif()
3535
if(NBL_STATIC_BUILD)
3636
message(STATUS "Static Nabla build enabled!")
3737
else()
38-
if(MSVC)
39-
if(NBL_DYNAMIC_MSVC_RUNTIME)
40-
message(STATUS "Shared Nabla build enabled!")
41-
else()
42-
message(FATAL_ERROR "Turn NBL_DYNAMIC_MSVC_RUNTIME on! For dynamic Nabla builds dynamic MSVC runtime is mandatory!")
43-
endif()
44-
else()
45-
message(FATAL_ERROR "Nabla can't be built with shared libraries! Please make sure you are targetting Windows OS and MSVC compiler!")
38+
if(NOT NBL_COMPILER_DYNAMIC_RUNTIME)
39+
message(FATAL_ERROR "Turn NBL_COMPILER_DYNAMIC_RUNTIME on! For dynamic Nabla builds dynamic runtime is mandatory!")
4640
endif()
4741
endif()
4842

CMakePresets.json

+20-4
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

+52-12
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(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()
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)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
# Release
25+
set(NBL_CXX_RELEASE_COMPILE_OPTIONS
26+
/Zc:__cplusplus /O2 /Ob2 /DNDEBUG /GL /MP${_NBL_JOBS_AMOUNT_} /Gy- /Zc:wchar_t /sdl- /GF /GS- /fp:fast
27+
)
28+
29+
# RelWithDebInfo
30+
set(NBL_CXX_RELWITHDEBINFO_COMPILE_OPTIONS
31+
/Zc:__cplusplus /O2 /Ob1 /DNDEBUG /GL /Zc:wchar_t /MP${_NBL_JOBS_AMOUNT_} /Gy /sdl- /Oy- /fp:fast
32+
)
33+
34+
if(NBL_SANITIZE_ADDRESS)
35+
list(APPEND NBL_CXX_COMPILE_OPTIONS /fsanitize=address)
36+
endif()
37+
38+
# this should also be not part of profile, pasting from old flags-set function temporary
39+
# TODO: use profile
40+
41+
#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.
42+
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /INCREMENTAL:NO /LTCG:incremental")
+46
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

-31
Original file line numberDiff line numberDiff line change
@@ -23,51 +23,20 @@ if(NBL_SANITIZE_ADDRESS)
2323
list(APPEND NBL_C_DEBUG_COMPILE_OPTIONS /RTC1)
2424
endif()
2525

26-
set(NBL_CXX_DEBUG_COMPILE_OPTIONS
27-
/Zc:__cplusplus ${NBL_C_DEBUG_COMPILE_OPTIONS}
28-
)
29-
30-
set(NBL_DEBUG_COMPILE_OPTIONS
31-
$<$<COMPILE_LANGUAGE:CXX>:${NBL_CXX_DEBUG_COMPILE_OPTIONS}>
32-
$<$<COMPILE_LANGUAGE:C>:${NBL_C_DEBUG_COMPILE_OPTIONS}>
33-
)
34-
3526
# Release
3627
set(NBL_C_RELEASE_COMPILE_OPTIONS
3728
/O2 /Ob2 /DNDEBUG /GL /MP${_NBL_JOBS_AMOUNT_} /Gy- /Zc:wchar_t /sdl- /GF /GS- /fp:fast
3829
)
39-
set(NBL_CXX_RELEASE_COMPILE_OPTIONS
40-
/Zc:__cplusplus ${NBL_C_RELEASE_COMPILE_OPTIONS}
41-
)
42-
43-
set(NBL_RELEASE_COMPILE_OPTIONS
44-
$<$<COMPILE_LANGUAGE:CXX>:${NBL_CXX_RELEASE_COMPILE_OPTIONS}>
45-
$<$<COMPILE_LANGUAGE:C>:${NBL_C_RELEASE_COMPILE_OPTIONS}>
46-
)
4730

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

6136
if(NBL_SANITIZE_ADDRESS)
6237
list(APPEND NBL_C_COMPILE_OPTIONS /fsanitize=address)
63-
list(APPEND NBL_CXX_COMPILE_OPTIONS ${NBL_C_COMPILE_OPTIONS})
6438
endif()
6539

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

0 commit comments

Comments
 (0)