1111# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212# See the License for the specific language governing permissions and
1313# limitations under the License.
14+ #
1415
1516cmake_minimum_required (VERSION 3.5 )
1617
@@ -31,50 +32,76 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
3132# and turn warnings into errors to stop the build if any warning is
3233# emitted ...
3334include (CheckCXXCompilerFlag )
34- CHECK_CXX_COMPILER_FLAG (-Werror COMPILER_SUPPORTS_WERROR )
35- if (COMPILER_SUPPORTS_WERROR)
36- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS } -Werror" )
37- endif ()
38- CHECK_CXX_COMPILER_FLAG (-Wall COMPILER_SUPPORTS_WALL )
39- if (COMPILER_SUPPORTS_WALL)
40- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS } -Wall" )
41- endif ()
42- CHECK_CXX_COMPILER_FLAG (/WX COMPILER_SUPPORTS_WX )
43- if (COMPILER_SUPPORTS_WX)
44- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS } /WX" )
45- endif ()
46- CHECK_CXX_COMPILER_FLAG (/W4 COMPILER_SUPPORTS_SWALL )
47- if (COMPILER_SUPPORTS_SWALL)
48- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS } /Wall" )
35+
36+ if (NOT MSVC )
37+ CHECK_CXX_COMPILER_FLAG (-Werror COMPILER_SUPPORTS_WERROR )
38+ if (COMPILER_SUPPORTS_WERROR)
39+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS } -Werror" )
40+ endif ()
41+ CHECK_CXX_COMPILER_FLAG (-Wall COMPILER_SUPPORTS_WALL )
42+ if (COMPILER_SUPPORTS_WALL)
43+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS } -Wall" )
44+ endif ()
4945endif ()
5046
5147# ... include the functions to compile proto files ...
5248include (FindProtobuf )
5349
54- # ... find the grpc and grpc++ libraries using pkg-config ...
55- include (FindPkgConfig )
56- pkg_check_modules (GRPCPP REQUIRED grpc++>=1.4.1 )
57- pkg_check_modules (GRPC REQUIRED grpc>=4.0 )
58- pkg_check_modules (PROTOBUF REQUIRED protobuf>=3.0 )
59- link_directories (${GRPCPP_LIBRARY_DIRS} ${GRPC_LIBRARY_DIRS} ${PROTOBUF_LIBRARY_DIRS} )
60- include_directories (${GRPCPP_INCLUDE_DIRS} ${GRPC_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS} )
61-
62- # ... define where the googleapis protos can be found, and add that
63- # directory to the search path for header files ...
64- # Typically you can generate these using:
65- # $ make -C googleapis OUTPUT=$PWD/googleapis-gens
66- set (GOOGLEAPIS_PATH "${CMAKE_SOURCE_DIR } /googleapis" )
67- set (GOOGLEAPIS_GENS_PATH "${GOOGLEAPIS_PATH} -gens" )
68- include_directories ("${GOOGLEAPIS_GENS_PATH} " )
50+ # ... find the grpc and grpc++ libraries ...
51+ if (WIN32 )
52+ # ... use find_package and vcpkg on Windows ...
53+ find_package (GRPC REQUIRED grpc>=1.4 )
54+ find_package (PROTOBUF REQUIRED protobuf>=3.0 )
55+ link_directories (${GRPC_LIBRARY_DIRS} ${PROTOBUF_LIBRARY_DIRS} )
56+ include_directories (${GRPC_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS} )
57+ set (GRPC_LIBRARIES gRPC::grpc++ gRPC::grpc)
58+ set (PROTOBUF_LIBRARIES protobuf::libprotobuf)
59+ # Use the same settings that gRPC uses...
60+ add_definitions (-D_WIN32_WINNT=0x600 -D_SCL_SECURE_NO_WARNINGS )
61+ add_definitions (-D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS )
62+ if (MSVC )
63+ add_definitions (/wd4065 /wd4506 /wd4267 /wd4800 /wd4291 /wd4838 )
64+ if (VCPKG_TARGET_TRIPLET MATCHES "-static$" )
65+ set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE } /MT" )
66+ set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG } /MTd" )
67+ endif ()
68+ endif ()
69+ else ()
70+ # ... use pkg-config on Linux and Mac OSX ...
71+ include (FindPkgConfig )
72+ pkg_check_modules (GRPCPP REQUIRED grpc++>=1.4.1 )
73+ pkg_check_modules (GRPC REQUIRED grpc>=4.0 )
74+ pkg_check_modules (PROTOBUF REQUIRED protobuf>=3.0 )
75+ link_directories (${GRPCPP_LIBRARY_DIRS} ${GRPC_LIBRARY_DIRS} ${PROTOBUF_LIBRARY_DIRS} )
76+ include_directories (${GRPCPP_INCLUDE_DIRS} ${GRPC_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS} )
77+ endif ()
78+
79+ include (cmake/CompileProtos.cmake )
80+
81+ set (PROTOBUF_IMPORT_DIRS "${PROJECT_SOURCE_DIR } /googleapis" )
82+ PROTOBUF_GENERATE_CPP (PROTO_SOURCES PROTO_HDRS
83+ ${PROJECT_SOURCE_DIR } /googleapis/google/bigtable/admin/v2/bigtable_instance_admin.proto
84+ ${PROJECT_SOURCE_DIR } /googleapis/google/bigtable/admin/v2/bigtable_table_admin.proto
85+ ${PROJECT_SOURCE_DIR } /googleapis/google/bigtable/admin/v2/common.proto
86+ ${PROJECT_SOURCE_DIR } /googleapis/google/bigtable/admin/v2/instance.proto
87+ ${PROJECT_SOURCE_DIR } /googleapis/google/bigtable/admin/v2/table.proto
88+ ${PROJECT_SOURCE_DIR } /googleapis/google/longrunning/operations.proto
89+ ${PROJECT_SOURCE_DIR } /googleapis/google/rpc/status.proto
90+ ${PROJECT_SOURCE_DIR } /googleapis/google/api/annotations.proto
91+ ${PROJECT_SOURCE_DIR } /googleapis/google/api/auth.proto
92+ ${PROJECT_SOURCE_DIR } /googleapis/google/api/http.proto )
93+ GRPC_GENERATE_CPP (GRPCPP_SOURCES GRPCPP_HDRS
94+ ${PROJECT_SOURCE_DIR } /googleapis/google/bigtable/admin/v2/bigtable_instance_admin.proto
95+ ${PROJECT_SOURCE_DIR } /googleapis/google/bigtable/admin/v2/bigtable_table_admin.proto
96+ ${PROJECT_SOURCE_DIR } /googleapis/google/longrunning/operations.proto )
97+ include_directories ("${PROJECT_SOURCE_DIR } " "${PROJECT_BINARY_DIR } " )
6998
7099################################################################
71100# Create targets here ...
72101
73102# ... discover all the generated Google API files and turn them into a
74103# static library ...
75- file (GLOB_RECURSE GOOGLEAPIS_SRCS ${GOOGLEAPIS_GENS_PATH} /*.pb.cc )
76- file (GLOB_RECURSE GOOGLEAPIS_HDRS ${GOOGLEAPIS_GENS_PATH} /*.pb.h )
77- add_library (googleapis ${GOOGLEAPIS_SRCS} ${GOOGLEAPIS_HDRS} )
104+ add_library (googleapis ${PROTO_SOURCES} ${PROTO_HDRS} ${GRPCPP_SOURCES} ${GRPCPP_HDRS} )
78105
79106add_executable (list_instances list_instances.cc )
80107target_link_libraries (list_instances googleapis ${GRPCPP_LIBRARIES} ${GRPC_LIBRARIES} ${PROTOBUF_LIBRARIES} )
@@ -84,3 +111,12 @@ target_link_libraries(create_instance googleapis ${GRPCPP_LIBRARIES} ${GRPC_LIBR
84111
85112add_executable (delete_instance delete_instance.cc )
86113target_link_libraries (delete_instance googleapis ${GRPCPP_LIBRARIES} ${GRPC_LIBRARIES} ${PROTOBUF_LIBRARIES} )
114+
115+ add_executable (create_table create_table.cc )
116+ target_link_libraries (create_table googleapis ${GRPCPP_LIBRARIES} ${GRPC_LIBRARIES} ${PROTOBUF_LIBRARIES} )
117+
118+ add_executable (delete_table delete_table.cc )
119+ target_link_libraries (delete_table googleapis ${GRPCPP_LIBRARIES} ${GRPC_LIBRARIES} ${PROTOBUF_LIBRARIES} )
120+
121+ add_executable (list_tables list_tables.cc )
122+ target_link_libraries (list_tables googleapis ${GRPCPP_LIBRARIES} ${GRPC_LIBRARIES} ${PROTOBUF_LIBRARIES} )
0 commit comments