xref: /freebsd/contrib/libpcap/rpcapd/CMakeLists.txt (revision 480093f4440d54b30b3025afeac24b48f2ba7a2e)
1if(UNIX)
2  check_function_exists(crypt HAVE_CRYPT_IN_SYSTEM_LIBRARIES)
3  if(HAVE_CRYPT_IN_SYSTEM_LIBRARIES)
4    set(HAVE_CRYPT TRUE)
5  else(HAVE_CRYPT_IN_SYSTEM_LIBRARIES)
6    check_library_exists(crypt crypt "" HAVE_CRYPT_IN_LIBCRYPT)
7    if(HAVE_CRYPT_IN_LIBCRYPT)
8      set(RPCAPD_LINK_LIBRARIES ${RPCAPD_LINK_LIBRARIES} crypt)
9      set(HAVE_CRYPT TRUE)
10    else(HAVE_CRYPT_IN_LIBCRYPT)
11      message(WARNING "crypt() not found. Won't be able to build rpcapd.")
12    endif(HAVE_CRYPT_IN_LIBCRYPT)
13  endif(HAVE_CRYPT_IN_SYSTEM_LIBRARIES)
14endif(UNIX)
15
16#
17# On UN*X, we need pthreads and crypt().
18#
19if(WIN32 OR ((CMAKE_USE_PTHREADS_INIT OR PTHREADS_FOUND) AND HAVE_CRYPT))
20  if(UNIX)
21    #
22    # Do we have getspnam()?
23    #
24    check_function_exists(getspnam HAVE_GETSPNAM)
25
26    #
27    # Find library needed for getaddrinfo.
28    # NOTE: if you hand check_library_exists as its last argument a variable
29    # that's been set, it skips the test, so we need different variables.
30    #
31    include(CheckLibraryExists)
32    check_function_exists(getaddrinfo STDLIBS_HAVE_GETADDRINFO)
33    if(NOT STDLIBS_HAVE_GETADDRINFO)
34      check_library_exists(xnet getaddrinfo "" LIBXNET_HAS_GETADDRINFO)
35      if(LIBXNET_HAS_GETADDRINFO)
36        set(RPCAPD_LINK_LIBRARIES ${RPCAPD_LINK_LIBRARIES} xnet)
37      else(LIBXNET_HAS_GETADDRINFO)
38        include(CMakePushCheckState)
39        cmake_push_check_state()
40        set(CMAKE_REQUIRED_LIBRARIES nsl)
41        check_library_exists(socket getaddrinfo "" LIBSOCKET_HAS_GETADDRINFO)
42        cmake_pop_check_state()
43        if(LIBSOCKET_HAS_GETADDRINFO)
44          set(RPCAPD_LINK_LIBRARIES ${RPCAPD_LINK_LIBRARIES} socket nsl)
45        endif(LIBSOCKET_HAS_GETADDRINFO)
46      endif(LIBXNET_HAS_GETADDRINFO)
47    endif(NOT STDLIBS_HAVE_GETADDRINFO)
48  endif(UNIX)
49
50  if(WIN32)
51    set(RPCAPD_EXTRA_SOURCES
52        win32-svc.c
53        ${pcap_SOURCE_DIR}/missing/getopt.c
54        ${pcap_SOURCE_DIR}/missing/win_snprintf.c
55        rpcapd.rc)
56    include_directories(${pcap_SOURCE_DIR}/rpcapd ${pcap_SOURCE_DIR}/missing)
57  endif(WIN32)
58
59  add_executable(rpcapd
60    daemon.c
61    fileconf.c
62    log.c
63    rpcapd.c
64    ${pcap_SOURCE_DIR}/rpcap-protocol.c
65    ${pcap_SOURCE_DIR}/sockutils.c
66    ${pcap_SOURCE_DIR}/fmtutils.c
67    ${RPCAPD_EXTRA_SOURCES}
68  )
69
70  if(NOT C_ADDITIONAL_FLAGS STREQUAL "")
71    set_target_properties(rpcapd PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS})
72  endif()
73
74  #
75  # By default, build rpcapd universal with the appropriate set of
76  # architectures for the OS on which we're doing the build.
77  #
78  if(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
79    #
80    # Get the major version of Darwin.
81    #
82    string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MAJOR "${CMAKE_SYSTEM_VERSION}")
83
84    if(SYSTEM_VERSION_MAJOR EQUAL 9)
85      #
86      # Leopard.  Build for 32-bit x86 and 32-bit PowerPC, with
87      # 32-bit x86 first.
88      #
89      set(OSX_PROGRAM_ARCHITECTURES "i386;ppc")
90    elseif(SYSTEM_VERSION_MAJOR EQUAL 10)
91      #
92      # Snow Leopard.  Build for x86-64 and 32-bit x86, with
93      # x86-64 first.
94      #
95      set(OSX_PROGRAM_ARCHITECTURES "x86_64;i386")
96    else()
97      #
98      # Post-Snow Leopard.  Build only for x86-64.
99      # XXX - update if and when Apple adds ARM-based Macs.
100      # (You're on your own for iOS etc.)
101      #
102      set(OSX_PROGRAM_ARCHITECTURES "x86_64")
103    endif()
104
105    set_target_properties(rpcapd PROPERTIES
106      OSX_ARCHITECTURES "${OSX_PROGRAM_ARCHITECTURES}")
107  endif()
108
109  if(WIN32)
110    target_link_libraries(rpcapd ${LIBRARY_NAME}
111      ${RPCAPD_LINK_LIBRARIES} ${PCAP_LINK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
112  else(WIN32)
113    target_link_libraries(rpcapd ${LIBRARY_NAME}_static
114      ${RPCAPD_LINK_LIBRARIES} ${PCAP_LINK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
115  endif(WIN32)
116
117  ######################################
118  # Install rpcap daemon and man pages
119  ######################################
120
121  #
122  # "Define GNU standard installation directories", which actually
123  # are also defined, to some degree, by autotools, and at least
124  # some of which are general UN*X conventions.
125  #
126  include(GNUInstallDirs)
127
128  set(MANADMIN_EXPAND rpcapd.manadmin.in)
129
130  set(MANFILE_EXPAND rpcapd-config.manfile.in)
131
132  if(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
133    install(TARGETS rpcapd DESTINATION bin/amd64)
134  else(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
135    install(TARGETS rpcapd DESTINATION bin)
136  endif(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
137
138  # On UN*X, and on Windows when not using MSVC, generate process man
139  # pages and arrange that they be installed.
140  if(NOT MSVC)
141    #
142    # Man pages.
143    #
144    # For each section of the manual for which we have man pages
145    # that require macro expansion, do the expansion.
146    #
147    set(MANADMIN "")
148    foreach(TEMPLATE_MANPAGE ${MANADMIN_EXPAND})
149        string(REPLACE ".manadmin.in" ".${MAN_ADMIN_COMMANDS}" MANPAGE ${TEMPLATE_MANPAGE})
150        configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
151        set(MANADMIN ${MANADMIN} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
152    endforeach(TEMPLATE_MANPAGE)
153    install(FILES ${MANADMIN} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_ADMIN_COMMANDS})
154
155    set(MANFILE "")
156    foreach(TEMPLATE_MANPAGE ${MANFILE_EXPAND})
157        string(REPLACE ".manfile.in" ".${MAN_FILE_FORMATS}" MANPAGE ${TEMPLATE_MANPAGE})
158        configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
159        set(MANFILE ${MANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
160    endforeach(TEMPLATE_MANPAGE)
161    install(FILES ${MANFILE} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_FILE_FORMATS})
162  endif(NOT MSVC)
163endif(WIN32 OR ((CMAKE_USE_PTHREADS_INIT OR PTHREADS_FOUND) AND HAVE_CRYPT))
164