Use add_compile_definitions for newer CMake versions.

add_definitions is deprecated.
Note the new command does not need the -D qualifier but will detect
if there is one and act accordingly. This helps with package
configuration files that have "-DVAR" in their COMPILE_DEFINTIONS

As some packages actually already add the -D qualifier we now detect
that to be able to support old CMake version without
add_compile_definitions. In this case we prevent adding another -D
and use add_definitions.
This commit is contained in:
Markus Blatt
2021-03-15 21:52:59 +01:00
parent 66ed9bcf75
commit a4f73a3a7c
2 changed files with 10 additions and 2 deletions

View File

@@ -29,7 +29,11 @@ macro (opm_compile opm)
# create this library, if there are any compilation units
link_directories (${${opm}_LIBRARY_DIRS})
add_definitions (${${opm}_DEFINITIONS})
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.12")
add_compile_definitions (${${opm}_DEFINITIONS})
else()
add_definitions(${${opm}_DEFINITIONS})
endif()
set (${opm}_VERSION "${${opm}_VERSION_MAJOR}.${${opm}_VERSION_MINOR}")
if (${opm}_SOURCES)
add_library (${${opm}_TARGET} ${${opm}_LIBRARY_TYPE} ${${opm}_SOURCES})

View File

@@ -96,9 +96,13 @@ macro (find_opm_package module deps header lib defs prog conf)
# compile with this option to avoid avalanche of warnings
set (${module}_DEFINITIONS "${${module}_DEFINITIONS}")
foreach (_def IN ITEMS ${defs})
list (APPEND ${module}_DEFINITIONS "-D${_def}")
if(_def MATCHES "^[A-Za-z].*")
list (APPEND ${module}_DEFINITIONS "-D${_def}")
endif()
endforeach (_def)
list (APPEND ${module}_DEFINITIONS ${defs})
# tidy the lists before returning them
remove_dup_deps (${module})