From c084742b80d6514b39824617a41eb16910c53cf4 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 24 Sep 2018 14:59:31 -0700 Subject: fixes #735 Configuring ZeroTier for a unified build is too hard This changes the code to make use of a different project we have created (libzerotiercore) that is "CMake clean". This should make using and configuring this code *much* better. It may also have the benefit of making this configuration work better for Windows systems. --- CMakeLists.txt | 1 + docs/BUILD_ZEROTIER.adoc | 68 ++++++++++++++++------------------- src/transport/zerotier/CMakeLists.txt | 46 +++++++++--------------- src/transport/zerotier/zerotier.c | 2 +- 4 files changed, 49 insertions(+), 68 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3042be38..52421a0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -236,6 +236,7 @@ mark_as_advanced(NNG_TRANSPORT_WSS) option (NNG_TRANSPORT_ZEROTIER "Enable ZeroTier transport (requires libzerotiercore)." OFF) if (NNG_TRANSPORT_ZEROTIER) + find_package(zerotiercore REQUIRED) add_definitions (-DNNG_TRANSPORT_ZEROTIER) endif () mark_as_advanced(NNG_TRANSPORT_ZEROTIER) diff --git a/docs/BUILD_ZEROTIER.adoc b/docs/BUILD_ZEROTIER.adoc index a61d065c..80ee0722 100644 --- a/docs/BUILD_ZEROTIER.adoc +++ b/docs/BUILD_ZEROTIER.adoc @@ -5,48 +5,41 @@ endif::[] = Building for ZeroTier Support If you want to include support for the experimental ZeroTier -transport (zt:// URLs), you should follow these directions. +transport (`zt://` URLs), you should follow these directions. -You will need a checked out copy of the ZeroTierOne repository. -The repo is located at github.com/ZeroTier/ZeroTierOne. -These instructions have been tested with version 1.2.10 (tag) -of that repository. +Staysail has created a package that builds a clean CMake project +that you can import. +Download this from https://github.com/staysail/libzerotiercore[GitHub]. -IMPORTANT: ZeroTier is licensed under different terms than NNG. -You are responsible for reading those license terms, and ensuring -that your use conforms to them. -IMPORTANT: The ZeroTier transport, and these build instructions, are -experimental. We expect both to change over time as ZeroTier -and the NNG zt:// transport both mature. As always, _caveat emptor_. +IMPORTANT: ZeroTierOne is licensed under different terms than NNG. +You are responsible for reading those license terms, and ensuring that +your use conforms to them. -== Building libzerotiercore.a +IMPORTANT: The ZeroTier transport, and these build instructions, +are experimental. +We expect both to change over time as ZeroTier and the NNG `zt://` transport +both mature. +As always, _caveat emptor_. -The ZeroTierOne repo is not set up for building this library by default, -so you'll need to explicitly build it. +== Building libzerotiercore -=== Using "make" -If you have a "make" based system such as Linux or macOS, you can -just do "make core" at the top-level. The end result will be a -libzerotiercore.a in that top level. - -=== Using "cmake" - -If not, you can use the CMakeLists file at the top of the ZeroTierOne tree. -That CMakeLists file only generates one output, the libzerotiercore.a -library, which will normally be a static delivery. - -Using your usual cmake tool chain, build the library. -The resulting library (usually `libzerotier.a`) will need to be copied -into the top-level of the ZeroTierOne tree, as that is where the NNG -build expects to find it. +Using "CMake", you can build libzerotiercore +using any normal CMake generator. +You should install it as well. +Normally it will install into `/usr/local` on +Linux and UNIX systems. == Configuring NNG with ZT -You will need to enable ZeroTier within NNG using the CMake option -`NNG_TRANSPORT_ZEROTIER=ON` and set the CMake option -`NNG_TRANSPORT_ZEROTIER_SOURCE` to the directory path of the ZeroTierOne -tree you have checked out. +You will need to enable ZeroTier within NNG using the CMake option `NNG_TRANSPORT_ZEROTIER=ON`. +If you have installed the libzerotiercore in +one of the default locations, then that should be all +that is needed. + +If you have specified a different location, you will +need to inform CMake of this by setting the CMake +variable `-Dzerotier_DIR=` == Example @@ -56,23 +49,24 @@ that we have checked out github source trees into `$HOME/work`. [source, sh] ---- $ export NNGDIR=$HOME/work/nng -$ export ZTDIR=$HOME/work/ZeroTierOne +$ export ZTDIR=$HOME/work/libzerotiercore +$ git clone https://github.com/staysail/libzerotiercore $ZTDIR $ cd $ZTDIR $ mkdir build $ cd build +$ cmake .. ... (lots of lines of output from cmake...) -$ cmake .. $ make ... (lots of lines of output from make...) -$ cp libzerotiercore.a $ZTDIR +$ make install $ cd $NNGDIR $ mkdir build $ cd build -$ cmake -DNNG_TRANSPORT_ZEROTIER=ON -DNNG_TRANSPORT_ZEROTIER_SOURCE=${ZTDIR} .. +$ cmake -DNNG_TRANSPORT_ZEROTIER=ON .. ... (lots of lines of output from cmake...) diff --git a/src/transport/zerotier/CMakeLists.txt b/src/transport/zerotier/CMakeLists.txt index 8ca78f0f..d8dbb566 100644 --- a/src/transport/zerotier/CMakeLists.txt +++ b/src/transport/zerotier/CMakeLists.txt @@ -10,43 +10,29 @@ # ZeroTier protocol -set (NNG_TRANSPORT_ZEROTIER_SOURCE "" CACHE PATH "Location of ZeroTier source tree.") -mark_as_advanced(NNG_TRANSPORT_ZEROTIER_SOURCE) - if (NNG_TRANSPORT_ZEROTIER) - # We use the libzerotiercore.a library, which is unfortunately a C++ object - # even though it exposes only public C symbols. It would be extremely - # helpful if libzerotiercore didn't make us carry the whole C++ runtime - # behind us. The user must specify the location of the ZeroTier source - # tree (dev branch for now, and already compiled please) by setting the - # NNG_ZEROTIER_SOURCE macro. - # NB: This needs to be the zerotierone tree, not the libzt library. - # This is because we don't access the API, but instead use the low - # level zerotiercore functionality directly. + # The zerotiercore project will have been found at the top level + # of the package. This is necessary because import libraries cannot + # percolate back to the parent tree. + # NB: As we wind up linking libzerotiercore.a into the application, # this means that your application will *also* need to either be licensed # under the GPLv3, or you will need to have a commercial license from # ZeroTier permitting its use elsewhere. - - enable_language(CXX) - find_library(NNG_LIBZTCORE zerotiercore PATHS ${NNG_TRANSPORT_ZEROTIER_SOURCE}) - if (NNG_LIBZTCORE) - set(CMAKE_REQUIRED_INCLUDES ${NNG_TRANSPORT_ZEROTIER_SOURCE}/include) - message(STATUS "C++ ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES}") - set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${NNG_LIBZTCORE} ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES}) - set(NNG_REQUIRED_LIBRARIES ${NNG_REQUIRED_LIBRARIES} ${NNG_LIBZTCORE} ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES} PARENT_SCOPE) - set(NNG_REQUIRED_INCLUDES ${NNG_REQUIRED_INCLUDES} ${NNG_TRANSPORT_ZEROTIER_SOURCE}/include PARENT_SCOPE) - nng_check_sym(ZT_Node_join ZeroTierOne.h HAVE_ZTCORE) - endif() - if (NOT HAVE_ZTCORE) - message (FATAL_ERROR "Cannot find ZeroTier components") - endif() - message(STATUS "Found ZeroTier at ${NNG_LIBZTCORE}") + + message(WARNING " + ************************************************************ + Linking against zerotiercore changes license terms (GPLv3). + Consult a lawyer and the license files for details. + ************************************************************") + + set(NNG_REQUIRED_LIBRARIES ${NNG_REQUIRED_LIBRARIES} zerotiercore::zerotiercore) + set(NNG_REQUIRED_LIBRARIES ${NNG_REQUIRED_LIBRARIES} PARENT_SCOPE) set(ZT_SOURCES transport/zerotier/zerotier.c transport/zerotier/zerotier.h) set(ZT_HEADERS transport/zerotier/zerotier.h) -endif() -set(NNG_SOURCES ${NNG_SOURCES} ${ZT_SOURCES} PARENT_SCOPE) -set(NNG_HEADERS ${NNG_HEADERS} ${ZT_HEADERS} PARENT_SCOPE) + set(NNG_SOURCES ${NNG_SOURCES} ${ZT_SOURCES} PARENT_SCOPE) + set(NNG_HEADERS ${NNG_HEADERS} ${ZT_HEADERS} PARENT_SCOPE) +endif() diff --git a/src/transport/zerotier/zerotier.c b/src/transport/zerotier/zerotier.c index 1fc128b7..0cd83ee7 100644 --- a/src/transport/zerotier/zerotier.c +++ b/src/transport/zerotier/zerotier.c @@ -16,7 +16,7 @@ #include "core/nng_impl.h" #include "zerotier.h" -#include +#include // ZeroTier Transport. This sits on the ZeroTier L2 network, which itself // is implemented on top of UDP. This requires the 3rd party -- cgit v1.2.3-70-g09d2