diff --git a/CMakeLists.txt b/CMakeLists.txt index 717de6e61a4..188f35a9981 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -241,10 +241,9 @@ option(USE_OBSERVERS "Use observers module." OFF) option(USE_OPENCL "Use OpenCL" OFF) option(USE_OPENCV "Use OpenCV" OFF) option(USE_OPENMP "Use OpenMP for parallel code" ON) -option(USE_PRECOMPILED_HEADERS "Use pre-compiled headers to accelerate build. Requires cmake >= 3.16." OFF) -if(USE_PRECOMPILED_HEADERS AND (CMAKE_VERSION VERSION_LESS "3.16")) - message(FATAL_ERROR "Precompiled headers require cmake >= 3.16") -endif() +cmake_dependent_option( + USE_PRECOMPILED_HEADERS "Use pre-compiled headers to accelerate build. Requires cmake >= 3.16." OFF + "CMAKE_VERSION VERSION_LESS \"3.16\"" OFF) option(USE_PROF "Use profiling" OFF) option(USE_QNNPACK "Use QNNPACK (quantized 8-bit operators)" ON) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 66dbec29870..7d8659a8bab 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -30,6 +30,7 @@ - [Use Ninja](#use-ninja) - [Use CCache](#use-ccache) - [Use a faster linker](#use-a-faster-linker) + - [Use pre-compiled headers](#use-pre-compiled-headers) - [C++ frontend development tips](#c-frontend-development-tips) - [GDB integration](#gdb-integration) - [CUDA development tips](#cuda-development-tips) @@ -850,6 +851,27 @@ The easiest way to use `lld` this is download the ln -s /path/to/downloaded/ld.lld /usr/local/bin/ld ``` +#### Use pre-compiled headers + +Sometimes there's no way of getting around rebuilding lots of files, for example +editing `native_functions.yaml` usually means 1000+ files being rebuilt. If +you're using CMake newer than 3.16, you can enable pre-compiled headers by +setting `USE_PRECOMPILED_HEADERS=1` either on first setup, or in the +`CMakeCache.txt` file. + +```sh +USE_PRECOMPILED_HEADERS=1 python setup.py develop +``` + +This adds a build step where the compiler takes `` and essentially +dumps it's internal AST to a file so the compiler can avoid repeating itself for +every `.cpp` file. + +One caveat is that when enabled, this header gets included in every file by default. +Which may change what code is legal, for example: +- internal functions can never alias existing names in `` +- names in `` will work even if you don't explicitly include it. + ### C++ frontend development tips We have very extensive tests in the [test/cpp/api](test/cpp/api) folder. The