cotire icon indicating copy to clipboard operation
cotire copied to clipboard

Target_unity does not depend on target_pch

Open martinhanzik opened this issue 8 years ago • 0 comments

I am having trouble with precompiled headers (either autogenerated or manually provided). The header and a corresponding source file get generated, but since the targets do not depend on each other properly, the precompiled header does not get built, but it is -included for every unity file and gets compiled with each unity file from scratch.

Example setup:

cmake_minimum_required(VERSION 3.8)

set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR})
include(cotire)

project(testproj)

add_executable(${PROJECT_NAME} src/a.cpp src/b.cpp src/c.cpp src/d.cpp src/e.cpp src/f.cpp)

# With or without this line, both are broken
# set_target_properties(${PROJECT_NAME} PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "src/pre.hpp")

cotire(${PROJECT_NAME})

# This line adds the dependency and fixes the build
# add_dependencies(${PROJECT_NAME}_unity ${PROJECT_NAME}_pch)

the src/[a-f].hpp files are empty and cpp files contain a single include of the corresponding header. src/pre.hpp contains includes for all headers.

The following logs show the issue:

Generated but not built:

[ 20%] Generating CXX prefix source cotire/testproj_CXX_prefix.cxx
[ 40%] Generating CXX prefix header cotire/testproj_CXX_prefix.hxx
[ 60%] Generating CXX unity source cotire/testproj_CXX_unity.cxx
Scanning dependencies of target testproj_unity
[ 80%] Building CXX object CMakeFiles/testproj_unity.dir/cotire/testproj_CXX_unity.cxx.o
[100%] Linking CXX executable testproj

Generated and built upfront:

Scanning dependencies of target testproj_pch
[ 14%] Generating CXX unity source cotire/testproj_CXX_unity.cxx
[ 28%] Generating CXX prefix source cotire/testproj_CXX_prefix.cxx
[ 42%] Generating CXX prefix header cotire/testproj_CXX_prefix.hxx
[ 57%] Building CXX precompiled header cotire/testproj_CXX_prefix.hxx.pch
[ 57%] Built target testproj_pch
Scanning dependencies of target testproj_unity
[ 71%] Building CXX object CMakeFiles/testproj_unity.dir/cotire/testproj_CXX_unity.cxx.o
[ 85%] Linking CXX executable testproj

This issue results in a 30% build time slowdown (from 4.5m to roughly 3m) in one of my projects.

martinhanzik avatar Aug 01 '17 15:08 martinhanzik