summarylogtreecommitdiffstats
path: root/541.patch
blob: fc7327a2f8873c8c2a3fb8231c8fb95baf2bca23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
From 8c6406b01cf0c9e144466651c9fe7d833a2c5ca4 Mon Sep 17 00:00:00 2001
From: Nehal J Wani <nehaljw.kkd1@gmail.com>
Date: Sat, 29 Aug 2020 13:37:21 -0400
Subject: [PATCH] Partially rework cmake modules to accommodate library types

This patch allows selectively linking each third party library
statically with a fallback to dynamic, if not available
---
 c++/src/CMakeLists.txt                  |  17 ++--
 c++/test/CMakeLists.txt                 |  16 ++--
 cmake_modules/FindGTest.cmake           |  37 ++++++--
 cmake_modules/FindLZ4.cmake             |  21 +++--
 cmake_modules/FindProtobuf.cmake        |  27 ++++--
 cmake_modules/FindSnappy.cmake          |  21 +++--
 cmake_modules/FindZLIB.cmake            |  20 ++--
 cmake_modules/FindZSTD.cmake            |  24 ++---
 cmake_modules/ThirdpartyToolchain.cmake | 118 +++++++++++++++++-------
 tools/src/CMakeLists.txt                |   3 +-
 tools/test/CMakeLists.txt               |  11 +--
 11 files changed, 200 insertions(+), 115 deletions(-)

diff --git a/c++/src/CMakeLists.txt b/c++/src/CMakeLists.txt
index 7ff543dd78..772f4c6671 100644
--- a/c++/src/CMakeLists.txt
+++ b/c++/src/CMakeLists.txt
@@ -155,7 +155,7 @@ CHECK_CXX_SOURCE_RUNS("
 )
 
 set(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR})
-set(CMAKE_REQUIRED_LIBRARIES zlib)
+set(CMAKE_REQUIRED_LIBRARIES orc_zlib)
 CHECK_CXX_SOURCE_COMPILES("
     #define Z_PREFIX
     #include<zlib.h>
@@ -174,12 +174,7 @@ configure_file (
 include_directories (
   ${CMAKE_CURRENT_SOURCE_DIR}
   ${CMAKE_CURRENT_BINARY_DIR}
-  ${PROTOBUF_INCLUDE_DIR}
-  ${ZLIB_INCLUDE_DIR}
-  ${SNAPPY_INCLUDE_DIR}
-  ${LZ4_INCLUDE_DIR}
   ${LIBHDFSPP_INCLUDE_DIR}
-  ${ZSTD_INCLUDE_DIR}
   )
 
 add_custom_command(OUTPUT orc_proto.pb.h orc_proto.pb.cc
@@ -236,11 +231,11 @@ endif(BUILD_LIBHDFSPP)
 add_library (orc STATIC ${SOURCE_FILES})
 
 target_link_libraries (orc
-  protobuf
-  zlib
-  snappy
-  lz4
-  zstd
+  orc::protobuf
+  orc::zlib
+  orc::snappy
+  orc::lz4
+  orc::zstd
   ${LIBHDFSPP_LIBRARIES}
   )
 
diff --git a/c++/test/CMakeLists.txt b/c++/test/CMakeLists.txt
index ae4b807b16..da5ef577a6 100644
--- a/c++/test/CMakeLists.txt
+++ b/c++/test/CMakeLists.txt
@@ -14,10 +14,6 @@ include_directories(
   ${PROJECT_SOURCE_DIR}/c++/src
   ${PROJECT_BINARY_DIR}/c++/include
   ${PROJECT_BINARY_DIR}/c++/src
-  ${PROTOBUF_INCLUDE_DIR}
-  ${ZLIB_INCLUDE_DIR}
-  ${SNAPPY_INCLUDE_DIR}
-  ${GTEST_INCLUDE_DIR}
 )
 
 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_FLAGS} ${WARN_FLAGS}")
@@ -54,11 +50,11 @@ add_executable (orc-test
 
 target_link_libraries (orc-test
   orc
-  lz4
-  protobuf
-  snappy
-  zlib
-  ${GTEST_LIBRARIES}
+  orc::lz4
+  orc::protobuf
+  orc::snappy
+  orc::zlib
+  orc::gmock
 )
 
 add_executable (create-test-files
@@ -67,7 +63,7 @@ add_executable (create-test-files
 
 target_link_libraries (create-test-files
   orc
-  protobuf
+  orc::protobuf
 )
 
 if (TEST_VALGRIND_MEMCHECK)
diff --git a/cmake_modules/FindGTest.cmake b/cmake_modules/FindGTest.cmake
index 3ae8954324..c1326ea5f0 100644
--- a/cmake_modules/FindGTest.cmake
+++ b/cmake_modules/FindGTest.cmake
@@ -13,8 +13,10 @@
 # GTEST_HOME environmental variable is used to check for GTest headers and static library
 
 # GTEST_INCLUDE_DIR: directory containing headers
-# GTEST_LIBS: directory containing gtest libraries
+# GMOCK_LIBRARY: path to libgmock
+# GTEST_LIBRARY: path to libgtest
 # GMOCK_STATIC_LIB: is set to gmock.a static library
+# GTEST_STATIC_LIB: is set to gtest.a static library
 # GTEST_FOUND is set if GTEST is found
 
 if (NOT "${GTEST_HOME}" STREQUAL "")
@@ -28,24 +30,40 @@ find_path (GTEST_INCLUDE_DIR gmock/gmock.h HINTS
   NO_DEFAULT_PATH
   PATH_SUFFIXES "include")
 
-find_library (GTEST_LIBRARIES NAMES gmock HINTS
+find_library (GMOCK_LIBRARY NAMES gmock HINTS
   ${_gtest_path}
   PATH_SUFFIXES "lib")
 
-if (GTEST_INCLUDE_DIR AND GTEST_LIBRARIES)
+find_library (GTEST_LIBRARY NAMES gtest HINTS
+  ${_gtest_path}
+  PATH_SUFFIXES "lib")
+
+find_library (GMOCK_STATIC_LIB NAMES ${CMAKE_STATIC_LIBRARY_PREFIX}gmock${CMAKE_STATIC_LIBRARY_SUFFIX} HINTS
+  ${_gtest_path}
+  PATH_SUFFIXES "lib")
+
+find_library (GTEST_STATIC_LIB NAMES ${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX} HINTS
+  ${_gtest_path}
+  PATH_SUFFIXES "lib")
+
+if (GTEST_INCLUDE_DIR AND GMOCK_LIBRARY)
   set (GTEST_FOUND TRUE)
-  get_filename_component (GTEST_LIBS ${GTEST_LIBRARIES} PATH )
   set (GTEST_HEADER_NAME gmock/gmock.h)
   set (GTEST_HEADER ${GTEST_INCLUDE_DIR}/${GTEST_HEADER_NAME})
-  set (GTEST_LIB_NAME gmock)
-  set (GMOCK_STATIC_LIB ${GTEST_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}${GTEST_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
 else ()
   set (GTEST_FOUND FALSE)
 endif ()
 
 if (GTEST_FOUND)
   message (STATUS "Found the GTest header: ${GTEST_HEADER}")
-  message (STATUS "Found the GTest library: ${GMOCK_STATIC_LIB}")
+  message (STATUS "Found the GTest library: ${GTEST_LIBRARY}")
+  message (STATUS "Found the GMock library: ${GMOCK_LIBRARY}")
+  if (GTEST_STATIC_LIB)
+    message (STATUS "Found the GTest static library: ${GTEST_STATIC_LIB}")
+  endif ()
+  if (GMOCK_STATIC_LIB)
+    message (STATUS "Found the GMock static library: ${GMOCK_STATIC_LIB}")
+  endif ()
 else ()
   if (_gtest_path)
     set (GTEST_ERR_MSG "Could not find GTest. Looked in ${_gtest_path}.")
@@ -63,6 +81,7 @@ endif ()
 mark_as_advanced (
   GTEST_INCLUDE_DIR
   GMOCK_STATIC_LIB
-  GTEST_LIBS
-  GTEST_LIBRARIES
+  GTEST_STATIC_LIB
+  GMOCK_LIBRARY
+  GTEST_LIBRARY
 )
diff --git a/cmake_modules/FindLZ4.cmake b/cmake_modules/FindLZ4.cmake
index e522a6f76a..f57984940a 100644
--- a/cmake_modules/FindLZ4.cmake
+++ b/cmake_modules/FindLZ4.cmake
@@ -13,7 +13,7 @@
 # LZ4_HOME environment variable is used to check for LZ4 headers and static library
 
 # LZ4_INCLUDE_DIR: directory containing headers
-# LZ4_LIBS: directory containing LZ4 libraries
+# LZ4_LIBRARY: path to liblz4
 # LZ4_STATIC_LIB: path to lz4.a
 # LZ4_FOUND: whether LZ4 has been found
 
@@ -28,24 +28,28 @@ find_path (LZ4_INCLUDE_DIR lz4.h HINTS
   NO_DEFAULT_PATH
   PATH_SUFFIXES "include")
 
-find_library (LZ4_LIBRARIES NAMES lz4 HINTS
+find_library (LZ4_LIBRARY NAMES lz4 HINTS
   ${_lz4_path}
   PATH_SUFFIXES "lib" "lib64")
 
-if (LZ4_INCLUDE_DIR AND LZ4_LIBRARIES)
+find_library (LZ4_STATIC_LIB NAMES ${CMAKE_STATIC_LIBRARY_PREFIX}${LZ4_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX} HINTS
+  ${_lz4_path}
+  PATH_SUFFIXES "lib" "lib64")
+
+if (LZ4_INCLUDE_DIR AND LZ4_LIBRARY)
   set (LZ4_FOUND TRUE)
-  get_filename_component (LZ4_LIBS ${LZ4_LIBRARIES} PATH)
   set (LZ4_HEADER_NAME lz4.h)
   set (LZ4_HEADER ${LZ4_INCLUDE_DIR}/${LZ4_HEADER_NAME})
-  set (LZ4_LIB_NAME lz4)
-  set (LZ4_STATIC_LIB ${LZ4_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}${LZ4_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
 else ()
   set (LZ4_FOUND FALSE)
 endif ()
 
 if (LZ4_FOUND)
   message (STATUS "Found the LZ4 header: ${LZ4_HEADER}")
-  message (STATUS "Found the LZ4 library: ${LZ4_STATIC_LIB}")
+  message (STATUS "Found the LZ4 library: ${LZ4_LIBRARY}")
+  if (LZ4_STATIC_LIB)
+    message (STATUS "Found the LZ4 static library: ${LZ4_STATIC_LIB}")
+  endif ()
 else()
   if (_lz4_path)
     set (LZ4_ERR_MSG "Could not find LZ4. Looked in ${_lz4_path}.")
@@ -63,6 +67,5 @@ endif()
 mark_as_advanced (
   LZ4_INCLUDE_DIR
   LZ4_STATIC_LIB
-  LZ4_LIBS
-  LZ4_LIBRARIES
+  LZ4_LIBRARY
 )
diff --git a/cmake_modules/FindProtobuf.cmake b/cmake_modules/FindProtobuf.cmake
index d901c55a10..f2b6a7ca91 100644
--- a/cmake_modules/FindProtobuf.cmake
+++ b/cmake_modules/FindProtobuf.cmake
@@ -14,8 +14,9 @@
 
 # PROTOBUF_FOUND is set if Protobuf is found
 # PROTOBUF_INCLUDE_DIR: directory containing headers
-# PROTOBUF_LIBS: directory containing Protobuf libraries
+# PROTOBUF_LIBRARY: location of libprotobuf
 # PROTOBUF_STATIC_LIB: location of protobuf.a
+# PROTOC_LIBRARY: location of libprotoc
 # PROTOC_STATIC_LIB: location of protoc.a
 # PROTOBUF_EXECUTABLE: location of protoc
 
@@ -40,10 +41,18 @@ find_library (PROTOBUF_LIBRARY NAMES protobuf HINTS
   ${_protobuf_path}
   PATH_SUFFIXES "lib")
 
+find_library (PROTOBUF_STATIC_LIB NAMES ${CMAKE_STATIC_LIBRARY_PREFIX}protobuf${CMAKE_STATIC_LIBRARY_SUFFIX} HINTS
+  ${_protobuf_path}
+  PATH_SUFFIXES "lib")
+
 find_library (PROTOC_LIBRARY NAMES protoc HINTS
   ${_protobuf_path}
   PATH_SUFFIXES "lib")
 
+find_library (PROTOC_STATIC_LIB NAMES ${CMAKE_STATIC_LIBRARY_PREFIX}protoc${CMAKE_STATIC_LIBRARY_SUFFIX} HINTS
+  ${_protobuf_path}
+  PATH_SUFFIXES "lib")
+
 find_program(PROTOBUF_EXECUTABLE protoc HINTS
   ${_protobuf_path}
   NO_DEFAULT_PATH
@@ -51,20 +60,23 @@ find_program(PROTOBUF_EXECUTABLE protoc HINTS
 
 if (PROTOBUF_INCLUDE_DIR AND PROTOBUF_LIBRARY AND PROTOC_LIBRARY AND PROTOBUF_EXECUTABLE)
   set (PROTOBUF_FOUND TRUE)
-  get_filename_component (PROTOBUF_LIBS ${PROTOBUF_LIBRARY} PATH)
   set (PROTOBUF_LIB_NAME protobuf)
   set (PROTOC_LIB_NAME protoc)
-  set (PROTOBUF_STATIC_LIB ${PROTOBUF_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}${PROTOBUF_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
-  set (PROTOC_STATIC_LIB ${PROTOBUF_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}${PROTOC_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
 else ()
   set (PROTOBUF_FOUND FALSE)
 endif ()
 
 if (PROTOBUF_FOUND)
   message (STATUS "Found the Protobuf headers: ${PROTOBUF_INCLUDE_DIR}")
-  message (STATUS "Found the Protobuf library: ${PROTOBUF_STATIC_LIB}")
-  message (STATUS "Found the Protoc library: ${PROTOC_STATIC_LIB}")
+  message (STATUS "Found the Protobuf library: ${PROTOBUF_LIBRARY}")
+  message (STATUS "Found the Protoc library: ${PROTOC_LIBRARY}")
   message (STATUS "Found the Protoc executable: ${PROTOBUF_EXECUTABLE}")
+  if (PROTOBUF_STATIC_LIB)
+     message (STATUS "Found the Protobuf static library: ${PROTOBUF_STATIC_LIB}")
+  endif ()
+  if (PROTOC_STATIC_LIB)
+     message (STATUS "Found the Protoc static library: ${PROTOC_STATIC_LIB}")
+  endif ()
 else()
   if (_protobuf_path)
     set (PROTOBUF_ERR_MSG "Could not find Protobuf. Looked in ${_protobuf_path}.")
@@ -81,7 +93,8 @@ endif()
 
 mark_as_advanced (
   PROTOBUF_INCLUDE_DIR
-  PROTOBUF_LIBS
+  PROTOBUF_LIBRARY
   PROTOBUF_STATIC_LIB
   PROTOC_STATIC_LIB
+  PROTOC_LIBRARY
 )
diff --git a/cmake_modules/FindSnappy.cmake b/cmake_modules/FindSnappy.cmake
index 5aeb88e78c..a834dd0ddf 100644
--- a/cmake_modules/FindSnappy.cmake
+++ b/cmake_modules/FindSnappy.cmake
@@ -13,7 +13,7 @@
 # SNAPPY_HOME environmental variable is used to check for Snappy headers and static library
 
 # SNAPPY_INCLUDE_DIR: directory containing headers
-# SNAPPY_LIBS: directory containing snappy libraries
+# SNAPPY_LIBRARY: path to libsnappy
 # SNAPPY_STATIC_LIB: path to libsnappy.a
 # SNAPPY_FOUND: whether snappy has been found
 
@@ -28,24 +28,28 @@ find_path (SNAPPY_INCLUDE_DIR snappy.h HINTS
   NO_DEFAULT_PATH
   PATH_SUFFIXES "include")
 
-find_library (SNAPPY_LIBRARIES NAMES snappy HINTS
+find_library (SNAPPY_LIBRARY NAMES snappy HINTS
   ${_snappy_path}
   PATH_SUFFIXES "lib" "lib64")
 
-if (SNAPPY_INCLUDE_DIR AND SNAPPY_LIBRARIES)
+find_library (SNAPPY_STATIC_LIB NAMES ${CMAKE_STATIC_LIBRARY_PREFIX}${SNAPPY_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX} HINTS
+  ${_snappy_path}
+  PATH_SUFFIXES "lib" "lib64")
+
+if (SNAPPY_INCLUDE_DIR AND SNAPPY_LIBRARY)
   set (SNAPPY_FOUND TRUE)
-  get_filename_component (SNAPPY_LIBS ${SNAPPY_LIBRARIES} PATH)
   set (SNAPPY_HEADER_NAME snappy.h)
   set (SNAPPY_HEADER ${SNAPPY_INCLUDE_DIR}/${SNAPPY_HEADER_NAME})
-  set (SNAPPY_LIB_NAME snappy)
-  set (SNAPPY_STATIC_LIB ${SNAPPY_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}${SNAPPY_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
 else ()
   set (SNAPPY_FOUND FALSE)
 endif ()
 
 if (SNAPPY_FOUND)
   message (STATUS "Found the Snappy header: ${SNAPPY_HEADER}")
-  message (STATUS "Found the Snappy library: ${SNAPPY_STATIC_LIB}")
+  message (STATUS "Found the Snappy library: ${SNAPPY_LIBRARY}")
+  if (SNAPPY_STATIC_LIB)
+      message (STATUS "Found the Snappy static library: ${SNAPPY_STATIC_LIB}")
+  endif()
 else()
   if (_snappy_path)
     set (SNAPPY_ERR_MSG "Could not find Snappy. Looked in ${_snappy_path}.")
@@ -63,6 +67,5 @@ endif()
 mark_as_advanced (
   SNAPPY_INCLUDE_DIR
   SNAPPY_STATIC_LIB
-  SNAPPY_LIBS
-  SNAPPY_LIBRARIES
+  SNAPPY_LIBRARY
 )
diff --git a/cmake_modules/FindZLIB.cmake b/cmake_modules/FindZLIB.cmake
index 6c09640e97..968d14821a 100644
--- a/cmake_modules/FindZLIB.cmake
+++ b/cmake_modules/FindZLIB.cmake
@@ -13,7 +13,7 @@
 # ZLIB_HOME environmental variable is used to check for ZLIB headers and static library
 
 # ZLIB_INCLUDE_DIR: directory containing headers
-# ZLIB_LIBS: directory containing ZLIB libraries
+# ZLIB_LIBRARY: path to libz/libzlib
 # ZLIB_STATIC_LIB: path to zlib.a
 # ZLIB_FOUND: whether ZLIB has been found
 
@@ -32,23 +32,28 @@ if (NOT ZLIB_STATIC_LIB_NAME)
   set (ZLIB_STATIC_LIB_NAME z)
 endif()
 
-find_library (ZLIB_LIBRARIES NAMES ${ZLIB_STATIC_LIB_NAME} HINTS
+find_library (ZLIB_LIBRARY NAMES z zlib ${ZLIB_STATIC_LIB_NAME} HINTS
   ${_zlib_path}
   PATH_SUFFIXES "lib")
 
-if (ZLIB_INCLUDE_DIR AND ZLIB_LIBRARIES)
+find_library (ZLIB_STATIC_LIB NAMES ${CMAKE_STATIC_LIBRARY_PREFIX}${ZLIB_STATIC_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX} HINTS
+  ${_zlib_path}
+  PATH_SUFFIXES "lib")
+
+if (ZLIB_INCLUDE_DIR AND ZLIB_LIBRARY)
   set (ZLIB_FOUND TRUE)
-  get_filename_component (ZLIB_LIBS ${ZLIB_LIBRARIES} PATH )
   set (ZLIB_HEADER_NAME zlib.h)
   set (ZLIB_HEADER ${ZLIB_INCLUDE_DIR}/${ZLIB_HEADER_NAME})
-  set (ZLIB_STATIC_LIB ${ZLIB_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}${ZLIB_STATIC_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
 else ()
   set (ZLIB_FOUND FALSE)
 endif ()
 
 if (ZLIB_FOUND)
   message (STATUS "Found the ZLIB header: ${ZLIB_HEADER}")
-  message (STATUS "Found the ZLIB library: ${ZLIB_STATIC_LIB}")
+  message (STATUS "Found the ZLIB library: ${ZLIB_LIBRARY}")
+  if (ZLIB_STATIC_LIB)
+    message (STATUS "Found the ZLIB static library: ${ZLIB_STATIC_LIB}")
+  endif ()
 else()
   if (_zlib_path)
     set (ZLIB_ERR_MSG "Could not find ZLIB. Looked in ${_zlib_path}.")
@@ -66,6 +71,5 @@ endif()
 mark_as_advanced (
   ZLIB_INCLUDE_DIR
   ZLIB_STATIC_LIB
-  ZLIB_LIBS
-  ZLIB_LIBRARIES
+  ZLIB_LIBRARY
 )
diff --git a/cmake_modules/FindZSTD.cmake b/cmake_modules/FindZSTD.cmake
index e0889769b8..02c5889a6c 100644
--- a/cmake_modules/FindZSTD.cmake
+++ b/cmake_modules/FindZSTD.cmake
@@ -13,7 +13,7 @@
 # ZSTD_HOME environmental variable is used to check for Zstd headers and static library
 
 # ZSTD_INCLUDE_DIR: directory containing headers
-# ZSTD_LIBS: directory containing zstd libraries
+# ZSTD_LIBRARY: path to libzstd
 # ZSTD_STATIC_LIB: path to libzstd.a
 # ZSTD_FOUND: whether zstd has been found
 
@@ -23,32 +23,33 @@ endif()
 
 message (STATUS "ZSTD_HOME: ${ZSTD_HOME}")
 
-if (NOT ZSTD_STATIC_LIB_NAME)
-  set (ZSTD_STATIC_LIB_NAME ${CMAKE_STATIC_LIBRARY_PREFIX}zstd)
-endif()
-
 find_path (ZSTD_INCLUDE_DIR zstd.h HINTS
         ${_zstd_path}
         NO_DEFAULT_PATH
         PATH_SUFFIXES "include")
 
-find_library (ZSTD_LIBRARIES NAMES ${ZSTD_STATIC_LIB_NAME} HINTS
+find_library (ZSTD_LIBRARY NAMES zstd HINTS
+        ${_zstd_path}
+        PATH_SUFFIXES "lib")
+
+find_library (ZSTD_STATIC_LIB NAMES ${CMAKE_STATIC_LIBRARY_PREFIX}zstd${CMAKE_STATIC_LIBRARY_SUFFIX} HINTS
         ${_zstd_path}
         PATH_SUFFIXES "lib")
 
-if (ZSTD_INCLUDE_DIR AND ZSTD_LIBRARIES)
+if (ZSTD_INCLUDE_DIR AND ZSTD_LIBRARY)
   set (ZSTD_FOUND TRUE)
-  get_filename_component (ZSTD_LIBS ${ZSTD_LIBRARIES} PATH)
   set (ZSTD_HEADER_NAME zstd.h)
   set (ZSTD_HEADER ${ZSTD_INCLUDE_DIR}/${ZSTD_HEADER_NAME})
-  set (ZSTD_STATIC_LIB ${ZSTD_LIBS}/${ZSTD_STATIC_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
 else ()
   set (ZSTD_FOUND FALSE)
 endif ()
 
 if (ZSTD_FOUND)
   message (STATUS "Found the zstd header: ${ZSTD_HEADER}")
-  message (STATUS "Found the zstd library: ${ZSTD_STATIC_LIB}")
+  message (STATUS "Found the zstd library: ${ZSTD_LIBRARY}")
+  if (ZSTD_STATIC_LIB)
+    message (STATUS "Found the zstd static library: ${ZSTD_STATIC_LIB}")
+  endif ()
 else()
   if (_ZSTD_path)
     set (ZSTD_ERR_MSG "Could not find zstd. Looked in ${_zstd_path}.")
@@ -66,6 +67,5 @@ endif()
 mark_as_advanced (
         ZSTD_INCLUDE_DIR
         ZSTD_STATIC_LIB
-        ZSTD_LIBS
-        ZSTD_LIBRARIES
+        ZSTD_LIBRARY
 )
diff --git a/cmake_modules/ThirdpartyToolchain.cmake b/cmake_modules/ThirdpartyToolchain.cmake
index 3a35325796..f3e1089c5d 100644
--- a/cmake_modules/ThirdpartyToolchain.cmake
+++ b/cmake_modules/ThirdpartyToolchain.cmake
@@ -17,6 +17,13 @@ set(GTEST_VERSION "1.8.0")
 set(PROTOBUF_VERSION "3.5.1")
 set(ZSTD_VERSION "1.4.5")
 
+option(ORC_PREFER_STATIC_PROTOBUF "Prefer static protobuf library, if available" ON)
+option(ORC_PREFER_STATIC_SNAPPY   "Prefer static snappy library, if available"   ON)
+option(ORC_PREFER_STATIC_LZ4      "Prefer static lz4 library, if available"      ON)
+option(ORC_PREFER_STATIC_ZSTD     "Prefer static zstd library, if available"     ON)
+option(ORC_PREFER_STATIC_ZLIB     "Prefer static zlib library, if available"     ON)
+option(ORC_PREFER_STATIC_GMOCK    "Prefer static gmock library, if available"    ON)
+
 # zstd requires us to add the threads
 FIND_PACKAGE(Threads REQUIRED)
 
@@ -75,15 +82,21 @@ else ()
     ${THIRDPARTY_LOG_OPTIONS}
     BUILD_BYPRODUCTS "${SNAPPY_STATIC_LIB}")
 
+  set(SNAPPY_LIBRARY ${SNAPPY_STATIC_LIB})
   set(SNAPPY_VENDORED TRUE)
 endif ()
 
-include_directories (SYSTEM ${SNAPPY_INCLUDE_DIR})
-add_library (snappy STATIC IMPORTED)
-set_target_properties (snappy PROPERTIES IMPORTED_LOCATION ${SNAPPY_STATIC_LIB})
+add_library (orc_snappy INTERFACE)
+add_library (orc::snappy ALIAS orc_snappy)
+if (ORC_PREFER_STATIC_SNAPPY AND ${SNAPPY_STATIC_LIB})
+  target_link_libraries(orc_snappy INTERFACE ${SNAPPY_STATIC_LIB})
+else ()
+  target_link_libraries(orc_snappy INTERFACE ${SNAPPY_LIBRARY})
+endif ()
+target_include_directories (orc_snappy SYSTEM INTERFACE ${SNAPPY_INCLUDE_DIR})
 
 if (SNAPPY_VENDORED)
-  add_dependencies (snappy snappy_ep)
+  add_dependencies (orc_snappy snappy_ep)
   if (INSTALL_VENDORED_LIBS)
     install(FILES "${SNAPPY_STATIC_LIB}"
             DESTINATION "lib")
@@ -117,15 +130,21 @@ else ()
     ${THIRDPARTY_LOG_OPTIONS}
     BUILD_BYPRODUCTS "${ZLIB_STATIC_LIB}")
 
+  set(ZLIB_LIBRARY ${ZLIB_STATIC_LIB})
   set(ZLIB_VENDORED TRUE)
 endif ()
 
-include_directories (SYSTEM ${ZLIB_INCLUDE_DIR})
-add_library (zlib STATIC IMPORTED)
-set_target_properties (zlib PROPERTIES IMPORTED_LOCATION ${ZLIB_STATIC_LIB})
+add_library (orc_zlib INTERFACE)
+add_library (orc::zlib ALIAS orc_zlib)
+if (ORC_PREFER_STATIC_ZLIB AND ${ZLIB_STATIC_LIB})
+  target_link_libraries (orc_zlib INTERFACE ${ZLIB_LIBRARY})
+else ()
+  target_link_libraries (orc_zlib INTERFACE ${ZLIB_STATIC_LIB})
+endif ()
+target_include_directories (orc_zlib SYSTEM INTERFACE ${ZLIB_INCLUDE_DIR})
 
 if (ZLIB_VENDORED)
-  add_dependencies (zlib zlib_ep)
+  add_dependencies (orc_zlib zlib_ep)
   if (INSTALL_VENDORED_LIBS)
     install(FILES "${ZLIB_STATIC_LIB}"
             DESTINATION "lib")
@@ -166,15 +185,21 @@ else ()
           ${THIRDPARTY_LOG_OPTIONS}
           BUILD_BYPRODUCTS ${ZSTD_STATIC_LIB})
 
+  set(ZSTD_LIBRARY ${ZSTD_STATIC_LIB})
   set(ZSTD_VENDORED TRUE)
 endif ()
 
-include_directories (SYSTEM ${ZSTD_INCLUDE_DIR})
-add_library (zstd STATIC IMPORTED)
-set_target_properties (zstd PROPERTIES IMPORTED_LOCATION ${ZSTD_STATIC_LIB})
+add_library (orc_zstd INTERFACE)
+add_library (orc::zstd ALIAS orc_zstd)
+if (ORC_PREFER_STATIC_ZSTD AND ${ZSTD_STATIC_LIB})
+  target_link_libraries (orc_zstd INTERFACE ${ZSTD_STATIC_LIB})
+else ()
+  target_link_libraries (orc_zstd INTERFACE ${ZSTD_LIBRARY})
+endif ()
+target_include_directories (orc_zstd SYSTEM INTERFACE ${ZSTD_INCLUDE_DIR})
 
 if (ZSTD_VENDORED)
-  add_dependencies (zstd zstd_ep)
+  add_dependencies (orc_zstd zstd_ep)
   if (INSTALL_VENDORED_LIBS)
     install(FILES "${ZSTD_STATIC_LIB}"
             DESTINATION "lib")
@@ -208,15 +233,21 @@ else ()
     ${THIRDPARTY_LOG_OPTIONS}
     BUILD_BYPRODUCTS ${LZ4_STATIC_LIB})
 
+  set(LZ4_LIBRARY ${LZ4_STATIC_LIB})
   set(LZ4_VENDORED TRUE)
 endif ()
 
-include_directories (SYSTEM ${LZ4_INCLUDE_DIR})
-add_library (lz4 STATIC IMPORTED)
-set_target_properties (lz4 PROPERTIES IMPORTED_LOCATION ${LZ4_STATIC_LIB})
+add_library (orc_lz4 INTERFACE)
+add_library (orc::lz4 ALIAS orc_lz4)
+if (ORC_PREFER_STATIC_LZ4 AND ${LZ4_STATIC_LIB})
+  target_link_libraries (orc_lz4 INTERFACE ${LZ4_STATIC_LIB})
+else ()
+  target_link_libraries (orc_lz4 INTERFACE ${LZ4_LIBRARY})
+endif ()
+target_include_directories (orc_lz4 SYSTEM INTERFACE ${LZ4_INCLUDE_DIR})
 
 if (LZ4_VENDORED)
-  add_dependencies (lz4 lz4_ep)
+  add_dependencies (orc_lz4 lz4_ep)
   if (INSTALL_VENDORED_LIBS)
     install(FILES "${LZ4_STATIC_LIB}"
             DESTINATION "lib")
@@ -267,21 +298,33 @@ if (BUILD_CPP_TESTS)
       CMAKE_ARGS ${GTEST_CMAKE_ARGS}
       BUILD_BYPRODUCTS "${GMOCK_STATIC_LIB}")
 
+    set(GMOCK_LIBRARY ${GMOCK_STATIC_LIB})
     set(GTEST_VENDORED TRUE)
   endif ()
 
-  include_directories (SYSTEM ${GTEST_INCLUDE_DIR})
-
-  add_library (gmock STATIC IMPORTED)
-  set_target_properties (gmock PROPERTIES IMPORTED_LOCATION ${GMOCK_STATIC_LIB})
+  # This is a bit special cased because gmock requires gtest and some
+  # distributions statically link gtest inside the gmock shared lib
+  add_library (orc_gmock INTERFACE)
+  add_library (orc::gmock ALIAS orc_gmock)
+  if (ORC_PREFER_STATIC_GMOCK AND ${GMOCK_STATIC_LIB})
+    target_link_libraries (orc_gmock INTERFACE ${GMOCK_STATIC_LIB})
+    if (NOT "${GTEST_STATIC_LIB}" STREQUAL "")
+      target_link_libraries (orc_gmock INTERFACE ${GTEST_STATIC_LIB})
+    endif ()
+  else ()
+    target_link_libraries (orc_gmock INTERFACE ${GMOCK_LIBRARY})
+    if (NOT "${GTEST_LIBRARY}" STREQUAL "")
+      target_link_libraries (orc_gmock INTERFACE ${GTEST_LIBRARY})
+    endif ()
+  endif ()
+  target_include_directories (orc_gmock SYSTEM INTERFACE ${GTEST_INCLUDE_DIR})
 
   if (GTEST_VENDORED)
-    add_dependencies (gmock googletest_ep)
+    add_dependencies (orc_gmock googletest_ep)
   endif ()
 
-  set(GTEST_LIBRARIES gmock)
   if (NOT APPLE AND NOT MSVC)
-    list (APPEND GTEST_LIBRARIES pthread)
+    target_link_libraries (orc_gmock INTERFACE Threads::Threads)
   endif ()
 endif ()
 
@@ -322,20 +365,33 @@ else ()
     ${THIRDPARTY_LOG_OPTIONS}
     BUILD_BYPRODUCTS "${PROTOBUF_STATIC_LIB}" "${PROTOC_STATIC_LIB}")
 
+  set(PROTOBUF_LIBRARY ${PROTOBUF_STATIC_LIB})
+  set(PROTOC_LIBRARY ${PROTOC_STATIC_LIB})
   set(PROTOBUF_VENDORED TRUE)
 endif ()
 
-include_directories (SYSTEM ${PROTOBUF_INCLUDE_DIR})
+add_library (orc_protobuf INTERFACE)
+add_library (orc::protobuf ALIAS orc_protobuf)
+add_library (orc_protoc INTERFACE)
+add_library (orc::protoc ALIAS orc_protoc)
 
-add_library (protobuf STATIC IMPORTED)
-set_target_properties (protobuf PROPERTIES IMPORTED_LOCATION ${PROTOBUF_STATIC_LIB})
+if (ORC_PREFER_STATIC_PROTOBUF AND ${PROTOBUF_STATIC_LIB})
+  target_link_libraries (orc_protobuf INTERFACE ${PROTOBUF_STATIC_LIB})
+else ()
+  target_link_libraries (orc_protobuf INTERFACE ${PROTOBUF_LIBRARY})
+endif()
+target_include_directories (orc_protobuf SYSTEM INTERFACE ${PROTOBUF_INCLUDE_DIR})
 
-add_library (protoc STATIC IMPORTED)
-set_target_properties (protoc PROPERTIES IMPORTED_LOCATION ${PROTOC_STATIC_LIB})
+if (ORC_PREFER_STATIC_PROTOBUF AND ${PROTOC_STATIC_LIB})
+  target_link_libraries (orc_protoc INTERFACE ${PROTOC_STATIC_LIB})
+else ()
+  target_link_libraries (orc_protoc INTERFACE ${PROTOC_LIBRARY})
+endif()
+target_include_directories (orc_protoc SYSTEM INTERFACE ${PROTOBUF_INCLUDE_DIR})
 
 if (PROTOBUF_VENDORED)
-  add_dependencies (protoc protobuf_ep)
-  add_dependencies (protobuf protobuf_ep)
+  add_dependencies (orc_protoc protobuf_ep)
+  add_dependencies (orc_protobuf protobuf_ep)
   if (INSTALL_VENDORED_LIBS)
     install(FILES "${PROTOBUF_STATIC_LIB}" "${PROTOC_STATIC_LIB}"
             DESTINATION "lib")
@@ -371,7 +427,7 @@ if(BUILD_LIBHDFSPP)
                                 -DBUILD_SHARED_HDFSPP=FALSE)
 
       ExternalProject_Add (libhdfspp_ep
-        DEPENDS protobuf
+        DEPENDS orc::protobuf
         URL ${LIBHDFSPP_SRC_URL}
         LOG_DOWNLOAD 0
         LOG_CONFIGURE 0
diff --git a/tools/src/CMakeLists.txt b/tools/src/CMakeLists.txt
index f5a53ca838..4b6768c5ec 100644
--- a/tools/src/CMakeLists.txt
+++ b/tools/src/CMakeLists.txt
@@ -22,7 +22,6 @@ include_directories (
   ${PROJECT_BINARY_DIR}/c++/include
   ${PROJECT_SOURCE_DIR}/c++/src
   ${PROJECT_BINARY_DIR}/c++/src
-  ${PROTOBUF_INCLUDE_DIR}
   )
 
 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g ${CXX11_FLAGS} ${WARN_FLAGS}")
@@ -51,7 +50,7 @@ add_executable (orc-metadata
 
 target_link_libraries (orc-metadata
   orc
-  protobuf
+  orc::protobuf
   ${CMAKE_THREAD_LIBS_INIT}
   )
 
diff --git a/tools/test/CMakeLists.txt b/tools/test/CMakeLists.txt
index 505fc8d289..29f54cb11a 100644
--- a/tools/test/CMakeLists.txt
+++ b/tools/test/CMakeLists.txt
@@ -16,9 +16,6 @@ include_directories(
   ${PROJECT_SOURCE_DIR}/tools-c++/src
   ${PROJECT_BINARY_DIR}/c++/include
   ${PROJECT_BINARY_DIR}/c++/src
-  ${PROTOBUF_INCLUDE_DIR}
-  ${ZLIB_INCLUDE_DIR}
-  ${GTEST_INCLUDE_DIR}
 )
 
 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_FLAGS} ${WARN_FLAGS}")
@@ -36,10 +33,10 @@ add_executable (tool-test
 
 target_link_libraries (tool-test
   orc
-  protobuf
-  zlib
-  snappy
-  ${GTEST_LIBRARIES}
+  orc::protobuf
+  orc::zlib
+  orc::snappy
+  orc::gmock
 )
 
 if (TEST_VALGRIND_MEMCHECK)