Skip to content

Commit 062b5ba

Browse files
committed
update profiles & flags check handle, take care of Clang profile; enter new compile errors after upgrading VS and toolsets (coming from DXC source files)
1 parent 7b8cb61 commit 062b5ba

File tree

8 files changed

+208
-197
lines changed

8 files changed

+208
-197
lines changed

cmake/adjust/flags.cmake

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,57 @@ define_property(TARGET PROPERTY NBL_CONFIGURATION_MAP
1212
BRIEF_DOCS "Stores configuration map for a target, it will evaluate to the configuration it's mapped to"
1313
)
1414

15-
function(NBL_REQUEST_COMPILE_OPTION_SUPPORT _NBL_COMPILE_OPTION_)
16-
set(NBL_COMPILE_OPTION "${_NBL_COMPILE_OPTION_}")
15+
# Usage: NBL_REQUEST_COMPILE_OPTION_SUPPORT(LANG <LANG;...> CONFIG <CONFIG;...> OPTIONS <OPTIONS;...> )
16+
# LANG, CONFIG - optional, OPTIONS - required
17+
function(NBL_REQUEST_COMPILE_OPTION_SUPPORT)
18+
cmake_parse_arguments(IMPL "" "" "LANG;CONFIG;OPTIONS" ${ARGN})
1719

18-
foreach(COMPILER IN ITEMS c cxx)
20+
set(DEFAULT_COMPILERS c cxx)
21+
22+
if(NOT IMPL_LANG)
23+
list(APPEND IMPL_LANG ${DEFAULT_COMPILERS})
24+
endif()
25+
26+
if(NOT IMPL_OPTIONS)
27+
message(FATAL_ERROR "NBL_REQUEST_COMPILE_OPTION_SUPPORT's OPTIONS empty!")
28+
endif()
29+
30+
foreach(COMPILER IN ITEMS ${IMPL_LANG})
1931
string(TOUPPER "${COMPILER}" COMPILER_UPPER)
2032

21-
string(REGEX REPLACE "[-=:;/.]" "_" flag_signature "${NBL_COMPILE_OPTION}")
22-
set(flag_var "__${COMPILER_UPPER}_Flag_${flag_signature}")
33+
if(COMPILER_UPPER STREQUAL C)
34+
macro(VALIDATE_FLAG)
35+
check_c_compiler_flag(${ARGV})
36+
endmacro()
37+
elseif(COMPILER_UPPER STREQUAL CXX)
38+
macro(VALIDATE_FLAG)
39+
check_cxx_compiler_flag(${ARGV})
40+
endmacro()
41+
endif()
42+
43+
foreach(COMPILE_OPTION ${IMPL_OPTIONS})
44+
string(REGEX REPLACE "[-=:;/.]" "_" FLAG_SIGNATURE "${COMPILE_OPTION}")
45+
set(FLAG_VAR "NBL_${COMPILER_UPPER}_COMPILER_HAS_${FLAG_SIGNATURE}_FLAG")
2346

24-
if(COMPILER STREQUAL "c")
25-
check_c_compiler_flag("${NBL_COMPILE_OPTION}" ${flag_var})
26-
elseif(COMPILER STREQUAL "cxx")
27-
check_cxx_compiler_flag("${NBL_COMPILE_OPTION}" ${flag_var})
28-
endif()
47+
VALIDATE_FLAG("${COMPILE_OPTION}" "${FLAG_VAR}")
2948

30-
if(${flag_var})
31-
message(STATUS "Enabled \"${NBL_COMPILE_OPTION}\" ${COMPILER_UPPER} compile option for Nabla projects!")
32-
set(NBL_${COMPILER_UPPER}_COMPILE_OPTIONS "${NBL_${COMPILER_UPPER}_COMPILE_OPTIONS};${NBL_COMPILE_OPTION}" PARENT_SCOPE)
33-
else()
34-
message(STATUS "Disabled \"${NBL_COMPILE_OPTION}\" ${COMPILER_UPPER} compile option for Nabla projects! (no support)")
35-
endif()
49+
if(${FLAG_VAR})
50+
if(IMPL_CONFIG)
51+
foreach(CONFIG ${IMPL_CONFIG})
52+
# TODO: validate (${CONFIG} \in ${CMAKE_CONFIGURATION_TYPES})
53+
string(TOUPPER "${CONFIG}" CONFIG_UPPER)
54+
set(NBL_${COMPILER_UPPER}_${CONFIG_UPPER}_COMPILE_OPTIONS "${NBL_${COMPILER_UPPER}_${CONFIG_UPPER}_COMPILE_OPTIONS};${COMPILE_OPTION}" PARENT_SCOPE)
55+
endforeach()
56+
else()
57+
set(NBL_${COMPILER_UPPER}_COMPILE_OPTIONS "${NBL_${COMPILER_UPPER}_COMPILE_OPTIONS};${COMPILE_OPTION}" PARENT_SCOPE)
58+
endif()
59+
endif()
60+
endforeach()
3661
endforeach()
3762
endfunction()
3863

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

4267
# profiles
4368
foreach(NBL_COMPILER_LANGUAGE IN ITEMS C CXX)
Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,5 @@
11
include_guard(GLOBAL)
22

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-
-maes
22-
-mfpmath=sse
23-
-Wextra
24-
-Wno-sequence-point
25-
-Wno-unused-parameter
26-
-Wno-unused-but-set-parameter
27-
-Wno-c++98-compat
28-
-Wno-c++98-compat-pedantic
29-
-Wno-padded
30-
-Wno-unsafe-buffer-usage
31-
-Wno-switch-enum
32-
-Wno-error=ignored-attributes
33-
-Wno-error=unused-function
34-
-Wno-error=unused-variable
35-
-Wno-error=unused-parameter
36-
-Wno-error=ignored-attributes
37-
-Wno-error=non-pod-varargs
38-
-fno-exceptions
39-
)
40-
41-
if(NBL_SANITIZE_ADDRESS)
42-
list(APPEND NBL_CXX_COMPILE_OPTIONS -fsanitize=address)
43-
endif()
44-
45-
if(NBL_SANITIZE_THREAD)
46-
list(APPEND NBL_CXX_COMPILE_OPTIONS -fsanitize=thread)
47-
endif()
48-
49-
# our pervious flags-set function called this, does not affect flags nor configs so I will keep it here temporary
50-
# TODO: move it out from the profile
51-
link_libraries(-fuse-ld=gold)
3+
set(LANG CXX)
4+
include("${CMAKE_CURRENT_LIST_DIR}/impl/Clang.cmake")
5+
# append unique CXX options here
Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,5 @@
11
include_guard(GLOBAL)
22

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")
3+
set(LANG CXX)
4+
include("${CMAKE_CURRENT_LIST_DIR}/impl/MSVC.cmake")
5+
# append unique CXX options here
Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,5 @@
11
include_guard(GLOBAL)
22

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-
-maes
22-
-mfpmath=sse
23-
-Wextra
24-
-Wno-sequence-point
25-
-Wno-unused-parameter
26-
-Wno-unused-but-set-parameter
27-
-Wno-c++98-compat
28-
-Wno-c++98-compat-pedantic
29-
-Wno-padded
30-
-Wno-unsafe-buffer-usage
31-
-Wno-switch-enum
32-
-Wno-error=ignored-attributes
33-
-Wno-error=unused-function
34-
-Wno-error=unused-variable
35-
-Wno-error=unused-parameter
36-
-Wno-error=ignored-attributes
37-
-Wno-error=non-pod-varargs
38-
-fno-exceptions
39-
)
40-
41-
if(NBL_SANITIZE_ADDRESS)
42-
list(APPEND NBL_C_COMPILE_OPTIONS -fsanitize=address)
43-
endif()
44-
45-
if(NBL_SANITIZE_THREAD)
46-
list(APPEND NBL_C_COMPILE_OPTIONS -fsanitize=thread)
47-
endif()
48-
49-
# our pervious flags-set function called this, does not affect flags nor configs so I will keep it here temporary
50-
# TODO: move it out from the profile
51-
link_libraries(-fuse-ld=gold)
3+
set(LANG C)
4+
include("${CMAKE_CURRENT_LIST_DIR}/impl/Clang.cmake")
5+
# append unique C options here
Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,5 @@
11
include_guard(GLOBAL)
22

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-
NBL_REQUEST_COMPILE_OPTION_SUPPORT(/Zc:preprocessor)
16-
17-
# Debug
18-
set(NBL_C_DEBUG_COMPILE_OPTIONS
19-
/Ob0 /Od /MP${_NBL_JOBS_AMOUNT_} /fp:fast /Zc:wchar_t /INCREMENTAL
20-
)
21-
22-
if(NBL_SANITIZE_ADDRESS)
23-
list(APPEND NBL_C_DEBUG_COMPILE_OPTIONS /RTC1)
24-
endif()
25-
26-
# Release
27-
set(NBL_C_RELEASE_COMPILE_OPTIONS
28-
/O2 /Ob2 /DNDEBUG /GL /MP${_NBL_JOBS_AMOUNT_} /Gy- /Zc:wchar_t /sdl- /GF /GS- /fp:fast
29-
)
30-
31-
# RelWithDebInfo
32-
set(NBL_C_RELWITHDEBINFO_COMPILE_OPTIONS
33-
/O2 /Ob1 /DNDEBUG /GL /Zc:wchar_t /MP${_NBL_JOBS_AMOUNT_} /Gy /sdl- /Oy- /fp:fast
34-
)
35-
36-
if(NBL_SANITIZE_ADDRESS)
37-
list(APPEND NBL_C_COMPILE_OPTIONS /fsanitize=address)
38-
endif()
39-
40-
# this should also be not part of profile, pasting from old flags-set function temporary
41-
# TODO: use profile
42-
43-
#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.
44-
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /INCREMENTAL:NO /LTCG:incremental")
3+
set(LANG C)
4+
include("${CMAKE_CURRENT_LIST_DIR}/impl/MSVC.cmake")
5+
# append unique C options here
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
include("${CMAKE_CURRENT_LIST_DIR}/reset.cmake")
2+
3+
# vendor template with options fitting for both C and CXX LANGs
4+
5+
if(NOT DEFINED LANG)
6+
message(FATAL_ERROR "LANG must be defined!")
7+
endif()
8+
9+
if(NBL_REQUEST_SSE_4_2)
10+
NBL_REQUEST_COMPILE_OPTION_SUPPORT(LANG ${LANG} OPTIONS
11+
-msse4.2 # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang1-msse4.2
12+
)
13+
endif()
14+
15+
if(NBL_REQUEST_SSE_AVX2)
16+
NBL_REQUEST_COMPILE_OPTION_SUPPORT(LANG ${LANG} OPTIONS
17+
-mavx2 # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mavx2
18+
)
19+
endif()
20+
21+
list(APPEND NBL_${LANG}_COMPILE_OPTIONS
22+
-Wextra # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-W-warning
23+
-maes # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-maes
24+
-mfpmath=sse # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mfpmath
25+
26+
# TODO: Yas, eliminate all below
27+
-fno-strict-aliasing
28+
-Wno-sequence-point
29+
-Wno-c++98-compat
30+
-Wno-c++98-compat-pedantic
31+
-Wno-padded
32+
-Wno-unsafe-buffer-usage
33+
-Wno-switch-enum
34+
-Wno-error=ignored-attributes
35+
-Wno-unused-parameter
36+
-Wno-unused-but-set-parameter
37+
-Wno-error=unused-function
38+
-Wno-error=unused-variable
39+
-Wno-error=unused-parameter
40+
-Wno-error=ignored-attributes
41+
-Wno-error=non-pod-varargs
42+
)
43+
44+
if(NBL_SANITIZE_ADDRESS)
45+
list(APPEND NBL_${LANG}_COMPILE_OPTIONS -fsanitize=address)
46+
endif()
47+
48+
if(NBL_SANITIZE_THREAD)
49+
list(APPEND NBL_${LANG}_COMPILE_OPTIONS -fsanitize=thread)
50+
endif()
51+
52+
set(NBL_${LANG}_DEBUG_COMPILE_OPTIONS
53+
-g # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-g
54+
-mincremental-linker-compatible # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mincremental-linker-compatible
55+
-fincremental-extensions # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fincremental-extensions
56+
-Wall # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-W-warning
57+
-fstack-protector-strong # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fstack-protector-strong
58+
-gline-tables-only # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-gline-tables-only
59+
-fno-omit-frame-pointer # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fomit-frame-pointer
60+
-fno-inline-functions # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-finline-functions
61+
)
62+
63+
set(NBL_${LANG}_RELEASE_COMPILE_OPTIONS
64+
-O2 # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-O-arg
65+
-finline-functions # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-finline-functions
66+
-mno-incremental-linker-compatible # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mincremental-linker-compatible
67+
)
68+
69+
set(NBL_${LANG}_RELWITHDEBINFO_COMPILE_OPTIONS
70+
-g # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-g
71+
-O1 # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-O-arg
72+
-finline-functions # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-finline-functions
73+
-mno-incremental-linker-compatible # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mincremental-linker-compatible
74+
-fno-omit-frame-pointer # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fomit-frame-pointer
75+
)

0 commit comments

Comments
 (0)