diff options
| author | Friedrich W. H. Kossebau <kossebau@kde.org> | 2021-01-17 22:08:41 +0100 | 
|---|---|---|
| committer | Friedrich W. H. Kossebau <kossebau@kde.org> | 2021-01-17 22:08:41 +0100 | 
| commit | 1704f7ab86253169615f19a9b10e2a832191b905 (patch) | |
| tree | 6106ffc9e1a14ab4a9947134179d63a5e2bea0d1 | |
| parent | 50c0f8b05bd623af927d29dc01e5c7e7fb04dd34 (diff) | |
| download | extra-cmake-modules-1704f7ab86253169615f19a9b10e2a832191b905.tar.gz extra-cmake-modules-1704f7ab86253169615f19a9b10e2a832191b905.tar.bz2  | |
ECMQtDeclareLoggingCategory: create .categories files in build, not configure
Ensures that the files
* are re-created by build rule when accidentally deleted in the build dir
* are not getting new timestamps on every cmake run, even when content
  has not changed
| -rw-r--r-- | modules/ECMQtDeclareLoggingCategory.cmake | 18 | ||||
| -rw-r--r-- | tests/CMakeLists.txt | 9 | ||||
| -rw-r--r-- | tests/ECMQtDeclareLoggingCategoryTest/CMakeLists.txt | 32 | ||||
| -rw-r--r-- | tests/ECMQtDeclareLoggingCategoryTest/check.cmake.in | 35 | 
4 files changed, 60 insertions, 34 deletions
diff --git a/modules/ECMQtDeclareLoggingCategory.cmake b/modules/ECMQtDeclareLoggingCategory.cmake index bc6f4710..752b5554 100644 --- a/modules/ECMQtDeclareLoggingCategory.cmake +++ b/modules/ECMQtDeclareLoggingCategory.cmake @@ -329,7 +329,7 @@ function(ecm_qt_install_logging_categories)          set(ARGS_FILE "${CMAKE_CURRENT_BINARY_DIR}/${ARGS_FILE}")      endif() -    file(WRITE ${ARGS_FILE} +    set(_categories_content  "# KDebugSettings data file  # This file was generated by ecm_qt_install_logging_categories(). DO NOT EDIT! @@ -350,15 +350,20 @@ function(ecm_qt_install_logging_categories)          # Format:          # logname<space>description(optional <space> DEFAULT_SEVERITY [DEFAULT_CATEGORY] as WARNING/DEBUG/INFO/CRITICAL) optional IDENTIFIER [...]) -        file(APPEND ${ARGS_FILE} "${_category} ${_description} ${_default_severity}IDENTIFIER [${_identifier}]\n") +        string(APPEND _categories_content "${_category} ${_description} ${_default_severity}IDENTIFIER [${_identifier}]\n")      endforeach() +    file(GENERATE +        OUTPUT ${ARGS_FILE} +        CONTENT ${_categories_content} +    ) +      set(_renamed_cats_file)      if (_renamed_categories)          get_filename_component(_dir ${ARGS_FILE} DIRECTORY)          get_filename_component(_base_name ${ARGS_FILE} NAME_WE)          set(_renamed_cats_file "${_dir}/${_base_name}.renamecategories") -        file(WRITE ${_renamed_cats_file} +        set(_renamed_cats_content  "# KDebugSettings data file  # This file was generated by ecm_qt_install_logging_categories(). DO NOT EDIT! @@ -373,10 +378,15 @@ function(ecm_qt_install_logging_categories)              foreach(_category_name IN LISTS _category_name_history)                  # Format:                  # oldlogname<space>newlogname -                file(APPEND ${_renamed_cats_file} "${_old_category_name} ${_category_name}\n") +                string(APPEND _renamed_cats_content "${_old_category_name} ${_category_name}\n")                  set(_old_category_name ${_category_name})              endforeach()          endforeach() + +        file(GENERATE +            OUTPUT ${_renamed_cats_file} +            CONTENT ${_renamed_cats_content} +        )      endif()      # install files diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1901ca16..fff7d988 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -150,7 +150,14 @@ if (TARGET Qt5::qmake)                       KDEInstallDirsTest.relative_or_absolute dummy)  endif ()  if (Qt5Core_FOUND) -    add_test_macro(ECMQtDeclareLoggingCategoryTest testmain) +    set(ECMQtDeclareLoggingCategoryTest_EXTRA_OPTIONS +        --build-target all +        --build-options +            "-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/ECMQtDeclareLoggingCategoryTest/InstallDirectory" +    ) +    add_test_macro(ECMQtDeclareLoggingCategoryTest +        ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/ECMQtDeclareLoggingCategoryTest/check.cmake" +    )  endif()  add_test_macro(FindModules dummy) diff --git a/tests/ECMQtDeclareLoggingCategoryTest/CMakeLists.txt b/tests/ECMQtDeclareLoggingCategoryTest/CMakeLists.txt index a921fd3b..3e8e859e 100644 --- a/tests/ECMQtDeclareLoggingCategoryTest/CMakeLists.txt +++ b/tests/ECMQtDeclareLoggingCategoryTest/CMakeLists.txt @@ -7,25 +7,6 @@ set(CMAKE_MODULE_PATH ${ECM_MODULE_DIR})  include(ECMQtDeclareLoggingCategory)  include(CMakeParseArguments) -function (check_file) -    set(options) -    set(oneValueArgs GENERATED EXPECTED) -    set(multiValueArgs) -    cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - -    if (NOT EXISTS "${ARGS_GENERATED}") -        message(FATAL_ERROR "${ARGS_GENERATED} was not generated") -    endif() -    file(READ "${ARGS_GENERATED}" generated_contents) -    if (NOT EXISTS "${ARGS_EXPECTED}") -        message(FATAL_ERROR "Original ${ARGS_EXPECTED} was not found") -    endif() -    file(READ "${ARGS_EXPECTED}" original_contents) -    if (NOT "${generated_contents}" STREQUAL "${original_contents}") -        message(FATAL_ERROR "${generated_file} contains '${generated_contents}' instead of '${original_contents}'") -    endif() -endfunction() -  ecm_qt_declare_logging_category(      sources      HEADER "log1.h" @@ -78,15 +59,8 @@ target_link_libraries(testmain  ecm_qt_install_logging_categories(      EXPORT LOG      FILE log.categories -    DESTINATION "${CMAKE_BINARY_DIR}/dummyinstall" -) - -check_file( -    GENERATED "${CMAKE_CURRENT_BINARY_DIR}/log.categories" -    EXPECTED "${CMAKE_CURRENT_SOURCE_DIR}/log.categories" -) -check_file( -    GENERATED "${CMAKE_CURRENT_BINARY_DIR}/log.renamecategories" -    EXPECTED "${CMAKE_CURRENT_SOURCE_DIR}/log.renamecategories" +    DESTINATION "${CMAKE_INSTALL_PREFIX}/share/qlogging-categories5"  ) +# this will be run by CTest +configure_file(check.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/check.cmake" @ONLY) diff --git a/tests/ECMQtDeclareLoggingCategoryTest/check.cmake.in b/tests/ECMQtDeclareLoggingCategoryTest/check.cmake.in new file mode 100644 index 00000000..2b684148 --- /dev/null +++ b/tests/ECMQtDeclareLoggingCategoryTest/check.cmake.in @@ -0,0 +1,35 @@ +set(CMAKE_MODULE_PATH "@MODULES_DIR@/../kde-modules") +set(CMAKE_CURRENT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@") +set(CMAKE_CURRENT_BINARY_DIR "@CMAKE_CURRENT_BINARY_DIR@") + + +########################################################### + +function (check_file) +    set(options) +    set(oneValueArgs GENERATED EXPECTED) +    set(multiValueArgs) +    cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + +    if (NOT EXISTS "${ARGS_GENERATED}") +        message(FATAL_ERROR "${ARGS_GENERATED} was not generated") +    endif() +    file(READ "${ARGS_GENERATED}" generated_contents) +    if (NOT EXISTS "${ARGS_EXPECTED}") +        message(FATAL_ERROR "Original ${ARGS_EXPECTED} was not found") +    endif() +    file(READ "${ARGS_EXPECTED}" original_contents) +    if (NOT "${generated_contents}" STREQUAL "${original_contents}") +        message(FATAL_ERROR "${generated_file} contains '${generated_contents}' instead of '${original_contents}'") +    endif() +endfunction() + + +check_file( +    GENERATED "${CMAKE_CURRENT_BINARY_DIR}/log.categories" +    EXPECTED "${CMAKE_CURRENT_SOURCE_DIR}/log.categories" +) +check_file( +    GENERATED "${CMAKE_CURRENT_BINARY_DIR}/log.renamecategories" +    EXPECTED "${CMAKE_CURRENT_SOURCE_DIR}/log.renamecategories" +)  | 
