Hi, I’m fairly new to cmake and using it in the project at work.
It mostly all seems good but whats bugging me is the amount of duplicate data that gets generated in the build folder, it seems for every cpp file a cmake_install.cmake file is created, which all contain the same project-wide parameters, as well as including sub-directory cmake_installs which also ultimately only contain parameters already defined on the higher level.
Is there no way to configure this so these don’t get generated for every file unless the file actually has a unique parameter that’s not yet set?
For example, cmake_install.cmake typically looks like:
# Install script for directory: /some/application/directory
# Set the install prefix
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "/usr/local")
endif()
string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
# Set the install configuration name.
if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
if(BUILD_TYPE)
string(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
else()
set(CMAKE_INSTALL_CONFIG_NAME "Debug")
endif()
message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
endif()
# Set the component getting installed.
if(NOT CMAKE_INSTALL_COMPONENT)
if(COMPONENT)
message(STATUS "Install component: \"${COMPONENT}\"")
set(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
else()
set(CMAKE_INSTALL_COMPONENT)
endif()
endif()
# Install shared libraries without execute permission?
if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
set(CMAKE_INSTALL_SO_NO_EXE "1")
endif()
# Is this installation the result of a crosscompile?
if(NOT DEFINED CMAKE_CROSSCOMPILING)
set(CMAKE_CROSSCOMPILING "TRUE")
endif()
# Set default install directory permissions.
if(NOT DEFINED CMAKE_OBJDUMP)
set(CMAKE_OBJDUMP "/usr/bin/objdump")
endif()
if(NOT CMAKE_INSTALL_LOCAL_ONLY)
# Include the install script for the subdirectory.
include("/some/sub/directory1/cmake_install.cmake")
endif()
if(NOT CMAKE_INSTALL_LOCAL_ONLY)
# Include the install script for the subdirectory.
include("some/sub/directory2/cmake_install.cmake”)
endif()
...
The first 39 lines of this are the same for every file apart from the first line saying which directory its for, then the following lines are for including the ones in subfolders (which in itself looks as though all the if(NOT CMAKE_INSTALL_LOCAL_ONLY) statements could be merged by listing the include directories line by line, if these are truly necessary (which in most cases, seems they aren’t)).
It’s a similar case for the CTestTestfile.cmakes which are generated… most are there only to link other cmake files. Is there any reason CMake must pollute the build folder (and console output via duplicate messages) this way instead of only creating the files where necessary and then just recursively scanning the whole build directory for any generated cmake files on any level?
It seems to also create a extremely large number of empty directories in CMakeFiles folders, which I feel could also be reduced to only generating them where needed.