CMake: plumbing for modern CMake usage

This is the minimal change required to start using modern CMake in the
blender build system. This change is designed to allow small
incremental changes to the build system rather than doing it in one
big bang which would be unmaintainable (for me)

The biggest functional change is, previously all libraries in the
`LIB` section of a `blender_add_lib` call had the `INTERFACE` scope,
which is rarely, if ever the correct scope. This diff changes this to
`PRIVATE`

Concrete implications of this diff :

The `LIB`, `INC` and `INC_SYS` sections of an `blender_add_lib` call
now allow scoping keywords (`PUBLIC`, `PRIVATE,` `INTERFACE`) to
declare the scope of the dependency.

Right now the only library using any modern cmake is
`bf_intern_atomic` which is an header only interface library that will
just advertise its include directories.

This allows us to clean up any `CMakeLists.txt` that adds
`../../../intern/atomic` to its `INC` section to remove it in `INC` by
adding a `PRIVATE bf_intern_atomic` to the `LIB` section.

Pull Request: https://projects.blender.org/blender/blender/pulls/107858
This commit is contained in:
Ray molenkamp
2023-06-27 20:57:50 +02:00
parent d53862351d
commit eff9e2f4ce
7 changed files with 159 additions and 75 deletions

View File

@@ -9,6 +9,25 @@ set(INC
set(INC_SYS
)
add_library(bf_intern_atomic INTERFACE)
target_include_directories(bf_intern_atomic INTERFACE .)
# CMake 3.19+ allows one to populate the interface library with
# source files to show in the IDE, for people on older CMake versions
# these headers will be visible in the bf_intern_guardedalloc project
# where they historically have been.
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.19")
set(SRC
atomic_ops.h
intern/atomic_ops_ext.h
intern/atomic_ops_msvc.h
intern/atomic_ops_unix.h
intern/atomic_ops_utils.h
)
target_sources(bf_intern_atomic PRIVATE ${SRC})
blender_source_group(bf_intern_atomic ${SRC})
endif()
if(WITH_GTESTS)
set(TEST_SRC
tests/atomic_test.cc
@@ -16,6 +35,7 @@ if(WITH_GTESTS)
set(TEST_INC
)
set(TEST_LIB
PRIVATE bf_intern_atomic
)
include(GTestTesting)
blender_add_test_executable(atomic "${TEST_SRC}" "${INC};${TEST_INC}" "${INC_SYS}" "${LIB};${TEST_LIB}")