diff options
author | Jisi Liu <jisi.liu@gmail.com> | 2015-06-12 15:49:21 -0700 |
---|---|---|
committer | Jisi Liu <jisi.liu@gmail.com> | 2015-06-16 18:27:36 -0700 |
commit | 78d470c7a50d3788bf3f819eba99597aea43674f (patch) | |
tree | f2d0c53ce1a94234cc4994ea319f1560f44b2f96 /cmake | |
parent | 4cbb612299eaf8259db25f5dcda46022fbd1db54 (diff) | |
download | protobuf-78d470c7a50d3788bf3f819eba99597aea43674f.tar.gz protobuf-78d470c7a50d3788bf3f819eba99597aea43674f.tar.bz2 protobuf-78d470c7a50d3788bf3f819eba99597aea43674f.zip |
Make the code independent of config.h
Now the Build tool needs to define -DHAVE_ZLIB and -DHAVE-PTHREAD rather
than providing a config.h
- Make pbconfig.h a manually written file to handle hash conditions
according to platform related macros.
- Remove #include "config.h" from source code.
- Changed the configure.ac and Makefile.am to pass down the macros.
- Change cmake to pass down the the macros.
Change-Id: I537249d5df8fdeba189706aec436d1ab1104a4dc
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/CMakeLists.txt | 14 | ||||
-rw-r--r-- | cmake/config.h.in | 4 | ||||
-rw-r--r-- | cmake/find_hash_map.cmake | 119 | ||||
-rw-r--r-- | cmake/pbconfig.h.in | 9 |
4 files changed, 7 insertions, 139 deletions
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 727864ba..d36292df 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -8,11 +8,11 @@ if (MSVC) option(ZLIB "Build with zlib support" OFF) endif (MSVC) +add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD) + find_package(Threads REQUIRED) if (CMAKE_USE_PTHREADS_INIT) - set(HAVE_PTHREAD 1) -else (CMAKE_USE_PTHREADS_INIT) - set(HAVE_PTHREAD 0) + add_definitions(-DHAVE_PTHREAD) endif (CMAKE_USE_PTHREADS_INIT) if (MSVC) @@ -36,6 +36,10 @@ else (MSVC) endif (ZLIB_FOUND) endif (MSVC) +if (HAVE_ZLIB) + add_definitions(-DHAVE_ZLIB) +endif (HAVE_ZLIB) + if (MSVC) if (BUILD_SHARED_LIBS) add_definitions(-DPROTOBUF_USE_DLLS) @@ -43,10 +47,6 @@ if (MSVC) add_definitions(/wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146 /wd4305) endif (MSVC) -include(find_hash_map.cmake) - -configure_file(config.h.in config.h) -configure_file(pbconfig.h.in google/protobuf/stubs/pbconfig.h) if (MSVC) string(REPLACE "/" "\\" PROTOBUF_SOURCE_WIN32_PATH ${protobuf_SOURCE_DIR}) string(REPLACE "/" "\\" PROTOBUF_BINARY_WIN32_PATH ${protobuf_BINARY_DIR}) diff --git a/cmake/config.h.in b/cmake/config.h.in deleted file mode 100644 index bca1cbba..00000000 --- a/cmake/config.h.in +++ /dev/null @@ -1,4 +0,0 @@ -#define GOOGLE_PROTOBUF_CMAKE_BUILD - -#define HAVE_PTHREAD ${HAVE_PTHREAD} -#define HAVE_ZLIB ${HAVE_ZLIB} diff --git a/cmake/find_hash_map.cmake b/cmake/find_hash_map.cmake deleted file mode 100644 index 22796fb8..00000000 --- a/cmake/find_hash_map.cmake +++ /dev/null @@ -1,119 +0,0 @@ -include(CheckCXXSourceCompiles) - -function(find_hash_map) - set(HAVE_HASH_MAP 1 PARENT_SCOPE) - set(HAVE_HASH_SET 1 PARENT_SCOPE) - # Search for hash_map in the following order: - # 1. <unordered_map> ::std::unordered_map - # 2. <tr1/unordered_map> ::std::tr1::unordered_map - # 3. <hash_map> ::hash_map - # 4. <hash_map> ::stdext::hash_map - # 5. <ext/hash_map> ::std::hash_map - # 6. <ext/hash_map> ::__gnu_cxx::hash_map - check_cxx_source_compiles(" - #include <unordered_map> - int main() { ::std::unordered_map<int, int> v; return v[0]; } - " HAS_STD_UNORDERED_MAP) - if (HAS_STD_UNORDERED_MAP) - set(HASH_NAMESPACE ::std PARENT_SCOPE) - set(HASH_MAP_H <unordered_map> PARENT_SCOPE) - set(HASH_MAP_CLASS unordered_map PARENT_SCOPE) - set(HASH_SET_H <unordered_set> PARENT_SCOPE) - set(HASH_SET_CLASS unordered_set PARENT_SCOPE) - return() - endif (HAS_STD_UNORDERED_MAP) - - check_cxx_source_compiles(" - #include <tr1/unordered_map> - int main() { ::std::tr1::unordered_map<int, int> v; return v[0]; } - " HAS_STD_TR1_UNORDERED_MAP) - if (HAS_STD_TR1_UNORDERED_MAP) - set(HASH_NAMESPACE ::std::tr1 PARENT_SCOPE) - set(HASH_MAP_H <tr1/unordered_map> PARENT_SCOPE) - set(HASH_MAP_CLASS unordered_map PARENT_SCOPE) - set(HASH_SET_H <tr1/unordered_set> PARENT_SCOPE) - set(HASH_SET_CLASS unordered_set PARENT_SCOPE) - return() - endif (HAS_STD_TR1_UNORDERED_MAP) - - check_cxx_source_compiles(" - #include <hash_map> - int main() { ::hash_map<int, int> v; return v[0]; } - " HAS_HASH_MAP) - if (HAS_HASH_MAP) - set(HASH_NAMESPACE :: PARENT_SCOPE) - set(HASH_MAP_H <hash_map> PARENT_SCOPE) - set(HASH_MAP_CLASS hash_map PARENT_SCOPE) - set(HASH_SET_H <hash_set> PARENT_SCOPE) - set(HASH_SET_CLASS hash_set PARENT_SCOPE) - return() - endif (HAS_HASH_MAP) - - check_cxx_source_compiles(" - #include <hash_map> - int main() { ::stdext::hash_map<int, int> v; return v[0]; } - " HAS_STDEXT_HASH_MAP) - if (HAS_STDEXT_HASH_MAP) - set(HASH_NAMESPACE ::stdext PARENT_SCOPE) - set(HASH_MAP_H <hash_map> PARENT_SCOPE) - set(HASH_MAP_CLASS hash_map PARENT_SCOPE) - set(HASH_SET_H <hash_set> PARENT_SCOPE) - set(HASH_SET_CLASS hash_set PARENT_SCOPE) - return() - endif (HAS_STDEXT_HASH_MAP) - - check_cxx_source_compiles(" - #include <ext/hash_map> - int main() { ::std::hash_map<int, int> v; return v[0]; } - " HAS_STD_HASH_MAP) - if (HAS_STD_HASH_MAP) - set(HASH_NAMESPACE ::std PARENT_SCOPE) - set(HASH_MAP_H <ext/hash_map> PARENT_SCOPE) - set(HASH_MAP_CLASS hash_map PARENT_SCOPE) - set(HASH_SET_H <ext/hash_set> PARENT_SCOPE) - set(HASH_SET_CLASS hash_set PARENT_SCOPE) - return() - endif (HAS_STD_HASH_MAP) - - check_cxx_source_compiles(" - #include <ext/hash_map> - int main() { ::__gnu_cxx::hash_map<int, int> v; return v[0]; } - " HAS_GNU_CXX_HASH_MAP) - if (HAS_GNU_CXX_HASH_MAP) - set(HASH_NAMESPACE ::gnu_cxx PARENT_SCOPE) - set(HASH_MAP_H <ext/hash_map> PARENT_SCOPE) - set(HASH_MAP_CLASS hash_map PARENT_SCOPE) - set(HASH_SET_H <ext/hash_set> PARENT_SCOPE) - set(HASH_SET_CLASS hash_set PARENT_SCOPE) - return() - endif (HAS_GNU_CXX_HASH_MAP) - - set(HAVE_HASH_MAP 0 PARENT_SCOPE) - set(HAVE_HASH_SET 0 PARENT_SCOPE) -endfunction() - -function(find_hash_compare) - if (MSVC) - check_cxx_source_compiles(" - #include ${HASH_MAP_H} - int main() { ::std::hash_compare<int> cp; return cp(0); } - " HAS_STD_HASH_COMPARE) - if (HAS_STD_HASH_COMPARE) - set(HASH_COMPARE ::std::hash_compare PARENT_SCOPE) - return() - endif (HAS_STD_HASH_COMPARE) - - check_cxx_source_compiles(" - #include ${HASH_MAP_H} - int main() { ::stdext::hash_compare<int> cp; return cp(0); } - " HAS_STDEXT_HASH_COMPARE) - if (HAS_STDEXT_HASH_COMPARE) - set(HASH_COMPARE ::stdext::hash_compare PARENT_SCOPE) - return() - endif (HAS_STDEXT_HASH_COMPARE) - endif (MSVC) - set(HASH_COMPARE PARENT_SCOPE) -endfunction() - -find_hash_map() -find_hash_compare() diff --git a/cmake/pbconfig.h.in b/cmake/pbconfig.h.in deleted file mode 100644 index fdc59686..00000000 --- a/cmake/pbconfig.h.in +++ /dev/null @@ -1,9 +0,0 @@ -#define GOOGLE_PROTOBUF_HAVE_HASH_MAP ${HAVE_HASH_MAP} -#define GOOGLE_PROTOBUF_HAVE_HASH_SET ${HAVE_HASH_MAP} - -#define GOOGLE_PROTOBUF_HASH_NAMESPACE ${HASH_NAMESPACE} -#define GOOGLE_PROTOBUF_HASH_MAP_H ${HASH_MAP_H} -#define GOOGLE_PROTOBUF_HASH_MAP_CLASS ${HASH_MAP_CLASS} -#define GOOGLE_PROTOBUF_HASH_SET_H ${HASH_SET_H} -#define GOOGLE_PROTOBUF_HASH_SET_CLASS ${HASH_SET_CLASS} -#define GOOGLE_PROTOBUF_HASH_COMPARE ${HASH_COMPARE} |