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}/charconv.c 54 ${pcap_SOURCE_DIR}/missing/getopt.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}/sslutils.c 67 ${pcap_SOURCE_DIR}/fmtutils.c 68 ${RPCAPD_EXTRA_SOURCES} 69 ) 70 71 if(NOT C_ADDITIONAL_FLAGS STREQUAL "") 72 set_target_properties(rpcapd PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS}) 73 endif() 74 75 if(NOT "${SANITIZER_FLAGS}" STREQUAL "") 76 set_target_properties(rpcapd PROPERTIES 77 LINK_FLAGS "${SANITIZER_FLAGS}") 78 endif() 79 80 # 81 # By default, build rpcapd universal with the appropriate set of 82 # architectures for the OS on which we're doing the build. 83 # 84 if(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "") 85 # 86 # Get the major version of Darwin. 87 # 88 string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MAJOR "${CMAKE_SYSTEM_VERSION}") 89 90 if(SYSTEM_VERSION_MAJOR EQUAL 9) 91 # 92 # Leopard. Build for 32-bit x86 and 32-bit PowerPC, with 93 # 32-bit x86 first. 94 # 95 set(OSX_PROGRAM_ARCHITECTURES "i386;ppc") 96 elseif(SYSTEM_VERSION_MAJOR EQUAL 10) 97 # 98 # Snow Leopard. Build for x86-64 and 32-bit x86, with 99 # x86-64 first. 100 # 101 set(OSX_PROGRAM_ARCHITECTURES "x86_64;i386") 102 else() 103 # 104 # Post-Snow Leopard. Build only for x86-64. 105 # XXX - update if and when Apple adds ARM-based Macs. 106 # (You're on your own for iOS etc.) 107 # 108 set(OSX_PROGRAM_ARCHITECTURES "x86_64") 109 endif() 110 111 set_target_properties(rpcapd PROPERTIES 112 OSX_ARCHITECTURES "${OSX_PROGRAM_ARCHITECTURES}") 113 endif() 114 115 if(WIN32) 116 target_link_libraries(rpcapd ${LIBRARY_NAME} 117 ${RPCAPD_LINK_LIBRARIES} ${PCAP_LINK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) 118 else(WIN32) 119 target_link_libraries(rpcapd ${LIBRARY_NAME}_static 120 ${RPCAPD_LINK_LIBRARIES} ${PCAP_LINK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) 121 endif(WIN32) 122 123 ###################################### 124 # Install rpcap daemon and man pages 125 ###################################### 126 127 # 128 # "Define GNU standard installation directories", which actually 129 # are also defined, to some degree, by autotools, and at least 130 # some of which are general UN*X conventions. 131 # 132 include(GNUInstallDirs) 133 134 set(MANADMIN_EXPAND rpcapd.manadmin.in) 135 136 set(MANFILE_EXPAND rpcapd-config.manfile.in) 137 138 if(WIN32) 139 # 140 # XXX - where should the install target put rpcapd on Windows? 141 # 142 # Note that if an installer package is being produced 143 # from the results of the build, the installer package 144 # will determine where it goes. 145 # 146 if(CMAKE_SIZEOF_VOID_P EQUAL 8) 147 install(TARGETS rpcapd DESTINATION bin/amd64) 148 else(CMAKE_SIZEOF_VOID_P EQUAL 8) 149 install(TARGETS rpcapd DESTINATION bin) 150 endif(CMAKE_SIZEOF_VOID_P EQUAL 8) 151 else(WIN32) 152 # 153 # On UN*X, we put it in the sbin directory. 154 # 155 # XXX - the Linux Filesystem Hierarchy Standard says /usr/sbin 156 # is for daemons, but some other systems use /usr/libexec instead. 157 # However, since some users might, instead of having rpcapd be 158 # launched by inetd/xinetd/launchd/systemd, just run it on a 159 # machine when remote capture is to be done, a case can be made 160 # for the sbin directory even on systems with /usr/libexec. 161 # 162 install(TARGETS rpcapd DESTINATION ${CMAKE_INSTALL_SBINDIR}) 163 endif(WIN32) 164 165 # On UN*X, and on Windows when not using MSVC, generate process man 166 # pages and arrange that they be installed. 167 if(NOT MSVC) 168 # 169 # Man pages. 170 # 171 # For each section of the manual for which we have man pages 172 # that require macro expansion, do the expansion. 173 # 174 set(MANADMIN "") 175 foreach(TEMPLATE_MANPAGE ${MANADMIN_EXPAND}) 176 string(REPLACE ".manadmin.in" ".${MAN_ADMIN_COMMANDS}" MANPAGE ${TEMPLATE_MANPAGE}) 177 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY) 178 set(MANADMIN ${MANADMIN} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE}) 179 endforeach(TEMPLATE_MANPAGE) 180 install(FILES ${MANADMIN} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_ADMIN_COMMANDS}) 181 182 set(MANFILE "") 183 foreach(TEMPLATE_MANPAGE ${MANFILE_EXPAND}) 184 string(REPLACE ".manfile.in" ".${MAN_FILE_FORMATS}" MANPAGE ${TEMPLATE_MANPAGE}) 185 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY) 186 set(MANFILE ${MANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE}) 187 endforeach(TEMPLATE_MANPAGE) 188 install(FILES ${MANFILE} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_FILE_FORMATS}) 189 endif(NOT MSVC) 190endif(WIN32 OR ((CMAKE_USE_PTHREADS_INIT OR PTHREADS_FOUND) AND HAVE_CRYPT)) 191