CMakeLists.txt 2.05 KB
cmake_minimum_required(VERSION 3.0)
project(zmqrpc)
find_package(Git REQUIRED)
if(CMAKE_TOOLCHAIN_FILE) 
set(TOOLCHAIN "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
else()
set(TOOLCHAIN "")
endif()


project(zmqrpc)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.2)
        message(FATAL_ERROR "GCC version must be at least 7.2!")
    endif()
endif()

add_compile_options(-std=c++17)
add_compile_options(-O4)

include(ExternalProject)

ExternalProject_Add (
      cppzmq		    
      GIT_REPOSITORY https://github.com/zeromq/cppzmq.git
      GIT_TAG v4.3.0
      UPDATE_COMMAND ""
      INSTALL_COMMAND ""
      CONFIGURE_COMMAND ""
      BUILD_COMMAND ""
      CMAKE_ARGS "${TOOLCHAIN}"	
      PREFIX "${CMAKE_CURRENT_BINARY_DIR}/external/cppzmq"	
)


ExternalProject_Add (
      zmq
      BUILD_IN_SOURCE 1	
      URL https://github.com/zeromq/libzmq/releases/download/v4.3.1/zeromq-4.3.1.tar.gz
      UPDATE_COMMAND ""
      PATCH_COMMAND cp  ${CMAKE_CURRENT_SOURCE_DIR}/patches/ip_resolver.cpp  ${CMAKE_CURRENT_BINARY_DIR}/external/libzmq/src/zmq/src/
      INSTALL_COMMAND make install
      CONFIGURE_COMMAND ./configure --without-docs --enable-static --prefix=${CMAKE_CURRENT_BINARY_DIR}/external/libzmq CXX=${CMAKE_CXX_COMPILER} CC=${CMAKE_C_COMPILER} ${CONFIG_HOST}
      PREFIX "${CMAKE_CURRENT_BINARY_DIR}/external/libzmq"
      BUILD_COMMAND make -j8
)


add_library(libzmq STATIC IMPORTED)
set_target_properties(libzmq PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/external/libzmq/lib/libzmq.a)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/variant/include)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/external/libzmq/include)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/external/cppzmq/src/cppzmq)

add_executable(server test/server.cpp)
target_link_libraries(server libzmq pthread rt)
add_dependencies(server zmq cppzmq)

add_executable(client test/client.cpp)
target_link_libraries(client libzmq pthread rt)
add_dependencies(client zmq cppzmq)