You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ha...@apache.org on 2017/08/13 05:21:29 UTC

zookeeper git commit: ZOOKEEPER-2859: Fix CMake build on OS X.

Repository: zookeeper
Updated Branches:
  refs/heads/master 0c5b32006 -> 5bcffe9bc


ZOOKEEPER-2859: Fix CMake build on OS X.

The libraries `libm` and `librt` (providing `math.h` and `clock_gettime`
respectively) cannot be linked on OS X. Instead, this functionality is
"free" with `libSystem`.

Note that the `hashtable` library has the dependency on `libm`, not the
`zookeeper` library. This was an error carried over from the Autotools
build.

Also finishes a TODO for `pthread` by importing it using the
`FindThreads` CMake package.

Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>

Reviewers: Michael Han <ha...@apache.org>

Closes #319 from andschwa/macos


Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/5bcffe9b
Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/5bcffe9b
Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/5bcffe9b

Branch: refs/heads/master
Commit: 5bcffe9bc242d825ad97ff4f9d2dea6476983a9a
Parents: 0c5b320
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Sat Aug 12 22:21:25 2017 -0700
Committer: Michael Han <ha...@apache.org>
Committed: Sat Aug 12 22:21:25 2017 -0700

----------------------------------------------------------------------
 src/c/CMakeLists.txt | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zookeeper/blob/5bcffe9b/src/c/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/c/CMakeLists.txt b/src/c/CMakeLists.txt
index 4bdb5e0..ef95a76 100644
--- a/src/c/CMakeLists.txt
+++ b/src/c/CMakeLists.txt
@@ -45,10 +45,11 @@ if(WANT_SYNCAPI)
 endif()
 
 # CppUnit option
-if(WIN32)
-  # The tests do not yet compile on Windows, so we set this to off by default.
+if(WIN32 OR APPLE)
+  # The tests do not yet compile on Windows or macOS,
+  # so we set this to off by default.
   #
-  # Note that CMake can does not have expressions except in conditionals,
+  # Note that CMake does not have expressions except in conditionals,
   # so we're left with this if/else/endif pattern.
   set(DEFAULT_WANT_CPPUNIT OFF)
 else()
@@ -147,6 +148,7 @@ configure_file(cmake_config.h.in ${CMAKE_SOURCE_DIR}/include/config.h)
 # hashtable library
 set(hashtable_sources src/hashtable/hashtable_itr.c src/hashtable/hashtable.c)
 add_library(hashtable STATIC ${hashtable_sources})
+target_link_libraries(hashtable PUBLIC $<$<PLATFORM_ID:Linux>:m>)
 
 # zookeeper library
 set(zookeeper_sources
@@ -168,17 +170,14 @@ if(WIN32)
 endif()
 
 add_library(zookeeper STATIC ${zookeeper_sources})
-target_link_libraries(zookeeper PUBLIC hashtable)
-if(UNIX)
-  target_link_libraries(zookeeper PUBLIC m rt)
-elseif(WIN32)
-  # Link to Winsock 2.0
-  target_link_libraries(zookeeper PUBLIC ws2_32)
-endif()
+target_link_libraries(zookeeper PUBLIC
+  hashtable
+  $<$<PLATFORM_ID:Linux>:rt> # clock_gettime
+  $<$<PLATFORM_ID:Windows>:ws2_32>) # Winsock 2.0
 
 if(WANT_SYNCAPI AND NOT WIN32)
-  # TODO: Use `find_library()` or `FindThreads()` for `pthread`.
-  target_link_libraries(zookeeper PUBLIC pthread)
+  find_package(Threads REQUIRED)
+  target_link_libraries(zookeeper PUBLIC Threads::Threads)
 endif()
 
 # cli executable