[CMake] : Add precompiled header support with FLATBUFFERS_ENABLE_PCH (#5827)

* [CMake] : Add precompiled header support with FLATBUFFERS_ENABLE_PCH

FLATBUFFERS_ENABLE_PCH enable precompile headers support for 'flatbuffers' and 'flatc'. Default if OFF.
You need to set it to ON to make it work. 'cmake -DFLATBUFFERS_ENABLE_PCH=ON ..'
This will only work if CMake version is >= 3.16, because target_precompile_headers is used.
If CMake doesn't have target_precompile_headers, then nothing will happen.
This can speed up compilation time.
Precompiled header file for 'flatbuffers' is 'pch.h'
Precompiled header file for 'flatc' is 'flatc_pch.h'

* Enable FLATBUFFERS_ENABLE_PCH for VC 2017 and VS2019 builds

* [CMake]: Fix error in FLATBUFFERS_ENABLE_PCH description

* Add a function add_pch_to_target to avoid copy and pasting the same code like add_fsanitize_to_target
Move pch.h and flatc_pch.h from include/flatbuffers to include/flatbuffers/pch
Make flatc_pch.h depends on pch.h since it extend it
This commit is contained in:
Olivier Le Doeuff
2020-03-27 16:35:44 +01:00
committed by GitHub
parent e9d4532401
commit d9fecc3327
4 changed files with 102 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
/*
* Copyright 2017 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FLATBUFFERS_FLATC_PCH_H_
#define FLATBUFFERS_FLATC_PCH_H_
// stl
#include <cmath>
#include <sstream>
#include <cassert>
#include <unordered_set>
#include <unordered_map>
#include <iostream>
#include <functional>
#include <set>
#include <iterator>
#include <tuple>
// flatbuffers
#include "flatbuffers/pch/pch.h"
#include "flatbuffers/code_generators.h"
#include "flatbuffers/flatbuffers.h"
#include "flatbuffers/flexbuffers.h"
#include "flatbuffers/idl.h"
#endif // FLATBUFFERS_FLATC_PCH_H_

View File

@@ -0,0 +1,38 @@
/*
* Copyright 2017 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FLATBUFFERS_PCH_H_
#define FLATBUFFERS_PCH_H_
// stl
#include <cstdint>
#include <cstring>
#include <algorithm>
#include <list>
#include <string>
#include <utility>
#include <iomanip>
#include <map>
#include <memory>
#include <limits>
#include <stack>
#include <vector>
#include <type_traits>
// flatbuffers
#include "flatbuffers/util.h"
#endif // FLATBUFFERS_PCH_H_