Cleanup: CMake: De-duplicate with_shader_cpp_compilation code

Move the common setup and function to `macros.cmake`.

Pull Request: https://projects.blender.org/blender/blender/pulls/131391
This commit is contained in:
Miguel Pozo
2024-12-06 21:03:11 +01:00
committed by Clément Foucault
parent 7a8a58e7e5
commit e3c6c2c6fc
6 changed files with 55 additions and 197 deletions

View File

@@ -1491,3 +1491,41 @@ macro(windows_process_platform_bundled_libraries library_deps)
endforeach()
endif()
endmacro()
macro(with_shader_cpp_compilation_config)
# avoid noisy warnings
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
add_c_flag("-Wno-unused-result")
remove_cc_flag("-Wmissing-declarations")
# Would be nice to enable the warning once we support references.
add_cxx_flag("-Wno-uninitialized")
# Would be nice to enable the warning once we support nameless parameters.
add_cxx_flag("-Wno-unused-parameter")
# To compile libraries.
add_cxx_flag("-Wno-pragma-once-outside-header")
elseif(MSVC)
# Equivalent to "-Wno-uninitialized"
add_cxx_flag("/wd4700")
# Equivalent to "-Wno-unused-parameter"
add_cxx_flag("/wd4100")
# Disable "potential divide by 0" warning
add_cxx_flag("/wd4723")
endif()
add_definitions(-DGPU_SHADER)
endmacro()
function(compile_sources_as_cpp
executable
sources
define
)
foreach(glsl_file ${sources})
set_source_files_properties(${glsl_file} PROPERTIES LANGUAGE CXX)
endforeach()
add_library(${executable} OBJECT ${sources})
set_target_properties(${executable} PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(${executable} PUBLIC ${INC_GLSL})
target_compile_definitions(${executable} PRIVATE ${define})
endfunction()

View File

@@ -2,25 +2,6 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later
# avoid noisy warnings
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
add_c_flag("-Wno-unused-result")
remove_cc_flag("-Wmissing-declarations")
# Would be nice to enable the warning once we support references.
add_cxx_flag("-Wno-uninitialized")
# Would be nice to enable the warning once we support nameless parameters.
add_cxx_flag("-Wno-unused-parameter")
# To compile libraries.
add_cxx_flag("-Wno-pragma-once-outside-header")
elseif(MSVC)
# Equivalent to "-Wno-uninitialized"
add_cxx_flag("/wd4700")
# Equivalent to "-Wno-unused-parameter"
add_cxx_flag("/wd4100")
# Disable "potential divide by 0" warning
add_cxx_flag("/wd4723")
endif()
set(INC_GLSL
.
..
@@ -229,29 +210,12 @@ set(SRC_GLSL_LIB
eevee_volume_lib.glsl
)
add_definitions(-DGPU_SHADER)
# TODO Remove
add_definitions(-DUSE_GPU_SHADER_CREATE_INFO)
function(compile_sources_as_cpp
executable
sources
define
)
foreach(glsl_file ${sources})
set_source_files_properties(${glsl_file} PROPERTIES LANGUAGE CXX)
endforeach()
add_library(${executable} OBJECT ${sources})
set_target_properties(${executable} PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(${executable} PUBLIC ${INC_GLSL})
target_compile_definitions(${executable} PRIVATE ${define})
endfunction()
# Compile shaders with shader code.
if (WITH_GPU_SHADER_CPP_COMPILATION)
with_shader_cpp_compilation_config()
# TODO Remove
add_definitions(-DUSE_GPU_SHADER_CREATE_INFO)
compile_sources_as_cpp(eevee_cpp_shaders_vert "${SRC_GLSL_VERT}" "GPU_VERTEX_SHADER")
compile_sources_as_cpp(eevee_cpp_shaders_frag "${SRC_GLSL_FRAG}" "GPU_FRAGMENT_SHADER")
compile_sources_as_cpp(eevee_cpp_shaders_comp "${SRC_GLSL_COMP}" "GPU_COMPUTE_SHADER")

View File

@@ -2,25 +2,6 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later
# avoid noisy warnings
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
add_c_flag("-Wno-unused-result")
remove_cc_flag("-Wmissing-declarations")
# Would be nice to enable the warning once we support references.
add_cxx_flag("-Wno-uninitialized")
# Would be nice to enable the warning once we support nameless parameters.
add_cxx_flag("-Wno-unused-parameter")
# To compile libraries.
add_cxx_flag("-Wno-pragma-once-outside-header")
elseif(MSVC)
# Equivalent to "-Wno-uninitialized"
add_cxx_flag("/wd4700")
# Equivalent to "-Wno-unused-parameter"
add_cxx_flag("/wd4100")
# Disable "potential divide by 0" warning
add_cxx_flag("/wd4723")
endif()
set(INC_GLSL
.
..
@@ -60,27 +41,10 @@ set(SRC_GLSL_LIB
gpencil_common_lib.glsl
)
add_definitions(-DGPU_SHADER)
function(compile_sources_as_cpp
executable
sources
define
)
foreach(glsl_file ${sources})
set_source_files_properties(${glsl_file} PROPERTIES LANGUAGE CXX)
endforeach()
add_library(${executable} OBJECT ${sources})
set_target_properties(${executable} PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(${executable} PUBLIC ${INC_GLSL})
target_compile_definitions(${executable} PRIVATE ${define})
endfunction()
# Compile shaders with shader code.
if (WITH_GPU_SHADER_CPP_COMPILATION)
with_shader_cpp_compilation_config()
compile_sources_as_cpp(gpencil_cpp_shaders_vert "${SRC_GLSL_VERT}" "GPU_VERTEX_SHADER")
compile_sources_as_cpp(gpencil_cpp_shaders_frag "${SRC_GLSL_FRAG}" "GPU_FRAGMENT_SHADER")
# compile_sources_as_cpp(gpencil_cpp_shaders_comp "${SRC_GLSL_COMP}" "GPU_COMPUTE_SHADER")

View File

@@ -2,25 +2,6 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later
# avoid noisy warnings
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
add_c_flag("-Wno-unused-result")
remove_cc_flag("-Wmissing-declarations")
# Would be nice to enable the warning once we support references.
add_cxx_flag("-Wno-uninitialized")
# Would be nice to enable the warning once we support nameless parameters.
add_cxx_flag("-Wno-unused-parameter")
# To compile libraries.
add_cxx_flag("-Wno-pragma-once-outside-header")
elseif(MSVC)
# Equivalent to "-Wno-uninitialized"
add_cxx_flag("/wd4700")
# Equivalent to "-Wno-unused-parameter"
add_cxx_flag("/wd4100")
# Disable "potential divide by 0" warning
add_cxx_flag("/wd4723")
endif()
set(INC_GLSL
.
..
@@ -82,29 +63,12 @@ set(SRC_GLSL_LIB
workbench_world_light_lib.glsl
)
add_definitions(-DGPU_SHADER)
# TODO Remove
add_definitions(-DUSE_GPU_SHADER_CREATE_INFO)
function(compile_sources_as_cpp
executable
sources
define
)
foreach(glsl_file ${sources})
set_source_files_properties(${glsl_file} PROPERTIES LANGUAGE CXX)
endforeach()
add_library(${executable} OBJECT ${sources})
set_target_properties(${executable} PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(${executable} PUBLIC ${INC_GLSL})
target_compile_definitions(${executable} PRIVATE ${define})
endfunction()
# Compile shaders with shader code.
if (WITH_GPU_SHADER_CPP_COMPILATION)
with_shader_cpp_compilation_config()
# TODO Remove
add_definitions(-DUSE_GPU_SHADER_CREATE_INFO)
compile_sources_as_cpp(workbench_cpp_shaders_vert "${SRC_GLSL_VERT}" "GPU_VERTEX_SHADER")
compile_sources_as_cpp(workbench_cpp_shaders_frag "${SRC_GLSL_FRAG}" "GPU_FRAGMENT_SHADER")
compile_sources_as_cpp(workbench_cpp_shaders_comp "${SRC_GLSL_COMP}" "GPU_COMPUTE_SHADER")

View File

@@ -2,25 +2,6 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later
# avoid noisy warnings
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
add_c_flag("-Wno-unused-result")
remove_cc_flag("-Wmissing-declarations")
# Would be nice to enable the warning once we support references.
add_cxx_flag("-Wno-uninitialized")
# Would be nice to enable the warning once we support nameless parameters.
add_cxx_flag("-Wno-unused-parameter")
# To compile libraries.
add_cxx_flag("-Wno-pragma-once-outside-header")
elseif(MSVC)
# Equivalent to "-Wno-uninitialized"
add_cxx_flag("/wd4700")
# Equivalent to "-Wno-unused-parameter"
add_cxx_flag("/wd4100")
# Disable "potential divide by 0" warning
add_cxx_flag("/wd4723")
endif()
set(INC_GLSL
.
..
@@ -50,30 +31,13 @@ set(SRC_GLSL_COMP
draw_view_finalize_comp.glsl
draw_visibility_comp.glsl
)
add_definitions(-DGPU_SHADER)
# TODO Remove
add_definitions(-DUSE_GPU_SHADER_CREATE_INFO)
function(compile_sources_as_cpp
executable
sources
define
)
foreach(glsl_file ${sources})
set_source_files_properties(${glsl_file} PROPERTIES LANGUAGE CXX)
endforeach()
add_library(${executable} OBJECT ${sources})
set_target_properties(${executable} PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(${executable} PUBLIC ${INC_GLSL})
target_compile_definitions(${executable} PRIVATE ${define})
endfunction()
# Compile shaders with shader code.
if (WITH_GPU_SHADER_CPP_COMPILATION)
with_shader_cpp_compilation_config()
# TODO Remove
add_definitions(-DUSE_GPU_SHADER_CREATE_INFO)
compile_sources_as_cpp(draw_cpp_shaders_vert "${SRC_GLSL_VERT}" "GPU_VERTEX_SHADER")
compile_sources_as_cpp(draw_cpp_shaders_frag "${SRC_GLSL_FRAG}" "GPU_FRAGMENT_SHADER")
compile_sources_as_cpp(draw_cpp_shaders_comp "${SRC_GLSL_COMP}" "GPU_COMPUTE_SHADER")

View File

@@ -2,25 +2,6 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later
# avoid noisy warnings
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
add_c_flag("-Wno-unused-result")
remove_cc_flag("-Wmissing-declarations")
# Would be nice to enable the warning once we support references.
add_cxx_flag("-Wno-uninitialized")
# Would be nice to enable the warning once we support nameless parameters.
add_cxx_flag("-Wno-unused-parameter")
# To compile libraries.
add_cxx_flag("-Wno-pragma-once-outside-header")
elseif(MSVC)
# Equivalent to "-Wno-uninitialized"
add_cxx_flag("/wd4700")
# Equivalent to "-Wno-unused-parameter"
add_cxx_flag("/wd4100")
# Disable "potential divide by 0" warning
add_cxx_flag("/wd4723")
endif()
set(INC_GLSL
.
..
@@ -104,27 +85,10 @@ set(SRC_GLSL_LIB
common/gpu_shader_print_lib.glsl
)
add_definitions(-DGPU_SHADER)
function(compile_sources_as_cpp
executable
sources
define
)
foreach(glsl_file ${sources})
set_source_files_properties(${glsl_file} PROPERTIES LANGUAGE CXX)
endforeach()
add_library(${executable} OBJECT ${sources})
set_target_properties(${executable} PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(${executable} PUBLIC ${INC_GLSL})
target_compile_definitions(${executable} PRIVATE ${define})
endfunction()
# Compile shaders with shader code.
if (WITH_GPU_SHADER_CPP_COMPILATION)
with_shader_cpp_compilation_config()
compile_sources_as_cpp(gpu_cpp_shaders_vert "${SRC_GLSL_VERT}" "GPU_VERTEX_SHADER")
compile_sources_as_cpp(gpu_cpp_shaders_frag "${SRC_GLSL_FRAG}" "GPU_FRAGMENT_SHADER")
compile_sources_as_cpp(gpu_cpp_shaders_lib "${SRC_GLSL_LIB}" "GPU_LIBRARY_SHADER")