Make kconfig_compiler autotests use the KCONFIG_ADD_KCFG_FILES

Summary:
Instead of having an odd fake of it. Will help some required
refactorings and already showed some issues, fixed by this patch,
namely:
- don't use string(regex replace) to extract a string from another
string. in case it doesn't match it will offer the whole content which
is never what we want.
- messages(ERROR), the correct parameter is FATAL_ERROR, cmake
understands "ERROR" as mere output string
- turn the macro into a function, otherwise 2 calls in the same
subdirectory are dangerous.

CCBUG: 371562

Test Plan: tests still pass, projects that use the macro still build

Reviewers: #frameworks, dfaure

Reviewed By: dfaure

Subscribers: dfaure

Differential Revision: https://phabricator.kde.org/D3178
wilder
Aleix Pol 10 years ago
parent 3a7b8ae9c9
commit 91dbd2f5a3
  1. 27
      KF5ConfigMacros.cmake
  2. 41
      autotests/kconfig_compiler/CMakeLists.txt
  3. 1
      autotests/kconfig_compiler/test1.kcfgc
  4. 1
      autotests/kconfig_compiler/test12.kcfgc
  5. 1
      autotests/kconfig_compiler/test13.kcfgc
  6. 1
      autotests/kconfig_compiler/test9.kcfgc
  7. 2
      autotests/kconfig_compiler/test_qdebugcategory.kcfgc

@ -32,7 +32,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
macro (KCONFIG_ADD_KCFG_FILES _sources )
function (KCONFIG_ADD_KCFG_FILES _sources )
foreach (_current_ARG ${ARGN})
if( ${_current_ARG} STREQUAL "GENERATE_MOC" )
set(_kcfg_generatemoc TRUE)
@ -43,6 +43,8 @@ macro (KCONFIG_ADD_KCFG_FILES _sources )
endif()
endforeach ()
set(sources)
foreach (_current_FILE ${ARGN})
if(NOT ${_current_FILE} STREQUAL "GENERATE_MOC" AND NOT ${_current_FILE} STREQUAL "USE_RELATIVE_PATH")
@ -61,12 +63,16 @@ macro (KCONFIG_ADD_KCFG_FILES _sources )
get_filename_component(_basename ${_tmp_FILE} NAME_WE)
# If we had a relative path and we're asked to use it, then change the basename accordingly
if(NOT ${_rel_PATH} STREQUAL "")
if(_rel_PATH)
set(_basename ${_rel_PATH}/${_basename})
endif()
file(READ ${_tmp_FILE} _contents)
string(REGEX REPLACE "^(.*\n)?File=([^\n]+kcfg).*\n.*$" "\\2" _kcfg_FILENAME "${_contents}")
string(REGEX MATCH "File=([^\n]+\\.kcfg)\n" "" "${_contents}")
set(_kcfg_FILENAME "${CMAKE_MATCH_1}")
if (NOT _kcfg_FILENAME)
message(WARNING "Couldn't read the \"File\" field in ${_tmp_FILE}")
endif()
set(_src_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp)
set(_header_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h)
set(_moc_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc)
@ -77,7 +83,7 @@ macro (KCONFIG_ADD_KCFG_FILES _sources )
endif()
if(NOT EXISTS "${_kcfg_FILE}")
message(ERROR "${_kcfg_FILENAME} not found; tried in ${_abs_PATH} and ${CMAKE_CURRENT_BINARY_DIR}")
message(FATAL_ERROR "${_kcfg_FILENAME} not found; tried in ${_abs_PATH} and ${CMAKE_CURRENT_BINARY_DIR}")
endif()
# make sure the directory exist in the build directory
@ -93,13 +99,16 @@ macro (KCONFIG_ADD_KCFG_FILES _sources )
DEPENDS ${_kcfg_FILE})
if(_kcfg_generatemoc)
qt5_generate_moc(${_header_FILE} ${_moc_FILE} )
set_source_files_properties(${_src_FILE} PROPERTIES SKIP_AUTOMOC TRUE) # don't run automoc on this file
list(APPEND ${_sources} ${_moc_FILE})
list(APPEND sources ${_moc_FILE})
qt5_generate_moc(${_header_FILE} ${_moc_FILE})
set_property(SOURCE ${_src_FILE} PROPERTY SKIP_AUTOMOC TRUE) # don't run automoc on this file
set_property(SOURCE ${_src_FILE} APPEND PROPERTY OBJECT_DEPENDS ${_moc_FILE} )
endif()
list(APPEND ${_sources} ${_src_FILE} ${_header_FILE})
list(APPEND sources ${_src_FILE} ${_header_FILE})
endif(NOT ${_current_FILE} STREQUAL "GENERATE_MOC" AND NOT ${_current_FILE} STREQUAL "USE_RELATIVE_PATH")
endforeach (_current_FILE)
endmacro (KCONFIG_ADD_KCFG_FILES)
set(${_sources} ${${_sources}} ${sources} PARENT_SCOPE)
endfunction(KCONFIG_ADD_KCFG_FILES)

@ -10,26 +10,10 @@ endif()
# make sure the generated headers can be found
include_directories(${KCFG_OUTPUT_DIR})
include(${CMAKE_SOURCE_DIR}/KF5ConfigMacros.cmake)
macro(GEN_KCFG_TEST_SOURCE _testName _srcs)
cmake_parse_arguments(ARG "" "KCFG" "" ${ARGN} )
set(_kcfgFile ${ARG_KCFG})
if (NOT _kcfgFile)
set(_kcfgFile "${_testName}.kcfg")
endif()
add_custom_command(
OUTPUT ${KCFG_OUTPUT_DIR}/${_testName}.cpp ${KCFG_OUTPUT_DIR}/${_testName}.h
COMMAND KF5::kconfig_compiler ${CMAKE_CURRENT_SOURCE_DIR}/${_kcfgFile} ${CMAKE_CURRENT_SOURCE_DIR}/${_testName}.kcfgc
WORKING_DIRECTORY ${KCFG_OUTPUT_DIR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_kcfgFile} ${CMAKE_CURRENT_SOURCE_DIR}/${_testName}.kcfgc KF5::kconfig_compiler)
# set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_testName}.h PROPERTIES GENERATED TRUE)
qt5_generate_moc(${KCFG_OUTPUT_DIR}/${_testName}.h ${KCFG_OUTPUT_DIR}/${_testName}.moc )
# do not run automoc on the generated file
set_source_files_properties(${KCFG_OUTPUT_DIR}/${_testName}.cpp PROPERTIES SKIP_AUTOMOC TRUE)
set( ${_srcs} ${${_srcs}} ${KCFG_OUTPUT_DIR}/${_testName}.cpp)
set_property(SOURCE ${KCFG_OUTPUT_DIR}/${_testName}.cpp APPEND PROPERTY OBJECT_DEPENDS ${KCFG_OUTPUT_DIR}/${_testName}.moc )
endmacro(GEN_KCFG_TEST_SOURCE)
KCONFIG_ADD_KCFG_FILES(${_srcs} ${_testName}.kcfgc ${ARGN})
endmacro()
include(ECMMarkAsTest)
@ -181,7 +165,7 @@ target_link_libraries(test12 KF5::ConfigGui)
set(test13_SRCS test13main.cpp )
gen_kcfg_test_source(test13 test13_SRCS)
gen_kcfg_test_source(test13 test13_SRCS GENERATE_MOC)
ecm_add_test(TEST_NAME test13 ${test13_SRCS})
target_link_libraries(test13 KF5::ConfigGui)
@ -200,17 +184,17 @@ target_link_libraries(test_dpointer KF5::ConfigGui)
########### next target ###############
set(test_signal_SRCS test_signal_main.cpp )
gen_kcfg_test_source(test_signal test_signal_SRCS)
gen_kcfg_test_source(test_signal test_signal_SRCS GENERATE_MOC)
ecm_add_test(TEST_NAME test_signal ${test_signal_SRCS})
target_link_libraries(test_signal KF5::ConfigGui)
########### next target ###############
set(kconfigcompiler_test_signals_SRCS kconfigcompiler_test_signals.cpp)
gen_kcfg_test_source(signals_test_singleton kconfigcompiler_test_signals_SRCS KCFG signals_test.kcfg)
gen_kcfg_test_source(signals_test_no_singleton kconfigcompiler_test_signals_SRCS KCFG signals_test.kcfg)
gen_kcfg_test_source(signals_test_singleton_dpointer kconfigcompiler_test_signals_SRCS KCFG signals_test.kcfg)
gen_kcfg_test_source(signals_test_no_singleton_dpointer kconfigcompiler_test_signals_SRCS KCFG signals_test.kcfg)
gen_kcfg_test_source(signals_test_singleton kconfigcompiler_test_signals_SRCS GENERATE_MOC)
gen_kcfg_test_source(signals_test_no_singleton kconfigcompiler_test_signals_SRCS GENERATE_MOC)
gen_kcfg_test_source(signals_test_singleton_dpointer kconfigcompiler_test_signals_SRCS GENERATE_MOC)
gen_kcfg_test_source(signals_test_no_singleton_dpointer kconfigcompiler_test_signals_SRCS GENERATE_MOC)
ecm_add_test(${kconfigcompiler_test_signals_SRCS}
TEST_NAME kconfigcompiler-signals-test
@ -236,7 +220,7 @@ target_link_libraries(test_qdebugcategory KF5::ConfigGui)
########### next target ###############
set(test_translation_qt_SRCS test_translation_qt_main.cpp)
gen_kcfg_test_source(test_translation_qt test_translation_qt_SRCS KCFG test_translation.kcfg)
gen_kcfg_test_source(test_translation_qt test_translation_qt_SRCS)
ecm_add_test(TEST_NAME test_translation_qt ${test_translation_qt_SRCS})
target_link_libraries(test_translation_qt KF5::ConfigGui)
@ -244,7 +228,7 @@ target_link_libraries(test_translation_qt KF5::ConfigGui)
########### next target ###############
set(test_translation_kde_SRCS test_translation_kde_main.cpp)
gen_kcfg_test_source(test_translation_kde test_translation_kde_SRCS KCFG test_translation.kcfg)
gen_kcfg_test_source(test_translation_kde test_translation_kde_SRCS)
ecm_add_test(TEST_NAME test_translation_kde ${test_translation_kde_SRCS})
target_link_libraries(test_translation_kde KF5::ConfigGui)
@ -252,8 +236,7 @@ target_link_libraries(test_translation_kde KF5::ConfigGui)
########### next target ###############
set(test_translation_kde_domain_SRCS test_translation_kde_domain_main.cpp)
gen_kcfg_test_source(test_translation_kde_domain test_translation_kde_domain_SRCS KCFG test_translation.kcfg)
gen_kcfg_test_source(test_translation_kde_domain test_translation_kde_domain_SRCS)
ecm_add_test(TEST_NAME test_translation_kde_domain ${test_translation_kde_domain_SRCS})
target_link_libraries(test_translation_kde_domain KF5::ConfigGui)

@ -1,5 +1,6 @@
# Code generation options for kconfig_compiler_kf5
ClassName=Test1
File=test1.kcfg
#
# Singleton=false
#

@ -1 +1,2 @@
ClassName=Test12
File=test12.kcfg

@ -1,3 +1,4 @@
ClassName=Test13
GenerateProperties=true
Mutators=brightness
File=test13.kcfg

@ -1,5 +1,6 @@
# Code generation options for kconfig_compiler_kf5
ClassName=Test9
File=test9.kcfg
#
# Singleton=false
#

@ -1,5 +1,5 @@
# Code generation options for kconfig_compiler_kf5
File=test_qdebugcategory.kcfgc
File=test_qdebugcategory.kcfg
ClassName=TestQCategory
Singleton=false
Mutators=true

Loading…
Cancel
Save