Skip to content

Commit

Permalink
[cmake] Speed up export-files target
Browse files Browse the repository at this point in the history
The export-files target mirrors files from the source tree to the build
tree (such as system/ userdata/ addons/) by doing a byte wise diff
which is slow. Instead generate a CMake script that uses file(COPY)
which only copies if the source is newer.

Measurements on Linux machine (real time, cmake + make export-files):
- first run (with cleaned page caches):       19+27s vs. 19+6s
- consecutive run (with cleaned page caches): 12+35s vs. 12+3s
- consecutive run:                             6+18s vs.  6+0.3s

Measurements on Windows machine (real time, cmake + make export-files):
- first run:                                  43+65s vs. 52+8s
- consecutive run:                            19+62s vs. 29+1.5s
  • Loading branch information
fetzerch committed Apr 6, 2016
1 parent ce28cb6 commit cc735b7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions project/cmake/scripts/common/macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@ endfunction()
# (if NO_INSTALL is not given).
function(copy_file_to_buildtree file relative)
cmake_parse_arguments(arg "NO_INSTALL" "" "" ${ARGN})
if(NOT WIN32)
string(REPLACE "\(" "\\(" file ${file})
string(REPLACE "\)" "\\)" file ${file})
endif()
string(REPLACE "${relative}/" "" outfile ${file})
get_filename_component(outdir ${outfile} DIRECTORY)

if(NOT TARGET export-files)
add_custom_target(export-files ALL COMMENT "Copying files into build tree")
file(REMOVE ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ExportFiles.cmake)
add_custom_target(export-files ALL COMMENT "Copying files into build tree"
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ExportFiles.cmake)
endif()
if(NOT ${CORE_SOURCE_DIR} MATCHES ${CMAKE_BINARY_DIR})
if(VERBOSE)
message(STATUS "copy_file_to_buildtree - copying file: ${file} -> ${CMAKE_CURRENT_BINARY_DIR}/${outfile}")
message(STATUS "copy_file_to_buildtree - copying file: ${file} -> ${CMAKE_BINARY_DIR}/${outfile}")
endif()
add_custom_command(TARGET export-files COMMAND ${CMAKE_COMMAND} -E copy_if_different "${file}" "${CMAKE_CURRENT_BINARY_DIR}/${outfile}")
file(APPEND ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ExportFiles.cmake
"file(COPY \"${file}\" DESTINATION \"${CMAKE_BINARY_DIR}/${outdir}\")\n")
endif()
if(NOT arg_NO_INSTALL)
list(APPEND install_data ${outfile})
Expand Down

6 comments on commit cc735b7

@Fneufneu
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry but the first time i build kodi, ExportFiles.cmake does not exist dans the build failed at line 70 here.
is it something only related to FreeBSD cmake build ? because just before that all was fine.
@fetzerch ?

@fetzerch
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is strange. The file(APPEND...) creates the ExportFiles.cmake already at configure/cmake time. Could you upload a log file of the build with cmake executed with --trace. To be honest I never ran a BSD build so it's likely that it has some issues in other areas.

@Fneufneu
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fetzerch thanks for the tips, the problem is line 73, because in my case
${CORE_SOURCE_DIR} == ${CMAKE_BINARY_DIR}
I don't really understand the logic behind this if(), why not use something like that:
if(NOT EXISTS ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ExportFiles.cmake)

@fetzerch
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The (obviously untested ;)) logic behind that was that for in-source-builds, nothing should be copied to the build directory. So if(NOT ${CORE_SOURCE_DIR} MATCHES ${CMAKE_BINARY_DIR}) needs to be the outer condition, and in the else case the export-files target should just have no command associated.

Nevertheless, I would highly recommend to build out-of-source.

@fetzerch
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #10078

@Fneufneu
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

everything is fine when il build out source, thank you for your help :)

Please sign in to comment.