diff options
Diffstat (limited to 'cmake/scripts/common/Macros.cmake')
| -rw-r--r-- | cmake/scripts/common/Macros.cmake | 111 |
1 files changed, 77 insertions, 34 deletions
diff --git a/cmake/scripts/common/Macros.cmake b/cmake/scripts/common/Macros.cmake index d508f87..c21069d 100644 --- a/cmake/scripts/common/Macros.cmake +++ b/cmake/scripts/common/Macros.cmake | |||
| @@ -338,15 +338,54 @@ macro(export_dep) | |||
| 338 | mark_as_advanced(${depup}_LIBRARIES) | 338 | mark_as_advanced(${depup}_LIBRARIES) |
| 339 | endmacro() | 339 | endmacro() |
| 340 | 340 | ||
| 341 | # add a required dependency of main application | 341 | # split dependency specification to name and version |
| 342 | # Arguments: | 342 | # Arguments: |
| 343 | # dep_list name of find rule for dependency, used uppercased for variable prefix | 343 | # depspec dependency specification that can optionally include a required |
| 344 | # also accepts a list of multiple dependencies | 344 | # package version |
| 345 | # syntax: [package name], [package name]>=[version] (minimum version), | ||
| 346 | # or [package name]=[version] (exact version) | ||
| 347 | # name_outvar variable that should receive the package name | ||
| 348 | # version_outvar variable that should receive the package version part (>=[version]) | ||
| 345 | # On return: | 349 | # On return: |
| 346 | # dependency added to ${SYSTEM_INCLUDES}, ${DEPLIBS} and ${DEP_DEFINES} | 350 | # ${name_outvar} and ${version_outvar} in caller scope are set to respective values. |
| 351 | # ${version_outvar} may be unset if there is no specific version requested. | ||
| 352 | function(split_dependency_specification depspec name_outvar version_outvar) | ||
| 353 | if(${depspec} MATCHES "^([^>]*)(>?=[0-9.]+)$") | ||
| 354 | set(${name_outvar} ${CMAKE_MATCH_1} PARENT_SCOPE) | ||
| 355 | set(${version_outvar} ${CMAKE_MATCH_2} PARENT_SCOPE) | ||
| 356 | else() | ||
| 357 | set(${name_outvar} ${depspec} PARENT_SCOPE) | ||
| 358 | unset(${version_outvar} PARENT_SCOPE) | ||
| 359 | endif() | ||
| 360 | endfunction() | ||
| 361 | |||
| 362 | # helper macro to split version info from req and call find_package | ||
| 363 | macro(find_package_with_ver package) | ||
| 364 | set(_find_arguments "${ARGN}") | ||
| 365 | if("${ARGV1}" MATCHES "^(>)?=([0-9.]+)$") | ||
| 366 | # We have a version spec, parse it | ||
| 367 | list(REMOVE_AT _find_arguments 0) | ||
| 368 | # ">" not present? -> exact match | ||
| 369 | if(NOT CMAKE_MATCH_1) | ||
| 370 | list(INSERT _find_arguments 0 "EXACT") | ||
| 371 | endif() | ||
| 372 | find_package(${package} ${CMAKE_MATCH_2} ${_find_arguments}) | ||
| 373 | else() | ||
| 374 | find_package(${package} ${_find_arguments}) | ||
| 375 | endif() | ||
| 376 | unset(_find_arguments) | ||
| 377 | endmacro() | ||
| 378 | |||
| 379 | # add required dependencies of main application | ||
| 380 | # Arguments: | ||
| 381 | # dep_list One or many dependency specifications (see split_dependency_specification) | ||
| 382 | # for syntax). The dependency name is used uppercased as variable prefix. | ||
| 383 | # On return: | ||
| 384 | # dependencies added to ${SYSTEM_INCLUDES}, ${DEPLIBS} and ${DEP_DEFINES} | ||
| 347 | function(core_require_dep) | 385 | function(core_require_dep) |
| 348 | foreach(dep ${ARGN}) | 386 | foreach(depspec ${ARGN}) |
| 349 | find_package(${dep} REQUIRED) | 387 | split_dependency_specification(${depspec} dep version) |
| 388 | find_package_with_ver(${dep} ${version} REQUIRED) | ||
| 350 | string(TOUPPER ${dep} depup) | 389 | string(TOUPPER ${dep} depup) |
| 351 | list(APPEND SYSTEM_INCLUDES ${${depup}_INCLUDE_DIRS}) | 390 | list(APPEND SYSTEM_INCLUDES ${${depup}_INCLUDE_DIRS}) |
| 352 | list(APPEND DEPLIBS ${${depup}_LIBRARIES}) | 391 | list(APPEND DEPLIBS ${${depup}_LIBRARIES}) |
| @@ -355,15 +394,16 @@ function(core_require_dep) | |||
| 355 | endforeach() | 394 | endforeach() |
| 356 | endfunction() | 395 | endfunction() |
| 357 | 396 | ||
| 358 | # add a required dyloaded dependency of main application | 397 | # add required dyloaded dependencies of main application |
| 359 | # Arguments: | 398 | # Arguments: |
| 360 | # dep_list name of find rule for dependency, used uppercased for variable prefix | 399 | # dep_list One or many dependency specifications (see split_dependency_specification) |
| 361 | # also accepts a list of multiple dependencies | 400 | # for syntax). The dependency name is used uppercased as variable prefix. |
| 362 | # On return: | 401 | # On return: |
| 363 | # dependency added to ${SYSTEM_INCLUDES}, ${dep}_SONAME is set up | 402 | # dependency added to ${SYSTEM_INCLUDES}, ${dep}_SONAME is set up |
| 364 | function(core_require_dyload_dep) | 403 | function(core_require_dyload_dep) |
| 365 | foreach(dep ${ARGN}) | 404 | foreach(depspec ${ARGN}) |
| 366 | find_package(${dep} REQUIRED) | 405 | split_dependency_specification(${depspec} dep version) |
| 406 | find_package_with_ver(${dep} ${version} REQUIRED) | ||
| 367 | string(TOUPPER ${dep} depup) | 407 | string(TOUPPER ${dep} depup) |
| 368 | list(APPEND SYSTEM_INCLUDES ${${depup}_INCLUDE_DIRS}) | 408 | list(APPEND SYSTEM_INCLUDES ${${depup}_INCLUDE_DIRS}) |
| 369 | list(APPEND DEP_DEFINES ${${depup}_DEFINITIONS}) | 409 | list(APPEND DEP_DEFINES ${${depup}_DEFINITIONS}) |
| @@ -385,20 +425,21 @@ macro(setup_enable_switch) | |||
| 385 | set(${enable_switch} "AUTO" CACHE STRING "Enable ${depup} support?") | 425 | set(${enable_switch} "AUTO" CACHE STRING "Enable ${depup} support?") |
| 386 | endmacro() | 426 | endmacro() |
| 387 | 427 | ||
| 388 | # add an optional dependency of main application | 428 | # add optional dependencies of main application |
| 389 | # Arguments: | 429 | # Arguments: |
| 390 | # dep_list name of find rule for dependency, used uppercased for variable prefix | 430 | # dep_list One or many dependency specifications (see split_dependency_specification) |
| 391 | # also accepts a list of multiple dependencies | 431 | # for syntax). The dependency name is used uppercased as variable prefix. |
| 392 | # On return: | 432 | # On return: |
| 393 | # dependency optionally added to ${SYSTEM_INCLUDES}, ${DEPLIBS} and ${DEP_DEFINES} | 433 | # dependency optionally added to ${SYSTEM_INCLUDES}, ${DEPLIBS} and ${DEP_DEFINES} |
| 394 | function(core_optional_dep) | 434 | function(core_optional_dep) |
| 395 | foreach(dep ${ARGN}) | 435 | foreach(depspec ${ARGN}) |
| 396 | set(_required False) | 436 | set(_required False) |
| 437 | split_dependency_specification(${depspec} dep version) | ||
| 397 | setup_enable_switch() | 438 | setup_enable_switch() |
| 398 | if(${enable_switch} STREQUAL AUTO) | 439 | if(${enable_switch} STREQUAL AUTO) |
| 399 | find_package(${dep}) | 440 | find_package_with_ver(${dep} ${version}) |
| 400 | elseif(${${enable_switch}}) | 441 | elseif(${${enable_switch}}) |
| 401 | find_package(${dep} REQUIRED) | 442 | find_package_with_ver(${dep} ${version} REQUIRED) |
| 402 | set(_required True) | 443 | set(_required True) |
| 403 | endif() | 444 | endif() |
| 404 | 445 | ||
| @@ -417,20 +458,21 @@ function(core_optional_dep) | |||
| 417 | set(final_message ${final_message} PARENT_SCOPE) | 458 | set(final_message ${final_message} PARENT_SCOPE) |
| 418 | endfunction() | 459 | endfunction() |
| 419 | 460 | ||
| 420 | # add an optional dyloaded dependency of main application | 461 | # add optional dyloaded dependencies of main application |
| 421 | # Arguments: | 462 | # Arguments: |
| 422 | # dep_list name of find rule for dependency, used uppercased for variable prefix | 463 | # dep_list One or many dependency specifications (see split_dependency_specification) |
| 423 | # also accepts a list of multiple dependencies | 464 | # for syntax). The dependency name is used uppercased as variable prefix. |
| 424 | # On return: | 465 | # On return: |
| 425 | # dependency optionally added to ${SYSTEM_INCLUDES}, ${DEP_DEFINES}, ${dep}_SONAME is set up | 466 | # dependency optionally added to ${SYSTEM_INCLUDES}, ${DEP_DEFINES}, ${dep}_SONAME is set up |
| 426 | function(core_optional_dyload_dep) | 467 | function(core_optional_dyload_dep) |
| 427 | foreach(dep ${ARGN}) | 468 | foreach(depspec ${ARGN}) |
| 428 | set(_required False) | 469 | set(_required False) |
| 429 | setup_enable_switch() | 470 | split_dependency_specification(${depspec} dep version) |
| 471 | setup_enable_switch() | ||
| 430 | if(${enable_switch} STREQUAL AUTO) | 472 | if(${enable_switch} STREQUAL AUTO) |
| 431 | find_package(${dep}) | 473 | find_package_with_ver(${dep} ${version}) |
| 432 | elseif(${${enable_switch}}) | 474 | elseif(${${enable_switch}}) |
| 433 | find_package(${dep} REQUIRED) | 475 | find_package_with_ver(${dep} ${version} REQUIRED) |
| 434 | set(_required True) | 476 | set(_required True) |
| 435 | endif() | 477 | endif() |
| 436 | 478 | ||
| @@ -592,6 +634,7 @@ function(core_find_git_rev stamp) | |||
| 592 | else() | 634 | else() |
| 593 | find_package(Git) | 635 | find_package(Git) |
| 594 | if(GIT_FOUND AND EXISTS ${CMAKE_SOURCE_DIR}/.git) | 636 | if(GIT_FOUND AND EXISTS ${CMAKE_SOURCE_DIR}/.git) |
| 637 | # get tree status i.e. clean working tree vs dirty (uncommited or unstashed changes, etc.) | ||
| 595 | execute_process(COMMAND ${GIT_EXECUTABLE} update-index --ignore-submodules -q --refresh | 638 | execute_process(COMMAND ${GIT_EXECUTABLE} update-index --ignore-submodules -q --refresh |
| 596 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) | 639 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) |
| 597 | execute_process(COMMAND ${GIT_EXECUTABLE} diff-files --ignore-submodules --quiet -- | 640 | execute_process(COMMAND ${GIT_EXECUTABLE} diff-files --ignore-submodules --quiet -- |
| @@ -602,21 +645,21 @@ function(core_find_git_rev stamp) | |||
| 602 | RESULT_VARIABLE status_code | 645 | RESULT_VARIABLE status_code |
| 603 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) | 646 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) |
| 604 | endif() | 647 | endif() |
| 648 | # get HEAD commit SHA-1 | ||
| 649 | execute_process(COMMAND ${GIT_EXECUTABLE} log -n 1 --pretty=format:"%h" HEAD | ||
| 650 | OUTPUT_VARIABLE HASH | ||
| 651 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) | ||
| 652 | string(REPLACE "\"" "" HASH ${HASH}) | ||
| 653 | |||
| 605 | if(status_code) | 654 | if(status_code) |
| 606 | execute_process(COMMAND ${GIT_EXECUTABLE} log -n 1 --pretty=format:"%h-dirty" HEAD | 655 | string(CONCAT HASH ${HASH} "-dirty") |
| 607 | OUTPUT_VARIABLE HASH | ||
| 608 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) | ||
| 609 | string(SUBSTRING ${HASH} 1 13 HASH) | ||
| 610 | else() | ||
| 611 | execute_process(COMMAND ${GIT_EXECUTABLE} log -n 1 --pretty=format:"%h" HEAD | ||
| 612 | OUTPUT_VARIABLE HASH | ||
| 613 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) | ||
| 614 | string(SUBSTRING ${HASH} 1 7 HASH) | ||
| 615 | endif() | 656 | endif() |
| 657 | |||
| 658 | # get HEAD commit date | ||
| 616 | execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:"%cd" --date=short HEAD | 659 | execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:"%cd" --date=short HEAD |
| 617 | OUTPUT_VARIABLE DATE | 660 | OUTPUT_VARIABLE DATE |
| 618 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) | 661 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) |
| 619 | string(SUBSTRING ${DATE} 1 10 DATE) | 662 | string(REPLACE "\"" "" DATE ${DATE}) |
| 620 | string(REPLACE "-" "" DATE ${DATE}) | 663 | string(REPLACE "-" "" DATE ${DATE}) |
| 621 | else() | 664 | else() |
| 622 | string(TIMESTAMP DATE "%Y%m%d" UTC) | 665 | string(TIMESTAMP DATE "%Y%m%d" UTC) |
