KDE/kdelibs/cmake/modules
Kevin Ottens
ervin at kde.org
Tue Aug 25 16:42:42 CEST 2009
SVN commit 1015454 by ervin:
Handle relative paths gracefully for kde4_add_kcfg_files macro.
If the passed arguments have a relative path, the generated files end up
with the same relative path in the build dir, otherwise the old behavior
is applied (generated files end up in the current build dir).
(Actually we might want to investigate a similar trick for files
generated from ui files, and moc files as I seem to remember having a
similar issue with moc files in solid a while ago, workarounded by
changing lots of filenames...)
Should work fine with existing code, I only had to make a small
adjustment in plasma desktop shell (committed a minute ago).
CCMAIL: kde-buildsystem at kde.org
M +25 -1 KDE4Macros.cmake
--- trunk/KDE/kdelibs/cmake/modules/KDE4Macros.cmake #1015453:1015454
@@ -62,7 +62,26 @@
if(NOT ${_current_FILE} STREQUAL "GENERATE_MOC")
get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
get_filename_component(_abs_PATH ${_tmp_FILE} PATH)
+
+ # Get relative path
+ get_filename_component(_rel_PATH ${_current_FILE} PATH)
+
+ # Resolve the relative path from the current source dir
+ if(NOT ${_rel_PATH} STREQUAL "")
+ get_filename_component(_abs_PATH2 ${CMAKE_CURRENT_SOURCE_DIR}/${_rel_PATH} ABSOLUTE)
+ endif(NOT ${_rel_PATH} STREQUAL "")
+
+ # If the resolved relative path is not equal to the absolute one,
+ # that means that we got an absolute path in the first place
+ if(NOT "${_abs_PATH2}" STREQUAL "${_abs_PATH}")
+ set(_rel_PATH "")
+ endif(NOT "${_abs_PATH2}" STREQUAL "${_abs_PATH}")
+
get_filename_component(_basename ${_tmp_FILE} NAME_WE)
+ # If we had a real relative path, then change the basename accordingly
+ if(NOT ${_rel_PATH} STREQUAL "")
+ set(_basename ${_rel_PATH}/${_basename})
+ endif(NOT ${_rel_PATH} STREQUAL "")
file(READ ${_tmp_FILE} _contents)
string(REGEX REPLACE "^(.*\n)?File=([^\n]+kcfg).*\n.*$" "\\2" _kcfg_FILENAME "${_contents}")
@@ -78,10 +97,15 @@
message(ERROR "${_kcfg_FILENAME} not found; tried in ${_abs_PATH} and ${CMAKE_CURRENT_BINARY_DIR}")
endif(NOT EXISTS "${_kcfg_FILE}")
+ # make sure the directory exist in the build directory
+ if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${_rel_PATH}")
+ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${_rel_PATH})
+ endif(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${_rel_PATH}")
+
# the command for creating the source file from the kcfg file
add_custom_command(OUTPUT ${_header_FILE} ${_src_FILE}
COMMAND ${KDE4_KCFGC_EXECUTABLE}
- ARGS ${_kcfg_FILE} ${_tmp_FILE} -d ${CMAKE_CURRENT_BINARY_DIR}
+ ARGS ${_kcfg_FILE} ${_tmp_FILE} -d ${CMAKE_CURRENT_BINARY_DIR}/${_rel_PATH}
MAIN_DEPENDENCY ${_tmp_FILE}
DEPENDS ${_kcfg_FILE} ${_KDE4_KCONFIG_COMPILER_DEP} )
More information about the Kde-buildsystem
mailing list