sakra / cotire

CMake module to speed up builds.
MIT License
1.3k stars 143 forks source link

share precompiled header between targets #72

Open onqtam opened 9 years ago

onqtam commented 9 years ago

I am about to have ~100 small .dll's (with just a few source files or even just one) in which I plan to use the same manually maintained pch. There are hacks (atleast for MSVC) to compile the pch once and with some copying and compiler flags to have all the targets use it - see here.

I was wondering if cotire could abstract this somehow on all platforms/compilers? Has this problem been raised before?

EDIT: I just saw that this is listed as a known issue in README.md...

onqtam commented 9 years ago

Can't somehow precompiled header output directories be the same so intermediate files (and the pch itself) get reused? Something like this:

add_executable(SHARED game game.cpp)
set_target_properties(game PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "pch.h")
cotire(game)

add_library(SHARED dll dll.cpp)
set_target_properties(dll PROPERTIES COTIRE_CXX_PRECOMPILED_HEADER_FROM_TARGET game)
cotire(dll)

Or...

add_executable(SHARED game game.cpp)
set_target_properties(game PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "pch.h")
set_target_properties(game PROPERTIES COTIRE_CXX_PRECOMPILED_HEADER_PATH "some/shared/path")
cotire(game)

add_library(SHARED dll dll.cpp)
set_target_properties(game PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "pch.h")
set_target_properties(game PROPERTIES COTIRE_CXX_PRECOMPILED_HEADER_PATH "some/shared/path")
cotire(dll)

Copying the pch would not be that appropriate if it's a 200mb pch for 100 targets...

jcelerier commented 8 years ago

This would be extremely helpful. I have a 50mb PCH deduplicated 30 times because of this :(

mirkow commented 8 years ago

Would appreciate that too

Ryp commented 8 years ago

I wanted to do this for unit testing to share the boilerplate code between all the tests, this would be super useful considering the large amount of small binaries I have.

sbrodehl commented 6 years ago

Any updates on this? What's the benefit in sharing a generated prefix header, but not using the precompiled header?

jcelerier commented 6 years ago

my life in a nutshell:

ls **/*.pch
 40M    API/OSSIA/cotire/ossia_CXX_prefix.hxx.pch
 58M    base/addons/iscore-addon-pd/cotire/score_addon_pd_CXX_prefix.hxx.pch
 58M    base/addons/iscore-addon-shaders/cotire/score_addon_shader_CXX_prefix.hxx.pch
 58M    base/lib/cotire/score_lib_base_CXX_prefix.hxx.pch
 58M    base/plugins/score-lib-device/cotire/score_lib_device_CXX_prefix.hxx.pch
 58M    base/plugins/score-lib-inspector/cotire/score_lib_inspector_CXX_prefix.hxx.pch
 58M    base/plugins/score-lib-process/cotire/score_lib_process_CXX_prefix.hxx.pch
 58M    base/plugins/score-lib-state/cotire/score_lib_state_CXX_prefix.hxx.pch
 58M    base/plugins/score-plugin-automation/cotire/score_plugin_automation_CXX_prefix.hxx.pch
 58M    base/plugins/score-plugin-curve/cotire/score_plugin_curve_CXX_prefix.hxx.pch
 58M    base/plugins/score-plugin-deviceexplorer/cotire/score_plugin_deviceexplorer_CXX_prefix.hxx.pch
 58M    base/plugins/score-plugin-engine/cotire/score_plugin_engine_CXX_prefix.hxx.pch
 58M    base/plugins/score-plugin-inspector/cotire/score_plugin_inspector_CXX_prefix.hxx.pch
 58M    base/plugins/score-plugin-js/cotire/score_plugin_js_CXX_prefix.hxx.pch
 58M    base/plugins/score-plugin-loop/cotire/score_plugin_loop_CXX_prefix.hxx.pch
 58M    base/plugins/score-plugin-mapping/cotire/score_plugin_mapping_CXX_prefix.hxx.pch
 58M    base/plugins/score-plugin-media/cotire/score_plugin_media_CXX_prefix.hxx.pch
 58M    base/plugins/score-plugin-midi/cotire/score_plugin_midi_CXX_prefix.hxx.pch
 58M    base/plugins/score-plugin-pluginsettings/cotire/score_plugin_pluginsettings_CXX_prefix.hxx.pch
 58M    base/plugins/score-plugin-recording/cotire/score_plugin_recording_CXX_prefix.hxx.pch
 58M    base/plugins/score-plugin-scenario/cotire/score_plugin_scenario_CXX_prefix.hxx.pch
1,2G    total

only because I wanted to separate my software in small plug-ins each with their own cmake target...

onqtam commented 6 years ago

58 MB for each pch?!?! ONLY?! you lucky bastard :D

jcelerier commented 6 years ago

only because I hand-optimized them :p the auto-generated one was north of 130-140mb IIRC and was just making the build slower