Beginnings of enabling static builds. Still to do:
[obnox/wireshark/wip.git] / CMakeLists.txt
index 12d49724569ad4eebfbbd90846546fb50fc56a48..8e5848f59eb291f475672712939e73a38a8e3f32 100644 (file)
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #
 
-project(wireshark C)
+project(Wireshark C)
 
 cmake_minimum_required(VERSION 2.6)
 
 #Where to find local cmake scripts
 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
 INCLUDE(UseLemon)
+INCLUDE(UseMakeDissectorReg)
+INCLUDE(UseMakeTapReg)
 
 # Under linux the release mode (CMAKE_BUILD_TYPE=release) defines NDEBUG
 
 # Disable this later. Alternative: "make VERBOSE=1"
 set(CMAKE_VERBOSE_MAKEFILE ON)
 
-set(BUILD_SHARED_LIBS ON)
-
 #Defines CMAKE_INSTALL_BINDIR, CMAKE_INSTALL_DATADIR, etc ...
 include(CMakeInstallDirs)
 
 include_directories(
        ${CMAKE_BINARY_DIR}
-
        ${CMAKE_SOURCE_DIR}
        ${CMAKE_SOURCE_DIR}/epan
        ${CMAKE_SOURCE_DIR}/tools/lemon
@@ -50,7 +49,7 @@ include_directories(
 
 #Where to put libraries
 if(NOT LIBRARY_OUTPUT_PATH)
-       set(LIBRARY_OUTPUT_PATH ${wireshark_BINARY_DIR}/lib CACHE INTERNAL
+       set(LIBRARY_OUTPUT_PATH ${Wireshark_BINARY_DIR}/lib CACHE INTERNAL
                   "Single output directory for building all libraries.")
 endif()
 
@@ -64,19 +63,21 @@ option(BUILD_editcap     "Build editcap" ON)
 option(BUILD_capinfos    "Build capinfos" ON)
 option(BUILD_randpkt     "Build randpkt" ON)
 option(BUILD_dftest      "Build dftest" ON)
+option(AUTOGEN_dcerpc    "Autogenerate dcerpc dissectors" OFF)
+option(AUTOGEN_pidl      "Autogenerate pidl dissectors" OFF)
 
 option(DISABLE_WERROR   "Do not treat Warnings as errors" OFF)
-option(ENABLE_EXTRA_GCC_CHECKS "Do additional -W checks in GCC (disables -Werror)" ON)
+option(ENABLE_EXTRA_GCC_CHECKS "Do additional -W checks in GCC (disables -Werror)" OFF)
 option(ENABLE_AIRPCAP   "Enable Airpcap support" ON)
-# todo
-option(ENABLE_STATIC     "Build a static version of Wireshark" OFF)
+option(ENABLE_STATIC     "Build a static version of Wireshark (not yet working)" OFF)
 option(ENABLE_PLUGINS    "Build with plugins" ON)
+# todo
+option(ENABLE_GUIDES     "Build Guides (not yet implemented)" OFF)
 
 option(ENABLE_ADNS       "Build with adns support" ON)
 option(ENABLE_PCRE       "Build with pcre support" ON)
 option(ENABLE_PORTAUDIO  "Build with portaudio support" ON)
 option(ENABLE_Z          "Build with zlib compression support" ON)
-# todo wslua currently seems to be broken
 option(ENABLE_LUA       "Build with lua dissector support" ON)
 option(ENABLE_PYTHON    "Build with python dissector support" ON)
 option(ENABLE_SMI       "Build with smi snmp support" ON)
@@ -91,7 +92,6 @@ option(ENABLE_KERBEROS         "Build with Kerberos support" ON)
 
 set(WIRESHARK_C_FLAGS
        -O2
-       -Werror
        -Wall
        -W
        -Wextra
@@ -124,6 +124,8 @@ set(WIRESHARK_EXTRA_C_FLAGS
        -Wpragmas
        -Wredundant-decls
        -Wvla
+       -Wc++-compat
+       -Wjump-misses-init
        # packet-ncp2222.inc prevents this from going into all warnings
        -Wwrite-strings
        -Wstrict-prototypes
@@ -134,7 +136,7 @@ set(WIRESHARK_EXTRA_C_FLAGS
        -Wshorten-64-to-32
 )
 
-if(ENABLE_EXTRA_GCC_CHECKS)
+if(ENABLE_EXTRA_GCC_CHECKS)   # This overrides -Werror
        set(WIRESHARK_C_FLAGS ${WIRESHARK_C_FLAGS} ${WIRESHARK_EXTRA_C_FLAGS})
 endif()
 
@@ -159,8 +161,10 @@ foreach(THIS_FLAG ${WIRESHARK_C_FLAGS})
        math(EXPR C "${C} + 1")
 endforeach()
 
-if(DISABLE_WERROR OR ENABLE_EXTRA_GCC_CHECKS)
-       remove_definitions( -Werror )
+if(NOT DISABLE_WERROR AND NOT ENABLE_EXTRA_GCC_CHECKS)
+       check_c_compiler_flag(-Werror WERROR)
+else()
+       set(WERROR 0)
 endif()
 
 if(CMAKE_COMPILER_IS_GNUCC)
@@ -169,9 +173,20 @@ else()
        add_definitions( -D_U_=\"\" )
 endif()
 
-# todo 
+# todo
 # Same for linker flags, but it looks like it's do-it-yourself here
 # AC_WIRESHARK_GCC_LDFLAGS_CHECK([-Wl,--as-needed])
+# AC_WIRESHARK_GCC_LDFLAGS_CHECK([-flto])
+# AC_WIRESHARK_GCC_LDFLAGS_CHECK([-fwhopr])
+# AC_WIRESHARK_GCC_LDFLAGS_CHECK([-fwhole-program])
+
+if(ENABLE_STATIC)
+  set(LINK_MODE_LIB STATIC)
+  set(LINK_MODE_MODULE STATIC)
+else()
+  set(LINK_MODE_LIB SHARED)
+  set(LINK_MODE_MODULE MODULE)
+endif()
 
 #The minimum package list
 set(PACKAGELIST GLIB2 PCAP M LEX YACC Perl SH PythonInterp HtmlViewer ${PACKAGELIST})
@@ -261,7 +276,7 @@ find_package(YAPP)
 
 if(HAVE_LIBPYTHON)
        set(HAVE_PYTHON 1)
-       set(PYTHON_DIR "${CMAKE_INSTALL_PREFIX}/lib/wireshark/python/${VERSION}")
+       set(PYTHON_DIR "${CMAKE_INSTALL_PREFIX}/lib/wireshark/python/${CPACK_PACKAGE_VERSION}")
 endif()
 if(HAVE_LIBLUA)
        set(HAVE_LUA_H 1)
@@ -300,7 +315,7 @@ set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
 set(CPACK_PACKAGE_VERSION_MAJOR "1")
 set(CPACK_PACKAGE_VERSION_MINOR "3")
-set(CPACK_PACKAGE_VERSION_PATCH "1")
+set(CPACK_PACKAGE_VERSION_PATCH "2")
 set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
 
 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
@@ -345,6 +360,18 @@ foreach(PLUGIN_DIR ${PLUGIN_SRC_DIRS})
        add_subdirectory( ${PLUGIN_DIR} )
 endforeach()
 
+add_subdirectory( codecs )
+add_subdirectory( epan )
+add_subdirectory( gtk )
+add_subdirectory( tools/lemon )
+add_subdirectory( wiretap )
+add_subdirectory( wsutil )
+
+if(ENABLE_GUIDES)
+# todo
+#      add_subdirectory( docbook )
+endif()
+
 #Platform specific
 if(UNIX)
        set(WS_VAR_IMPORT "extern")
@@ -367,17 +394,10 @@ if(WIN32)
        endif()
 endif()
 
-
-add_subdirectory( codecs )
-add_subdirectory( epan )
-add_subdirectory( gtk )
-add_subdirectory( wiretap )
-add_subdirectory( wsutil )
-
 configure_file(${CMAKE_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_BINARY_DIR}/config.h)
 
 include(FeatureSummary)
-#SET_FEATURE_INFO(NAME DESCRIPTION [URL [COMMENT] ] 
+#SET_FEATURE_INFO(NAME DESCRIPTION [URL [COMMENT] ]
 PRINT_ENABLED_FEATURES()
 PRINT_DISABLED_FEATURES()
 
@@ -398,27 +418,8 @@ ADD_CUSTOM_COMMAND(
                ${CMAKE_CURRENT_SOURCE_DIR}/make-version.pl
 )
 
-# Create the necessary tools
-set(lemon_FILES
-       tools/lemon/lemon.c
-)
-set(lemon_LIBS
-       # Do we need something here on any platform?
-)
-add_executable(lemon ${lemon_FILES})
-target_link_libraries(lemon ${lemon_LIBS})
-# but don't install
-
-ADD_CUSTOM_COMMAND(
-       OUTPUT tshark-tap-register.c
-       COMMAND ${SHELL}
-         ${CMAKE_SOURCE_DIR}/make-tapreg-dotc
-         tshark-tap-register.c
-         ${CMAKE_CURRENT_SOURCE_DIR}
-         ${TSHARK_TAP_SRC}
-       DEPENDS
-         ${CMAKE_SOURCE_DIR}/make-tapreg-dotc
-         ${TSHARK_TAP_SRC}
+register_tap_files(tshark-tap-register.c
+       ${TSHARK_TAP_SRC}
 )
 
 ADD_CUSTOM_COMMAND(
@@ -512,44 +513,44 @@ set(INSTALL_DIRS
 set(INSTALL_FILES
        ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
        COPYING
-#      capinfos.html
+       ${CMAKE_BINARY_DIR}/capinfos.html
        cfilters
        colorfilters
-#      console.lua
        dfilters
-#      dtd_gen.lua
-#      dumpcap.html
-#      editcap.html
-#      idl2wrs.html
-#      init.lua
-#      ipmap.html
+       ${CMAKE_BINARY_DIR}/dumpcap.html
+       ${CMAKE_BINARY_DIR}/editcap.html
+       ${CMAKE_BINARY_DIR}/idl2wrs.html
+       ipmap.html
        manuf
-#      mergecap.html
-#      rawshark.html
+       ${CMAKE_BINARY_DIR}/mergecap.html
+       ${CMAKE_BINARY_DIR}/rawshark.html
        services
        smi_modules
-#      text2pcap.html
-#      tshark.html
-#      wireshark-filter.html
-#      wireshark.html
-#      ws.css
+       ${CMAKE_BINARY_DIR}/text2pcap.html
+       ${CMAKE_BINARY_DIR}/tshark.html
+       ${CMAKE_BINARY_DIR}/wireshark-filter.html
+       ${CMAKE_BINARY_DIR}/wireshark.html
+       docbook/ws.css
 )
 
 set(LIBEPAN_LIBS
-#              $(wireshark_optional_objects)
+#              @GETOPT_O@      # wsgetopt.c
+#              @INET_ATON_LO@  # epan/inet_aton.c
+#              @INET_NTOP_LO@  # inet_ntop.c
+#              @INET_PTON_LO@  # inet_pton.c
+#              @NSL_LIBS@      # -lnsl
+#              @SOCKET_LIBS@   # -lsocket
+#              @SSL_LIBS@      # -lcrypto
+#              @STRERROR_O@    # strerror.c
+#              @STRNCASECMP_O@ # strncasecmp.c
+#              @STRPTIME_O@    # strptime.c
                epan
-#              @INET_PTON_LO@
-#              @INET_NTOP_LO@
-#              @SSL_LIBS@
-#              $(plugin_ldadd)
+#              $(plugin_ldadd) # in case of static
                ${PCRE_LIBRARIES}
                ${PCAP_LIBRARIES}
-#              @SOCKET_LIBS@
-#              @NSL_LIBS@
                ${CARES_LIBRARIES}
                ${ADNS_LIBRARIES}
                ${KERBEROS_LIBRARIES}
-#              @FRAMEWORKS@
                ${LUA_LIBRARIES}
                ${PYTHON_LIBRARIES}
                ${GEOIP_LIBRARIES}
@@ -667,6 +668,9 @@ if(BUILD_text2pcap)
        set(text2pcap_FILES
                text2pcap.c
        )
+       set(text2pcap_CLEAN_FILES
+               ${text2pcap_FILES}
+       )
        add_lex_files(text2pcap_FILES
                text2pcap-scanner.l
        )
@@ -729,7 +733,6 @@ if(BUILD_dumpcap)
                ${CAP_LIBRARIES}
 #              @SOCKET_LIBS@
 #              @NSL_LIBS@
-#              @FRAMEWORKS@
                ${GCRYPT_LIBRARIES}
                ${GNUTLS_LIBRARIES}
                ${Z_LIBRARIES}
@@ -768,13 +771,105 @@ ADD_CUSTOM_COMMAND(
                ${CMAKE_SOURCE_DIR}/AUTHORS
 )
 
+ADD_CUSTOM_COMMAND(
+       OUTPUT  AUTHORS-SHORT-FORMAT
+               wireshark.pod
+       COMMAND ${PERL}
+               ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
+               ${CMAKE_SOURCE_DIR}/doc/make-authors-format.pl
+               < AUTHORS-SHORT
+               > AUTHORS-SHORT-FORMAT
+       COMMAND cat
+               ${CMAKE_SOURCE_DIR}/doc/wireshark.pod.template
+               AUTHORS-SHORT-FORMAT
+               > wireshark.pod
+       DEPENDS
+               ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
+               ${CMAKE_SOURCE_DIR}/doc/make-authors-format.pl
+               AUTHORS-SHORT
+               ${CMAKE_SOURCE_DIR}/doc/wireshark.pod.template
+)
+
+ADD_CUSTOM_COMMAND(
+       OUTPUT  wireshark-filter.pod
+       COMMAND tshark
+               -G fields |
+               ${PERL}
+               ${CMAKE_SOURCE_DIR}/doc/dfilter2pod.pl
+               ${CMAKE_SOURCE_DIR}/doc/wireshark-filter.pod.template
+               > wireshark-filter.pod
+       DEPENDS
+               ${CMAKE_SOURCE_DIR}/doc/dfilter2pod.pl
+               ${CMAKE_SOURCE_DIR}/doc/wireshark-filter.pod.template
+               tshark
+)
+
+find_package(POD)
+
+pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/capinfos 1 )
+pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/dumpcap 1 )
+pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/editcap 1 )
+pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/idl2wrs 1 )
+pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/mergecap 1 )
+pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/rawshark 1 )
+pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/text2pcap 1 )
+pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/tshark 1 )
+pod2manhtml( wireshark 1 )
+pod2manhtml( wireshark-filter 4 )
+
 add_custom_target(
        auxiliary ALL
        DEPENDS
                AUTHORS-SHORT
-               # todo: Add manpages and onlinedocs and generate them
+               capinfos.html
+               dumpcap.html
+               editcap.html
+               idl2wrs.html
+               mergecap.html
+               rawshark.html
+               text2pcap.html
+               tshark.html
+               wireshark.html
+               wireshark-filter.html
+)
+
+set(MAN1_FILES
+       ${CMAKE_BINARY_DIR}/capinfos.1
+       ${CMAKE_BINARY_DIR}/dumpcap.1
+       ${CMAKE_BINARY_DIR}/editcap.1
+       ${CMAKE_BINARY_DIR}/idl2wrs.1
+       ${CMAKE_BINARY_DIR}/mergecap.1
+       ${CMAKE_BINARY_DIR}/rawshark.1
+       ${CMAKE_BINARY_DIR}/text2pcap.1
+       ${CMAKE_BINARY_DIR}/tshark.1
+       ${CMAKE_BINARY_DIR}/wireshark.1
 )
 
+set(MAN4_FILES
+       ${CMAKE_BINARY_DIR}/wireshark-filter.4
+)
+
+set(CLEAN_FILES
+       ${wireshark_FILES}
+       ${tshark_FILES}
+       ${rawshark_FILES}
+       ${dftest_FILES}
+       ${randpkt_FILES}
+       ${text2pcap_CLEAN_FILES}
+       ${mergecap_FILES}
+       ${capinfos_FILES}
+       ${editcap_FILES}
+       ${dumpcap_FILES}
+)
+
+if (WERROR)
+       set_source_files_properties(
+               ${CLEAN_FILES}
+               PROPERTIES
+               COMPILE_FLAGS -Werror
+       )
+endif()
+
 install(
        FILES
                ${INSTALL_FILES}
@@ -782,6 +877,20 @@ install(
                ${CMAKE_INSTALL_DATADIR}/${CPACK_PACKAGE_NAME}
 )
 
+install(
+       FILES
+               ${MAN1_FILES}
+       DESTINATION
+               ${CMAKE_INSTALL_MANDIR}/man1
+)
+
+install(
+       FILES
+               ${MAN4_FILES}
+       DESTINATION
+               ${CMAKE_INSTALL_MANDIR}/man4
+)
+
 install(
        DIRECTORY
                ${INSTALL_DIRS}