From 55ca9c56549e52bea1a024f7d70b6c81c88edfce Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Fri, 23 Oct 2015 00:33:27 +0200 Subject: [PATCH 1/2] CMake: use libsodium if available, else use tweet_nacl --- CMakeLists.txt | 41 +++++++++++++++++++++++------------------ FindSodium.cmake | 40 ++++++++++++++++++++++++++++++++++++++++ tests/CMakeLists.txt | 3 ++- 3 files changed, 65 insertions(+), 19 deletions(-) create mode 100644 FindSodium.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e5cfa968..2ce69eb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,14 +9,17 @@ if(APPLE) option(ZMQ_BUILD_FRAMEWORK "Build as OS X framework" ON) endif() -if(WIN32) - option(WITH_TWEETNACL "Build with tweetnacl" OFF) -else() - option(WITH_TWEETNACL "Build with tweetnacl" ON) -endif() +list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}") +find_package(Sodium) -if(WITH_TWEETNACL) - add_definitions(-DHAVE_TWEETNACL -DHAVE_LIBSODIUM) +set(USE_TWEETNACL OFF) + +if(SODIUM_FOUND) + add_definitions(-DHAVE_LIBSODIUM) + include_directories(${SODIUM_INCLUDE_DIRS}) +else() + set(USE_TWEETNACL ON) + add_definitions(-DHAVE_TWEETNACL) include_directories( tweetnacl/contrib/randombytes tweetnacl/src @@ -25,16 +28,12 @@ if(WITH_TWEETNACL) set(TWEETNACL_SOURCES tweetnacl/src/tweetnacl.c ) - if(WIN32) - else() + + if(NOT WIN32) list(APPEND TWEETNACL_SOURCES tweetnacl/contrib/randombytes/devurandom.c) endif() -else() - find_library(SODIUM_FOUND sodium) endif() - - set(POLLER "" CACHE STRING "Choose polling system. valid values are kqueue, epoll, devpoll, poll or select [default=autodetect]") @@ -502,9 +501,11 @@ foreach(source ${cxx-sources}) list(APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/src/${source}) endforeach() -foreach(source ${TWEETNACL_SOURCES}) - list(APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/${source}) -endforeach() +if(USE_TWEETNACL) + foreach(source ${TWEETNACL_SOURCES}) + list(APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/${source}) + endforeach() +endif() foreach(source ${rc-sources}) list(APPEND sources ${CMAKE_CURRENT_BINARY_DIR}/${source}) @@ -602,7 +603,7 @@ else() PUBLIC_HEADER "${public_headers}" VERSION ${ZMQ_VERSION} SOVERSION "${ZMQ_VERSION_MAJOR}.${ZMQ_VERSION_MINOR}.0" - OUTPUT_NAME "libzmq") + OUTPUT_NAME "libzmq") if(ZMQ_BUILD_FRAMEWORK) set_target_properties(libzmq PROPERTIES FRAMEWORK TRUE @@ -623,7 +624,11 @@ else() OUTPUT_NAME "libzmq-static") endif() -target_link_libraries(libzmq ${SODIUM_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(libzmq ${CMAKE_THREAD_LIBS_INIT}) + +if(SODIUM_FOUND) + target_link_libraries(libzmq ${SODIUM_LIBRARIES}) +endif() if(HAVE_WS2_32) target_link_libraries(libzmq ws2_32) elseif(HAVE_WS2) diff --git a/FindSodium.cmake b/FindSodium.cmake new file mode 100644 index 00000000..ee1903f9 --- /dev/null +++ b/FindSodium.cmake @@ -0,0 +1,40 @@ +################################################################################ +# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY # +# Please refer to the README for information about making permanent changes. # +################################################################################ + +if (NOT MSVC) +include(FindPkgConfig) +pkg_check_modules(PC_SODIUM "libsodium") +if (NOT PC_SODIUM_FOUND) + pkg_check_modules(PC_SODIUM "sodium") +endif (NOT PC_SODIUM_FOUND) +if (PC_SODIUM_FOUND) + set(SODIUM_INCLUDE_HINTS ${PC_SODIUM_INCLUDE_DIRS} ${PC_SODIUM_INCLUDE_DIRS}/*) + set(SODIUM_LIBRARY_HINTS ${PC_SODIUM_LIBRARY_DIRS} ${PC_SODIUM_LIBRARY_DIRS}/*) +endif() +endif (NOT MSVC) + +# some libraries install the headers is a subdirectory of the include dir +# returned by pkg-config, so use a wildcard match to improve chances of finding +# headers and libraries. +find_path( + SODIUM_INCLUDE_DIRS + NAMES sodium.h + HINTS ${SODIUM_INCLUDE_HINTS} +) + +find_library( + SODIUM_LIBRARIES + NAMES libsodium sodium + HINTS ${SODIUM_LIBRARY_HINTS} +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SODIUM DEFAULT_MSG SODIUM_LIBRARIES SODIUM_INCLUDE_DIRS) +mark_as_advanced(SODIUM_FOUND SODIUM_LIBRARIES SODIUM_INCLUDE_DIRS) + +################################################################################ +# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY # +# Please refer to the README for information about making permanent changes. # +################################################################################ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cae45258..3aec08b7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -50,7 +50,7 @@ set(tests test_pub_invert_matching test_thread_safe test_client_server - test_sockopt_hwm + test_sockopt_hwm test_heartbeats test_poller ) @@ -83,6 +83,7 @@ foreach(test ${tests}) else() add_test(NAME ${test} COMMAND ${test}) endif() + set_tests_properties(${test} PROPERTIES TIMEOUT 10) endforeach() if(NOT WIN32) From 35d723ce5b9c17b60b750f6e8aba5e0bb06474e4 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Fri, 23 Oct 2015 01:32:00 +0200 Subject: [PATCH 2/2] Add Windows Continuous Integration (appveyor) --- appveyor.yml | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..fe4ebfd7 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,66 @@ +version: build-{build} + +clone_depth: 1 + +skip_tags: true + +os: Visual Studio 2015 + +environment: + CMAKE_GENERATOR: "Visual Studio 14 2015" + MSVCVERSION: "v140" + MSVCYEAR: "vs2015" + +matrix: + fast_finish: false + +platform: + - Win32 + - x64 + +configuration: + - Release + - Debug + +init: + #- ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) + - cmake --version + - msbuild /version + - cmd: reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v UserAuthentication /t REG_DWORD /d 0 /f + +install: + - cmd: if "%Platform%"=="x64" set "CMAKE_GENERATOR=%CMAKE_GENERATOR% Win64" + - cmd: echo "Generator='%CMAKE_GENERATOR%'" + - cmd: echo "Platform='%Platform%'" + - cmd: set LIBSODIUMDIR=C:\projects\libsodium + - cmd: git clone --depth 1 --quiet "https://github.com/jedisct1/libsodium.git" %LIBSODIUMDIR% + - cmd: msbuild /v:minimal /maxcpucount:%NUMBER_OF_PROCESSORS% /p:Configuration=%Configuration%DLL %LIBSODIUMDIR%\builds\msvc\%MSVCYEAR%\libsodium\libsodium.vcxproj + - cmd: set SODIUM_LIBRARY_DIR="%LIBSODIUMDIR%\bin\%Platform%\%Configuration%\%MSVCVERSION%\dynamic" + - cmd: set SODIUM_INCLUDE_DIR="%LIBSODIUMDIR%\src\libsodium\include" + - cmd: move "%SODIUM_LIBRARY_DIR%\libsodium.lib" "%SODIUM_LIBRARY_DIR%\sodium.lib" + +clone_folder: C:\projects\libzmq + +before_build: + - cmd: set LIBZMQ_BUILDDIR=C:\projects\build_libzmq + - cmd: md "%LIBZMQ_BUILDDIR%" + - cd "%LIBZMQ_BUILDDIR%" + - cmd: cmake -D CMAKE_INCLUDE_PATH="%SODIUM_INCLUDE_DIR%" -D CMAKE_LIBRARY_PATH="%SODIUM_LIBRARY_DIR%" -D CMAKE_C_FLAGS_RELEASE="/MT" -D CMAKE_C_FLAGS_DEBUG="/MTd" -G "%CMAKE_GENERATOR%" "%APPVEYOR_BUILD_FOLDER%" + + +build: + parallel: true + project: C:\projects\build_libzmq\ZeroMQ.sln + verbosity: minimal + +after_build: + - cmd: cd %LIBZMQ_BUILDDIR%\bin\%Configuration%" + - cmd: copy "%SODIUM_LIBRARY_DIR%\libsodium.dll" . + # Pack the artifacts + - cmd: 7z a -y -bd -mx=9 libzmq.zip *.exe *.dll + - ps: Push-AppveyorArtifact "libzmq.zip" -Filename "libzmq-${env:Platform}-${env:Configuration}.zip" + - cmd: cd "%LIBZMQ_BUILDDIR%" + - cmd: ctest -C "%Configuration%" -V + +test: + none