Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
610 lines (545 sloc) 18.2 KB
################################################################################
# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
# Read the zproject/README.md for information about making permanent changes. #
################################################################################
########################################################################
# Project setup
########################################################################
cmake_minimum_required(VERSION 2.8.8)
project(zyre)
enable_language(C)
enable_testing()
set(SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
# Select flags
SET(CMAKE_C_FLAGS_RELEASE "-O3")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake/Modules)
# Will be used to add flags to pkg-config useful when apps want to statically link
set(pkg_config_libs_private "")
########################################################################
# options
########################################################################
if (NOT CMAKE_BUILD_TYPE)
if (EXISTS "${SOURCE_DIR}/.git")
set (CMAKE_BUILD_TYPE Debug)
else ()
# http://xit0.org/2013/04/cmake-use-git-branch-and-commit-details-in-project/
# http://stackoverflow.com/questions/6797395/cmake-execute-process-always-fails-with-no-such-file-or-directory-when-i-cal
execute_process(
COMMAND git rev-parse --show-toplevel
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE git_result
OUTPUT_VARIABLE git_root
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "git workspace root [${git_result}]: ${git_root}")
if ( "${git_result}" STREQUAL "0" )
set (CMAKE_BUILD_TYPE Debug)
else ()
set (CMAKE_BUILD_TYPE Release)
endif ()
endif ()
endif ()
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
OPTION (ENABLE_DRAFTS "Build and install draft classes and methods" ON)
else ()
OPTION (ENABLE_DRAFTS "Build and install draft classes and methods" OFF)
endif ()
IF (ENABLE_DRAFTS)
ADD_DEFINITIONS (-DZYRE_BUILD_DRAFT_API)
ENDIF (ENABLE_DRAFTS)
########################################################################
# platform.h
########################################################################
include(CheckIncludeFile)
CHECK_INCLUDE_FILE("linux/wireless.h" HAVE_LINUX_WIRELESS_H)
CHECK_INCLUDE_FILE("net/if_media.h" HAVE_NET_IF_MEDIA_H)
include(CheckFunctionExists)
CHECK_FUNCTION_EXISTS("getifaddrs" HAVE_GETIFADDRS)
CHECK_FUNCTION_EXISTS("freeifaddrs" HAVE_FREEIFADDRS)
include(CheckIncludeFiles)
check_include_files("sys/socket.h;net/if.h" HAVE_NET_IF_H)
if (NOT HAVE_NET_IF_H)
CHECK_INCLUDE_FILE("net/if.h" HAVE_NET_IF_H)
endif()
file(WRITE "${SOURCE_DIR}/src/platform.h.in" "
#cmakedefine HAVE_LINUX_WIRELESS_H
#cmakedefine HAVE_NET_IF_H
#cmakedefine HAVE_NET_IF_MEDIA_H
#cmakedefine HAVE_GETIFADDRS
#cmakedefine HAVE_FREEIFADDRS
")
configure_file("${SOURCE_DIR}/src/platform.h.in" "${SOURCE_DIR}/src/platform.h")
#The MSVC C compiler is too out of date,
#so the sources have to be compiled as c++
if (MSVC)
enable_language(CXX)
file(GLOB sources "${SOURCE_DIR}/src/*.c")
set_source_files_properties(
${sources}
PROPERTIES LANGUAGE CXX
)
set(MORE_LIBRARIES ws2_32 Rpcrt4 Iphlpapi)
endif()
# specific case of windows UWP
if( "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore" AND "${CMAKE_SYSTEM_VERSION}" STREQUAL "10.0")
ADD_DEFINITIONS(-DZMQ_HAVE_WINDOWS_UWP)
ADD_DEFINITIONS(-D_WIN32_WINNT=_WIN32_WINNT_WIN10)
endif()
# required libraries for mingw
if (MINGW)
set(MORE_LIBRARIES -lws2_32 -lrpcrt4 -liphlpapi)
endif()
# required libraries for cygwin
if (CYGWIN)
set(MORE_LIBRARIES)
endif()
list(APPEND CMAKE_MODULE_PATH "${SOURCE_DIR}")
set(OPTIONAL_LIBRARIES)
########################################################################
# LIBZMQ dependency
########################################################################
find_package(libzmq REQUIRED)
IF (LIBZMQ_FOUND)
include_directories(${LIBZMQ_INCLUDE_DIRS})
list(APPEND MORE_LIBRARIES ${LIBZMQ_LIBRARIES})
set(pkg_config_libs_private "${pkg_config_libs_private} -lzmq")
ELSE (LIBZMQ_FOUND)
message( FATAL_ERROR "libzmq not found." )
ENDIF (LIBZMQ_FOUND)
########################################################################
# CZMQ dependency
########################################################################
find_package(czmq REQUIRED)
IF (CZMQ_FOUND)
include_directories(${CZMQ_INCLUDE_DIRS})
list(APPEND MORE_LIBRARIES ${CZMQ_LIBRARIES})
set(pkg_config_libs_private "${pkg_config_libs_private} -lczmq")
ELSE (CZMQ_FOUND)
message( FATAL_ERROR "czmq not found." )
ENDIF (CZMQ_FOUND)
########################################################################
# version
########################################################################
set(ZYRE_VERSION_MAJOR 2)
set(ZYRE_VERSION_MINOR 0)
set(ZYRE_VERSION_PATCH 1)
set(ZYRE_VERSION "${ZYRE_VERSION_MAJOR}.${ZYRE_VERSION_MINOR}.${ZYRE_VERSION_PATCH}")
message(STATUS "Detected ZYRE Version - ${ZYRE_VERSION}")
########################################################################
# includes
########################################################################
set (zyre_headers
include/zyre_library.h
include/zyre.h
include/zyre_event.h
src/zre_msg.h
src/zyre_peer.h
src/zyre_group.h
src/zyre_election.h
src/zyre_node.h
)
source_group ("Header Files" FILES ${zyre_headers})
install(FILES ${zyre_headers} DESTINATION include)
########################################################################
# library
########################################################################
include_directories("${SOURCE_DIR}/src" "${SOURCE_DIR}/include")
set (zyre_sources
src/zyre.c
src/zyre_event.c
src/zre_msg.c
src/zyre_peer.c
src/zyre_group.c
src/zyre_election.c
src/zyre_node.c
)
IF (ENABLE_DRAFTS)
list (APPEND zyre_sources
src/zyre_private_selftest.c
)
ENDIF (ENABLE_DRAFTS)
source_group("Source Files" FILES ${zyre_sources})
option(ZYRE_BUILD_SHARED "Whether or not to build the shared object" ON)
option(ZYRE_BUILD_STATIC "Whether or not to build the static archive" ON)
if (NOT ZYRE_BUILD_SHARED AND NOT ZYRE_BUILD_STATIC)
message(FATAL_ERROR "Neither static nor shared library build enabled")
endif()
IF (NOT MSVC)
# avoid building everything twice for shared + static
# only on *nix, as Windows needs different preprocessor defines in static builds
add_library (zyre_objects OBJECT ${zyre_sources})
set_property(TARGET zyre_objects PROPERTY POSITION_INDEPENDENT_CODE ON)
ENDIF (NOT MSVC)
# shared
if (ZYRE_BUILD_SHARED)
IF (MSVC)
add_library(zyre SHARED ${zyre_sources})
ELSE (MSVC)
add_library(zyre SHARED $<TARGET_OBJECTS:zyre_objects>)
ENDIF (MSVC)
set_target_properties (zyre PROPERTIES
PUBLIC_HEADER "${public_headers}"
DEFINE_SYMBOL "ZYRE_EXPORTS"
SOVERSION "2"
VERSION "${ZYRE_VERSION}"
COMPILE_DEFINITIONS "DLL_EXPORT"
OUTPUT_NAME "zyre"
PREFIX "lib"
)
target_link_libraries(zyre
PUBLIC ${MORE_LIBRARIES}
)
install(TARGETS zyre
EXPORT zyre-targets
LIBRARY DESTINATION "lib${LIB_SUFFIX}" # .so file
ARCHIVE DESTINATION "lib${LIB_SUFFIX}" # .lib file
RUNTIME DESTINATION bin # .dll file
)
target_include_directories(zyre
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
endif()
# static
if (ZYRE_BUILD_STATIC)
IF (MSVC)
add_library(zyre-static STATIC ${zyre_sources})
ELSE (MSVC)
add_library(zyre-static STATIC $<TARGET_OBJECTS:zyre_objects>)
ENDIF (MSVC)
set_target_properties(zyre-static PROPERTIES
PUBLIC_HEADER "${public_headers}"
COMPILE_DEFINITIONS "ZYRE_STATIC"
OUTPUT_NAME "zyre"
PREFIX "lib"
)
target_link_libraries(zyre-static
PUBLIC ${MORE_LIBRARIES}
)
install(TARGETS zyre-static
EXPORT zyre-targets
LIBRARY DESTINATION "lib${LIB_SUFFIX}" # .so file
ARCHIVE DESTINATION "lib${LIB_SUFFIX}" # .lib file
RUNTIME DESTINATION bin # .dll file
)
target_include_directories(zyre-static
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_compile_definitions(zyre-static
PUBLIC ZYRE_STATIC
)
endif()
include(${CMAKE_CURRENT_SOURCE_DIR}/src/CMakeLists-local.txt) # Optional project-local hook
########################################################################
# pkgconfig
########################################################################
set (VERSION "2.0.1")
set (prefix "${CMAKE_INSTALL_PREFIX}")
set (exec_prefix "\${prefix}")
set (libdir "\${prefix}/lib${LIB_SUFFIX}")
set (includedir "\${prefix}/include")
IF (ENABLE_DRAFTS)
set (pkg_config_defines "-DZYRE_BUILD_DRAFT_API=1")
ELSE (ENABLE_DRAFTS)
set (pkg_config_defines "")
ENDIF (ENABLE_DRAFTS)
configure_file(
"${SOURCE_DIR}/src/libzyre.pc.in"
"${SOURCE_DIR}/src/libzyre.pc"
@ONLY)
install(
FILES "${SOURCE_DIR}/src/libzyre.pc"
DESTINATION "lib${LIB_SUFFIX}/pkgconfig"
)
########################################################################
# installer
########################################################################
include(CMakePackageConfigHelpers)
if (WIN32)
set(CMAKECONFIG_INSTALL_DIR "CMake" CACHE STRING "install path for zyreConfig.cmake")
else()
# GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share".
set(CMAKECONFIG_INSTALL_DIR "share/cmake/zyre" CACHE STRING "install path for zyreConfig.cmake")
endif()
if (NOT CMAKE_VERSION VERSION_LESS 3.0)
export(EXPORT zyre-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/zyreTargets.cmake")
endif()
configure_package_config_file(builds/cmake/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/zyreConfig.cmake"
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR})
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/zyreConfigVersion.cmake
VERSION ${ZYRE_VERSION}
COMPATIBILITY AnyNewerVersion)
install(EXPORT zyre-targets
FILE zyreTargets.cmake
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/zyreConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/zyreConfigVersion.cmake
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
########################################################################
# executables
########################################################################
add_executable(
perf_local
"${SOURCE_DIR}/src/perf_local.c"
)
if (TARGET zyre)
target_link_libraries(
perf_local
zyre
${LIBZMQ_LIBRARIES}
${CZMQ_LIBRARIES}
${OPTIONAL_LIBRARIES}
)
endif()
if (NOT TARGET zyre AND TARGET zyre-static)
target_link_libraries(
perf_local
zyre-static
${LIBZMQ_LIBRARIES}
${CZMQ_LIBRARIES}
${OPTIONAL_LIBRARIES}
)
endif()
add_executable(
perf_remote
"${SOURCE_DIR}/src/perf_remote.c"
)
if (TARGET zyre)
target_link_libraries(
perf_remote
zyre
${LIBZMQ_LIBRARIES}
${CZMQ_LIBRARIES}
${OPTIONAL_LIBRARIES}
)
endif()
if (NOT TARGET zyre AND TARGET zyre-static)
target_link_libraries(
perf_remote
zyre-static
${LIBZMQ_LIBRARIES}
${CZMQ_LIBRARIES}
${OPTIONAL_LIBRARIES}
)
endif()
add_executable(
zpinger
"${SOURCE_DIR}/src/zpinger.c"
)
if (TARGET zyre)
target_link_libraries(
zpinger
zyre
${LIBZMQ_LIBRARIES}
${CZMQ_LIBRARIES}
${OPTIONAL_LIBRARIES}
)
endif()
if (NOT TARGET zyre AND TARGET zyre-static)
target_link_libraries(
zpinger
zyre-static
${LIBZMQ_LIBRARIES}
${CZMQ_LIBRARIES}
${OPTIONAL_LIBRARIES}
)
endif()
install(TARGETS zpinger
RUNTIME DESTINATION bin
)
add_executable(
ztester_beacon
"${SOURCE_DIR}/src/ztester_beacon.c"
)
if (TARGET zyre)
target_link_libraries(
ztester_beacon
zyre
${LIBZMQ_LIBRARIES}
${CZMQ_LIBRARIES}
${OPTIONAL_LIBRARIES}
)
endif()
if (NOT TARGET zyre AND TARGET zyre-static)
target_link_libraries(
ztester_beacon
zyre-static
${LIBZMQ_LIBRARIES}
${CZMQ_LIBRARIES}
${OPTIONAL_LIBRARIES}
)
endif()
add_executable(
ztester_gossip
"${SOURCE_DIR}/src/ztester_gossip.c"
)
if (TARGET zyre)
target_link_libraries(
ztester_gossip
zyre
${LIBZMQ_LIBRARIES}
${CZMQ_LIBRARIES}
${OPTIONAL_LIBRARIES}
)
endif()
if (NOT TARGET zyre AND TARGET zyre-static)
target_link_libraries(
ztester_gossip
zyre-static
${LIBZMQ_LIBRARIES}
${CZMQ_LIBRARIES}
${OPTIONAL_LIBRARIES}
)
endif()
add_executable(
zyre_selftest
"${SOURCE_DIR}/src/zyre_selftest.c"
)
if (TARGET zyre)
target_link_libraries(
zyre_selftest
zyre
${LIBZMQ_LIBRARIES}
${CZMQ_LIBRARIES}
${OPTIONAL_LIBRARIES}
)
endif()
if (NOT TARGET zyre AND TARGET zyre-static)
target_link_libraries(
zyre_selftest
zyre-static
${LIBZMQ_LIBRARIES}
${CZMQ_LIBRARIES}
${OPTIONAL_LIBRARIES}
)
endif()
########################################################################
# tests
########################################################################
set(CLASSTEST_TIMEOUT 60 CACHE STRING "Timeout of the selftest of a class")
set(TOTAL_TIMEOUT 600 CACHE STRING "Timout of the total testsuite")
if(UNIX)
find_program(MEMORYCHECK_COMMAND valgrind)
set(MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --show-reachable=yes
--error-exitcode=1
--suppressions=src/.valgrind.supp")
endif()
set(TEST_CLASSES
zyre
zyre_event
)
IF (ENABLE_DRAFTS)
list (APPEND TEST_CLASSES
private_classes
)
ENDIF (ENABLE_DRAFTS)
add_custom_target(
copy-selftest-ro ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/src/selftest-ro ${CMAKE_BINARY_DIR}/src/selftest-ro
)
add_custom_target(
make-selftest-rw ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/src/selftest-rw
)
set_directory_properties(
PROPERTIES
ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_BINARY_DIR}/src/selftest-ro;${CMAKE_BINARY_DIR}/src/selftest-rw"
)
foreach(TEST_CLASS ${TEST_CLASSES})
add_test(
NAME ${TEST_CLASS}
COMMAND zyre_selftest --continue --verbose --test ${TEST_CLASS}
)
set_tests_properties(
${TEST_CLASS}
PROPERTIES TIMEOUT ${CLASSTEST_TIMEOUT}
)
set_tests_properties(
${TEST_CLASS}
PROPERTIES DEPENDS "copy-selftest-ro;make-selftest-rw"
)
endforeach(TEST_CLASS)
include(CTest)
########################################################################
# cleanup
########################################################################
add_custom_target (distclean @echo Cleaning for source distribution)
set(cmake_generated ${CMAKE_BINARY_DIR}/CMakeCache.txt
${CMAKE_BINARY_DIR}/cmake_install.cmake
${CMAKE_BINARY_DIR}/Makefile
${CMAKE_BINARY_DIR}/CMakeFiles
${CMAKE_BINARY_DIR}/CTestTestfile.cmake
${CMAKE_BINARY_DIR}/DartConfiguration.tcl
${CMAKE_BINARY_DIR}/Testing
${CMAKE_BINARY_DIR}/compile_commands.json
${CMAKE_BINARY_DIR}/src/platform.h
${CMAKE_BINARY_DIR}/src/libzyre.pc
${CMAKE_BINARY_DIR}/src/libzyre.so
${CMAKE_BINARY_DIR}/src/zyre_selftest
${CMAKE_BINARY_DIR}/src/perf_local
${CMAKE_BINARY_DIR}/src/perf_remote
${CMAKE_BINARY_DIR}/src/zpinger
${CMAKE_BINARY_DIR}/src/ztester_beacon
${CMAKE_BINARY_DIR}/src/ztester_gossip
${CMAKE_BINARY_DIR}/src/zyre_selftest
)
add_custom_command(
DEPENDS clean
COMMENT "distribution clean"
COMMAND rm
ARGS -rf CMakeTmp ${cmake_generated}
TARGET distclean
)
include(ClangFormat OPTIONAL)
########################################################################
# summary
########################################################################
message ("")
message (STATUS "******************* Configuration Summary *******************")
message (STATUS "General:")
message (STATUS " Version : ${VERSION}")
message (STATUS " System : ${CMAKE_SYSTEM_NAME}")
message (STATUS " C compiler : ${CMAKE_C_COMPILER}")
message (STATUS " Debug C flags : ${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_FLAGS}")
message (STATUS " Release C flags : ${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_FLAGS}")
message (STATUS " Build type : ${CMAKE_BUILD_TYPE}")
message (STATUS " Static build : ${ZYRE_BUILD_STATIC}")
message (STATUS " Shared build : ${ZYRE_BUILD_SHARED}")
IF (ENABLE_DRAFTS)
message (STATUS " Draft API : Yes")
ELSE (ENABLE_DRAFTS)
message (STATUS " Draft API : No")
ENDIF (ENABLE_DRAFTS)
message (STATUS "")
message (STATUS "Dependencies:")
include(FeatureSummary)
feature_summary (WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
message (STATUS "")
message (STATUS "Install:")
message (STATUS " Install prefix :" "${CMAKE_INSTALL_PREFIX}")
message (STATUS "")
message (STATUS "************************* Options ***************************")
message (STATUS "Options:")
message (STATUS " Use the Draft API (default = yes):")
message (STATUS " -DENABLE-DRAFTS=[yes|no]")
message (STATUS "")
message (STATUS "*************************************************************")
message (STATUS "Configuration complete! Now procced with:")
message (STATUS " 'make' compile the project")
message (STATUS " 'make test' run the project's selftest")
message (STATUS " 'make install' install the project to ${CMAKE_INSTALL_PREFIX}")
message (STATUS "")
message (STATUS "Further options are:")
message (STATUS " 'ctest -T memcheck' run the project's selftest with")
message (STATUS " valgrind to check for memory leaks")
message (STATUS "")
################################################################################
# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
# Read the zproject/README.md for information about making permanent changes. #
################################################################################