WarnAboutGlobalProperties.cmake raw
1 # Copyright (c) 2023-present The Bitcoin Core developers
2 # Distributed under the MIT software license, see the accompanying
3 # file COPYING or https://opensource.org/license/mit/.
4
5 include_guard(GLOBAL)
6
7 # Avoid the directory-wide add_definitions() and add_compile_definitions() commands.
8 # Instead, prefer the target-specific target_compile_definitions() one.
9 get_directory_property(global_compile_definitions COMPILE_DEFINITIONS)
10 if(global_compile_definitions)
11 message(AUTHOR_WARNING "The directory's COMPILE_DEFINITIONS property is not empty: ${global_compile_definitions}")
12 endif()
13
14 # Avoid the directory-wide add_compile_options() command.
15 # Instead, prefer the target-specific target_compile_options() one.
16 get_directory_property(global_compile_options COMPILE_OPTIONS)
17 if(global_compile_options)
18 message(AUTHOR_WARNING "The directory's COMPILE_OPTIONS property is not empty: ${global_compile_options}")
19 endif()
20
21 # Avoid the directory-wide add_link_options() command.
22 # Instead, prefer the target-specific target_link_options() one.
23 get_directory_property(global_link_options LINK_OPTIONS)
24 if(global_link_options)
25 message(AUTHOR_WARNING "The directory's LINK_OPTIONS property is not empty: ${global_link_options}")
26 endif()
27
28 # Avoid the directory-wide link_libraries() command.
29 # Instead, prefer the target-specific target_link_libraries() one.
30 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy_cxx_source.cpp "#error")
31 add_library(check_loose_linked_libraries OBJECT EXCLUDE_FROM_ALL ${CMAKE_CURRENT_BINARY_DIR}/dummy_cxx_source.cpp)
32 set_target_properties(check_loose_linked_libraries PROPERTIES EXPORT_COMPILE_COMMANDS OFF)
33 get_target_property(global_linked_libraries check_loose_linked_libraries LINK_LIBRARIES)
34 if(global_linked_libraries)
35 message(AUTHOR_WARNING "There are libraries linked with `link_libraries` commands: ${global_linked_libraries}")
36 endif()
37