157e22627SCy Schubertif(UNIX)
257e22627SCy Schubert  check_function_exists(crypt HAVE_CRYPT_IN_SYSTEM_LIBRARIES)
357e22627SCy Schubert  if(HAVE_CRYPT_IN_SYSTEM_LIBRARIES)
457e22627SCy Schubert    set(HAVE_CRYPT TRUE)
557e22627SCy Schubert  else(HAVE_CRYPT_IN_SYSTEM_LIBRARIES)
657e22627SCy Schubert    check_library_exists(crypt crypt "" HAVE_CRYPT_IN_LIBCRYPT)
757e22627SCy Schubert    if(HAVE_CRYPT_IN_LIBCRYPT)
857e22627SCy Schubert      set(RPCAPD_LINK_LIBRARIES ${RPCAPD_LINK_LIBRARIES} crypt)
957e22627SCy Schubert      set(HAVE_CRYPT TRUE)
1057e22627SCy Schubert    else(HAVE_CRYPT_IN_LIBCRYPT)
1157e22627SCy Schubert      message(WARNING "crypt() not found. Won't be able to build rpcapd.")
1257e22627SCy Schubert    endif(HAVE_CRYPT_IN_LIBCRYPT)
1357e22627SCy Schubert  endif(HAVE_CRYPT_IN_SYSTEM_LIBRARIES)
1457e22627SCy Schubertendif(UNIX)
1557e22627SCy Schubert
1657e22627SCy Schubert#
1757e22627SCy Schubert# On UN*X, we need pthreads and crypt().
1857e22627SCy Schubert#
1957e22627SCy Schubertif(WIN32 OR ((CMAKE_USE_PTHREADS_INIT OR PTHREADS_FOUND) AND HAVE_CRYPT))
2057e22627SCy Schubert  if(UNIX)
2157e22627SCy Schubert    #
2257e22627SCy Schubert    # Do we have getspnam()?
2357e22627SCy Schubert    #
2457e22627SCy Schubert    check_function_exists(getspnam HAVE_GETSPNAM)
2557e22627SCy Schubert
2657e22627SCy Schubert    #
2757e22627SCy Schubert    # Find library needed for getaddrinfo.
2857e22627SCy Schubert    # NOTE: if you hand check_library_exists as its last argument a variable
2957e22627SCy Schubert    # that's been set, it skips the test, so we need different variables.
3057e22627SCy Schubert    #
3157e22627SCy Schubert    include(CheckLibraryExists)
3257e22627SCy Schubert    check_function_exists(getaddrinfo STDLIBS_HAVE_GETADDRINFO)
3357e22627SCy Schubert    if(NOT STDLIBS_HAVE_GETADDRINFO)
3457e22627SCy Schubert      check_library_exists(xnet getaddrinfo "" LIBXNET_HAS_GETADDRINFO)
3557e22627SCy Schubert      if(LIBXNET_HAS_GETADDRINFO)
3657e22627SCy Schubert        set(RPCAPD_LINK_LIBRARIES ${RPCAPD_LINK_LIBRARIES} xnet)
3757e22627SCy Schubert      else(LIBXNET_HAS_GETADDRINFO)
3857e22627SCy Schubert        include(CMakePushCheckState)
3957e22627SCy Schubert        cmake_push_check_state()
4057e22627SCy Schubert        set(CMAKE_REQUIRED_LIBRARIES nsl)
4157e22627SCy Schubert        check_library_exists(socket getaddrinfo "" LIBSOCKET_HAS_GETADDRINFO)
4257e22627SCy Schubert        cmake_pop_check_state()
4357e22627SCy Schubert        if(LIBSOCKET_HAS_GETADDRINFO)
4457e22627SCy Schubert          set(RPCAPD_LINK_LIBRARIES ${RPCAPD_LINK_LIBRARIES} socket nsl)
4557e22627SCy Schubert        endif(LIBSOCKET_HAS_GETADDRINFO)
4657e22627SCy Schubert      endif(LIBXNET_HAS_GETADDRINFO)
4757e22627SCy Schubert    endif(NOT STDLIBS_HAVE_GETADDRINFO)
4857e22627SCy Schubert  endif(UNIX)
4957e22627SCy Schubert
5057e22627SCy Schubert  if(WIN32)
5157e22627SCy Schubert    set(RPCAPD_EXTRA_SOURCES
5257e22627SCy Schubert        win32-svc.c
53*6f9cba8fSJoseph Mingrone        ${pcap_SOURCE_DIR}/charconv.c
5457e22627SCy Schubert        ${pcap_SOURCE_DIR}/missing/getopt.c
5557e22627SCy Schubert        rpcapd.rc)
5657e22627SCy Schubert    include_directories(${pcap_SOURCE_DIR}/rpcapd ${pcap_SOURCE_DIR}/missing)
5757e22627SCy Schubert  endif(WIN32)
5857e22627SCy Schubert
5957e22627SCy Schubert  add_executable(rpcapd
6057e22627SCy Schubert    daemon.c
6157e22627SCy Schubert    fileconf.c
6257e22627SCy Schubert    log.c
6357e22627SCy Schubert    rpcapd.c
6457e22627SCy Schubert    ${pcap_SOURCE_DIR}/rpcap-protocol.c
6557e22627SCy Schubert    ${pcap_SOURCE_DIR}/sockutils.c
66*6f9cba8fSJoseph Mingrone    ${pcap_SOURCE_DIR}/sslutils.c
6757e22627SCy Schubert    ${pcap_SOURCE_DIR}/fmtutils.c
6857e22627SCy Schubert    ${RPCAPD_EXTRA_SOURCES}
6957e22627SCy Schubert  )
7057e22627SCy Schubert
7157e22627SCy Schubert  if(NOT C_ADDITIONAL_FLAGS STREQUAL "")
7257e22627SCy Schubert    set_target_properties(rpcapd PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS})
7357e22627SCy Schubert  endif()
7457e22627SCy Schubert
75*6f9cba8fSJoseph Mingrone  if(NOT "${SANITIZER_FLAGS}" STREQUAL "")
76*6f9cba8fSJoseph Mingrone    set_target_properties(rpcapd PROPERTIES
77*6f9cba8fSJoseph Mingrone        LINK_FLAGS "${SANITIZER_FLAGS}")
78*6f9cba8fSJoseph Mingrone  endif()
79*6f9cba8fSJoseph Mingrone
8057e22627SCy Schubert  #
8157e22627SCy Schubert  # By default, build rpcapd universal with the appropriate set of
8257e22627SCy Schubert  # architectures for the OS on which we're doing the build.
8357e22627SCy Schubert  #
8457e22627SCy Schubert  if(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
8557e22627SCy Schubert    #
8657e22627SCy Schubert    # Get the major version of Darwin.
8757e22627SCy Schubert    #
8857e22627SCy Schubert    string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MAJOR "${CMAKE_SYSTEM_VERSION}")
8957e22627SCy Schubert
9057e22627SCy Schubert    if(SYSTEM_VERSION_MAJOR EQUAL 9)
9157e22627SCy Schubert      #
9257e22627SCy Schubert      # Leopard.  Build for 32-bit x86 and 32-bit PowerPC, with
9357e22627SCy Schubert      # 32-bit x86 first.
9457e22627SCy Schubert      #
9557e22627SCy Schubert      set(OSX_PROGRAM_ARCHITECTURES "i386;ppc")
9657e22627SCy Schubert    elseif(SYSTEM_VERSION_MAJOR EQUAL 10)
9757e22627SCy Schubert      #
9857e22627SCy Schubert      # Snow Leopard.  Build for x86-64 and 32-bit x86, with
9957e22627SCy Schubert      # x86-64 first.
10057e22627SCy Schubert      #
10157e22627SCy Schubert      set(OSX_PROGRAM_ARCHITECTURES "x86_64;i386")
10257e22627SCy Schubert    else()
10357e22627SCy Schubert      #
10457e22627SCy Schubert      # Post-Snow Leopard.  Build only for x86-64.
10557e22627SCy Schubert      # XXX - update if and when Apple adds ARM-based Macs.
10657e22627SCy Schubert      # (You're on your own for iOS etc.)
10757e22627SCy Schubert      #
10857e22627SCy Schubert      set(OSX_PROGRAM_ARCHITECTURES "x86_64")
10957e22627SCy Schubert    endif()
11057e22627SCy Schubert
11157e22627SCy Schubert    set_target_properties(rpcapd PROPERTIES
11257e22627SCy Schubert      OSX_ARCHITECTURES "${OSX_PROGRAM_ARCHITECTURES}")
11357e22627SCy Schubert  endif()
11457e22627SCy Schubert
11557e22627SCy Schubert  if(WIN32)
11657e22627SCy Schubert    target_link_libraries(rpcapd ${LIBRARY_NAME}
11757e22627SCy Schubert      ${RPCAPD_LINK_LIBRARIES} ${PCAP_LINK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
11857e22627SCy Schubert  else(WIN32)
11957e22627SCy Schubert    target_link_libraries(rpcapd ${LIBRARY_NAME}_static
12057e22627SCy Schubert      ${RPCAPD_LINK_LIBRARIES} ${PCAP_LINK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
12157e22627SCy Schubert  endif(WIN32)
12257e22627SCy Schubert
12357e22627SCy Schubert  ######################################
12457e22627SCy Schubert  # Install rpcap daemon and man pages
12557e22627SCy Schubert  ######################################
12657e22627SCy Schubert
12757e22627SCy Schubert  #
12857e22627SCy Schubert  # "Define GNU standard installation directories", which actually
12957e22627SCy Schubert  # are also defined, to some degree, by autotools, and at least
13057e22627SCy Schubert  # some of which are general UN*X conventions.
13157e22627SCy Schubert  #
13257e22627SCy Schubert  include(GNUInstallDirs)
13357e22627SCy Schubert
13457e22627SCy Schubert  set(MANADMIN_EXPAND rpcapd.manadmin.in)
13557e22627SCy Schubert
13657e22627SCy Schubert  set(MANFILE_EXPAND rpcapd-config.manfile.in)
13757e22627SCy Schubert
138*6f9cba8fSJoseph Mingrone  if(WIN32)
139*6f9cba8fSJoseph Mingrone    #
140*6f9cba8fSJoseph Mingrone    # XXX - where should the install target put rpcapd on Windows?
141*6f9cba8fSJoseph Mingrone    #
142*6f9cba8fSJoseph Mingrone    # Note that if an installer package is being produced
143*6f9cba8fSJoseph Mingrone    # from the results of the build, the installer package
144*6f9cba8fSJoseph Mingrone    # will determine where it goes.
145*6f9cba8fSJoseph Mingrone    #
146*6f9cba8fSJoseph Mingrone    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
14757e22627SCy Schubert      install(TARGETS rpcapd DESTINATION bin/amd64)
148*6f9cba8fSJoseph Mingrone    else(CMAKE_SIZEOF_VOID_P EQUAL 8)
14957e22627SCy Schubert      install(TARGETS rpcapd DESTINATION bin)
150*6f9cba8fSJoseph Mingrone    endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
151*6f9cba8fSJoseph Mingrone  else(WIN32)
152*6f9cba8fSJoseph Mingrone    #
153*6f9cba8fSJoseph Mingrone    # On UN*X, we put it in the sbin directory.
154*6f9cba8fSJoseph Mingrone    #
155*6f9cba8fSJoseph Mingrone    # XXX - the Linux Filesystem Hierarchy Standard says /usr/sbin
156*6f9cba8fSJoseph Mingrone    # is for daemons, but some other systems use /usr/libexec instead.
157*6f9cba8fSJoseph Mingrone    # However, since some users might, instead of having rpcapd be
158*6f9cba8fSJoseph Mingrone    # launched by inetd/xinetd/launchd/systemd, just run it on a
159*6f9cba8fSJoseph Mingrone    # machine when remote capture is to be done, a case can be made
160*6f9cba8fSJoseph Mingrone    # for the sbin directory even on systems with /usr/libexec.
161*6f9cba8fSJoseph Mingrone    #
162*6f9cba8fSJoseph Mingrone    install(TARGETS rpcapd DESTINATION ${CMAKE_INSTALL_SBINDIR})
163*6f9cba8fSJoseph Mingrone  endif(WIN32)
16457e22627SCy Schubert
16557e22627SCy Schubert  # On UN*X, and on Windows when not using MSVC, generate process man
16657e22627SCy Schubert  # pages and arrange that they be installed.
16757e22627SCy Schubert  if(NOT MSVC)
16857e22627SCy Schubert    #
16957e22627SCy Schubert    # Man pages.
17057e22627SCy Schubert    #
17157e22627SCy Schubert    # For each section of the manual for which we have man pages
17257e22627SCy Schubert    # that require macro expansion, do the expansion.
17357e22627SCy Schubert    #
17457e22627SCy Schubert    set(MANADMIN "")
17557e22627SCy Schubert    foreach(TEMPLATE_MANPAGE ${MANADMIN_EXPAND})
17657e22627SCy Schubert        string(REPLACE ".manadmin.in" ".${MAN_ADMIN_COMMANDS}" MANPAGE ${TEMPLATE_MANPAGE})
17757e22627SCy Schubert        configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
17857e22627SCy Schubert        set(MANADMIN ${MANADMIN} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
17957e22627SCy Schubert    endforeach(TEMPLATE_MANPAGE)
18057e22627SCy Schubert    install(FILES ${MANADMIN} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_ADMIN_COMMANDS})
18157e22627SCy Schubert
18257e22627SCy Schubert    set(MANFILE "")
18357e22627SCy Schubert    foreach(TEMPLATE_MANPAGE ${MANFILE_EXPAND})
18457e22627SCy Schubert        string(REPLACE ".manfile.in" ".${MAN_FILE_FORMATS}" MANPAGE ${TEMPLATE_MANPAGE})
18557e22627SCy Schubert        configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
18657e22627SCy Schubert        set(MANFILE ${MANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
18757e22627SCy Schubert    endforeach(TEMPLATE_MANPAGE)
18857e22627SCy Schubert    install(FILES ${MANFILE} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_FILE_FORMATS})
18957e22627SCy Schubert  endif(NOT MSVC)
19057e22627SCy Schubertendif(WIN32 OR ((CMAKE_USE_PTHREADS_INIT OR PTHREADS_FOUND) AND HAVE_CRYPT))
191