From c8a0dd4f1f63df33979aac904c3c7c2244ed539f Mon Sep 17 00:00:00 2001
From: Frank Winklmeier <frank.winklmeier@cern.ch>
Date: Wed, 15 May 2019 15:47:27 +0200
Subject: [PATCH 1/2] Use separate command for directory creation in install
 targets

Instead of
```
add_custom_command( OUTPUT foo/bar
  COMMAND cmake -E make_directory foo
  COMMAND ... )
```
which will execute a `make_directory` each time a "bar" needs to be
installed, use a separate command:
```
add_custom_command( OUTPUT foo
  COMMAND cmake -E make_directory foo )

add_custom_command( OUTPUT foo/bar
  COMMAND ...
  DEPENDS foo )
```
While the `make_directory` call silently succeeds in case the directory
already exists, it's still a small overhead and `stat` call on the
filesystem. Since this happens for every single (header, python, ...)
file that is being installed, this could add up. It also makes our
verbose build log files a bit more sane.
---
 .../modules/AtlasInstallFunctions.cmake       | 37 +++++++++++++------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/Build/AtlasCMake/modules/AtlasInstallFunctions.cmake b/Build/AtlasCMake/modules/AtlasInstallFunctions.cmake
index a386a24b..642ec2aa 100644
--- a/Build/AtlasCMake/modules/AtlasInstallFunctions.cmake
+++ b/Build/AtlasCMake/modules/AtlasInstallFunctions.cmake
@@ -45,16 +45,19 @@ function( atlas_install_headers )
       -E make_directory
       \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/include )" )
 
+   # Command to create the include directory:
+   add_custom_command( OUTPUT ${CMAKE_INCLUDE_OUTPUT_DIRECTORY}
+      COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_INCLUDE_OUTPUT_DIRECTORY} )
+
    # Loop over the specified directories:
    foreach( dir ${ARG_UNPARSED_ARGUMENTS} )
       # Set up the installation of the header directory into the build area:
       file( RELATIVE_PATH _target ${CMAKE_INCLUDE_OUTPUT_DIRECTORY}
          ${CMAKE_CURRENT_SOURCE_DIR}/${dir} )
       add_custom_command( OUTPUT ${CMAKE_INCLUDE_OUTPUT_DIRECTORY}/${dir}
-         COMMAND ${CMAKE_COMMAND} -E make_directory
-         ${CMAKE_INCLUDE_OUTPUT_DIRECTORY}
          COMMAND ${CMAKE_COMMAND} -E create_symlink ${_target}
-         ${CMAKE_INCLUDE_OUTPUT_DIRECTORY}/${dir} )
+         ${CMAKE_INCLUDE_OUTPUT_DIRECTORY}/${dir}
+         DEPENDS ${CMAKE_INCLUDE_OUTPUT_DIRECTORY} )
       # Clean up on "make clean":
       set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} APPEND PROPERTY
          ADDITIONAL_MAKE_CLEAN_FILES
@@ -155,6 +158,10 @@ function( atlas_install_generic )
       set( _installDest ${ARG_DESTINATION} )
    endif()
 
+   # Command to create the build directory:
+   add_custom_command( OUTPUT ${_buildDest}
+      COMMAND ${CMAKE_COMMAND} -E make_directory ${_buildDest} )
+
    # Now loop over all file names:
    foreach( _file ${_files} )
       # Set up its installation into the build area:
@@ -162,9 +169,9 @@ function( atlas_install_generic )
          ${_buildDest} ${CMAKE_CURRENT_SOURCE_DIR}/${_file} )
       get_filename_component( _filename ${_file} NAME )
       add_custom_command( OUTPUT ${_buildDest}/${_filename}
-         COMMAND ${CMAKE_COMMAND} -E make_directory ${_buildDest}
          COMMAND ${CMAKE_COMMAND} -E create_symlink ${_target}
-         ${_buildDest}/${_filename} )
+         ${_buildDest}/${_filename}
+         DEPENDS ${_buildDest} )
       set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} APPEND PROPERTY
          ADDITIONAL_MAKE_CLEAN_FILES
          ${_buildDest}/${_filename} )
@@ -293,6 +300,10 @@ function( atlas_install_python_modules )
                "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}" )
             set( _bytecodeDir "${_bytecodeDir}/pythonBytecode/${_path}" )
 
+            # Command to create the bytecode directory:
+            add_custom_command( OUTPUT ${_bytecodeDir}
+               COMMAND ${CMAKE_COMMAND} -E make_directory ${_bytecodeDir} )
+
             # Construct the bytecode's file name:
             set( _bytecode "${_bytecodeDir}/${_filename}.pyc" )
 
@@ -315,9 +326,8 @@ function( atlas_install_python_modules )
 
             # Set up a custom command for generating the bytecode:
             add_custom_command( OUTPUT ${_bytecode}
-               COMMAND ${CMAKE_COMMAND} -E make_directory ${_bytecodeDir}
                COMMAND ${PYTHON_EXECUTABLE} ${_pycmdFile}
-               DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${_pyFile}"
+               DEPENDS ${_bytecodeDir} "${CMAKE_CURRENT_SOURCE_DIR}/${_pyFile}"
                VERBATIM )
 
             # Make our installation target call this custom command:
@@ -356,8 +366,8 @@ function( atlas_install_python_modules )
          # Get the file's name, without its (probably) .py extension:
          get_filename_component( _filename "${_file}" NAME_WE )
          # Construct the bytecode's file name:
-         set( _bytecode
-            "${CMAKE_PYTHON_OUTPUT_DIRECTORY}/${pkgName}/${_filename}.pyc" )
+         set( _bytecodeDir "${CMAKE_PYTHON_OUTPUT_DIRECTORY}${CMAKE_FILES_DIRECTORY}" )
+         set( _bytecode    "${_bytecodeDir}/${_filename}.pyc" )
 
          # The python command to execute:
          set( _pycmd "import py_compile; py_compile.compile( " )
@@ -373,12 +383,14 @@ function( atlas_install_python_modules )
          file( GENERATE OUTPUT ${_pycmdFile}
             CONTENT "${_pycmd}" )
 
+         # Command to create the build directory:
+         add_custom_command( OUTPUT ${_bytecodeDir}
+            COMMAND ${CMAKE_COMMAND} -E make_directory ${_bytecodeDir} )
+
          # Set up a custom command for generating the bytecode:
          add_custom_command( OUTPUT ${_bytecode}
-            COMMAND ${CMAKE_COMMAND} -E make_directory
-            ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/${pkgName}
             COMMAND ${PYTHON_EXECUTABLE} ${_pycmdFile}
-            DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${_file}"
+            DEPENDS ${_bytecodeDir} "${CMAKE_CURRENT_SOURCE_DIR}/${_file}"
             VERBATIM )
 
          # Make our installation target call this custom command:
@@ -395,6 +407,7 @@ function( atlas_install_python_modules )
 
          # Clean up:
          unset( _filename )
+         unset( _bytecodeDir )
          unset( _bytecode )
          unset( _pycmd )
          unset( _bytecodeFname )
-- 
GitLab


From 6981676e02bf6d12af472e4ea9cfaf265389d412 Mon Sep 17 00:00:00 2001
From: Frank Winklmeier <frank.winklmeier@cern.ch>
Date: Wed, 29 May 2019 10:42:05 +0200
Subject: [PATCH 2/2] Fix setting of _byteCodeDir

Correct copy&paste mistake when setting _byteCodeDir for individual
python files.
---
 Build/AtlasCMake/modules/AtlasInstallFunctions.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Build/AtlasCMake/modules/AtlasInstallFunctions.cmake b/Build/AtlasCMake/modules/AtlasInstallFunctions.cmake
index 642ec2aa..002ce68f 100644
--- a/Build/AtlasCMake/modules/AtlasInstallFunctions.cmake
+++ b/Build/AtlasCMake/modules/AtlasInstallFunctions.cmake
@@ -366,7 +366,7 @@ function( atlas_install_python_modules )
          # Get the file's name, without its (probably) .py extension:
          get_filename_component( _filename "${_file}" NAME_WE )
          # Construct the bytecode's file name:
-         set( _bytecodeDir "${CMAKE_PYTHON_OUTPUT_DIRECTORY}${CMAKE_FILES_DIRECTORY}" )
+         set( _bytecodeDir "${CMAKE_PYTHON_OUTPUT_DIRECTORY}/${pkgName}" )
          set( _bytecode    "${_bytecodeDir}/${_filename}.pyc" )
 
          # The python command to execute:
-- 
GitLab