Skip to content

Commit

Permalink
Merge pull request #191 from DavidVujic/windows_quicker_build
Browse files Browse the repository at this point in the history
Windows: quicker build
  • Loading branch information
DavidVujic authored Jul 25, 2019
2 parents 24fdebf + d5446a3 commit 74d5481
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ For more details please refer to ZooKeeper docs.
# Windows support
Install `CMake` to build a ZooKeeper client on Windows. `Python 2.7.x` is currently required by the tool `node-gyp` to build the ZooKeeper client as a native Node.js Addon.

Also, run `npm install` in a Powershell window as an __Administrator__. For further instructions visit [node-gyp documentation](https://github.com/nodejs/node-gyp/#on-windows).
Also, run `npm install` in a Powershell window. For further instructions visit [node-gyp documentation](https://github.com/nodejs/node-gyp/#on-windows).

Windows support has been enabled mainly for supporting development, not for production.

Expand All @@ -208,6 +208,16 @@ To run full output during the module build one has to use `ZK_INSTALL_VERBOSE` f

`ZK_INSTALL_VERBOSE=1 npm install`

##### For Windows (PowerShell): verbose build #####
```bash
$env:ZK_INSTALL_VERBOSE=1
npm install
```
This PowerShell command will remove the environment variable:
```bash
Remove-Item Env:\ZK_INSTALL_VERBOSE
```

# Implementation Notes

### NOTE on Module Status (DDOPSON-2011-11-30):
Expand Down
68 changes: 68 additions & 0 deletions patches/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
cmake_minimum_required(VERSION 3.6)

project(zookeeper VERSION 3.4.13)
set(email [email protected])
set(description "zookeeper C client")

# general options
include_directories(include tests generated ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
add_compile_options(/W0)
add_definitions(-DUSE_STATIC_LIB)

# CppUnit option
set(DEFAULT_WANT_CPPUNIT OFF)
option(WANT_CPPUNIT "Enables CppUnit and tests" ${DEFAULT_WANT_CPPUNIT})

# The function `to_have(in out)` converts a header name like `arpa/inet.h`
# into an Autotools style preprocessor definition `HAVE_ARPA_INET_H`.
# This is then set or unset in `configure_file()` step.
#
# Note that CMake functions do not have return values; instead an "out"
# variable must be passed, and explicitly set with parent scope.
function(to_have in out)
string(TOUPPER ${in} str)
string(REGEX REPLACE "/|\\." "_" str ${str})
set(${out} "HAVE_${str}" PARENT_SCOPE)
endfunction()

# include file checks
foreach(f generated/zookeeper.jute.h generated/zookeeper.jute.c)
if(EXISTS "${CMAKE_SOURCE_DIR}/${f}")
to_have(${f} name)
set(${name} 1)
else()
message(FATAL_ERROR
"jute files are missing!\n"
"Please run 'ant compile_jute' while in the ZooKeeper top level directory.")
endif()
endforeach()

# configure
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
src/zookeeper.c
src/recordio.c
generated/zookeeper.jute.c
src/zk_log.c
src/zk_hashtable.c)

list(APPEND zookeeper_sources src/st_adaptor.c)

list(APPEND zookeeper_sources src/winport.c)

add_library(zookeeper STATIC ${zookeeper_sources})
target_link_libraries(zookeeper PUBLIC
hashtable
$<$<PLATFORM_ID:Linux>:rt> # clock_gettime
$<$<PLATFORM_ID:Windows>:ws2_32>) # Winsock 2.0

# cli executable
add_executable(cli src/cli.c)
target_link_libraries(cli zookeeper)
4 changes: 4 additions & 0 deletions scripts/prepublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ function applyPatches() {
shell.sed('-i', '#include "zookeeper.h"', '#include "winport.h"\n#include "zookeeper.h"\n', `${destination}/zk_adaptor.h`);
shell.sed('-i', '#include "zk_adaptor.h"', '#include "zk_adaptor.h"\n#include "winport.h"\n', `${destination}/zookeeper.c`);

if (!process.env.ZK_INSTALL_VERBOSE) {
const cmakeFile = 'CMakeLists.txt';
shell.cp(`${env.rootFolder}/patches/${cmakeFile}`, `${env.sourceFolder}/src/c/${cmakeFile}`);
}
return;
}

Expand Down

0 comments on commit 74d5481

Please sign in to comment.