CMake: Allow user build flags to override default build flags
[metze/wireshark/wip.git] / cmake / modules / WiresharkPlugin.cmake
1 # Plugin convenience macros.
2
3 # Set information
4 macro(SET_MODULE_INFO _plugin _ver_major _ver_minor _ver_micro _ver_extra)
5         # Create the Windows .rc file for the plugin.
6         # The values come from several files in the source, I can't see how to reuse them
7
8         set(PACKAGE ${_plugin})
9         set(MODULE_VERSION_MAJOR ${_ver_major})
10         set(MODULE_VERSION_MINOR ${_ver_minor})
11         set(MODULE_VERSION_MICRO ${_ver_micro})
12         set(MODULE_VERSION_EXTRA ${_ver_extra})
13         set(MODULE_VERSION "${MODULE_VERSION_MAJOR}.${MODULE_VERSION_MINOR}.${MODULE_VERSION_MICRO}.${MODULE_VERSION_EXTRA}")
14         set(RC_MODULE_VERSION "${MODULE_VERSION_MAJOR},${MODULE_VERSION_MINOR},${MODULE_VERSION_MICRO},${MODULE_VERSION_EXTRA}")
15
16         # This info is from Makefile.am
17         set(PLUGIN_NAME ${PACKAGE})
18
19         set(MSVC_VARIANT "${CMAKE_GENERATOR}")
20
21         # The rc.in requires a plain VERSION variable
22         set(VERSION ${PROJECT_VERSION})
23
24         # Create the plugin.rc file from the template
25         configure_file(plugin.rc.in plugin.rc @ONLY)
26 endmacro()
27
28 macro(ADD_PLUGIN_LIBRARY _plugin)
29         add_library(${_plugin} ${LINK_MODE_MODULE}
30                 ${PLUGIN_FILES}
31                 ${CMAKE_CURRENT_BINARY_DIR}/plugin.rc
32         )
33
34         set_target_properties(${_plugin} PROPERTIES
35                 PREFIX ""
36                 LINK_FLAGS "${WS_LINK_FLAGS}"
37                 FOLDER "Plugins"
38         )
39
40         # LIBRARY_OUTPUT_DIRECTORY alone appears to be sufficient.
41         set_target_properties(${_plugin} PROPERTIES
42                 #ARCHIVE_OUTPUT_DIRECTORY ${PLUGIN_DIR}
43                 LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_DIR}
44                 #RUNTIME_OUTPUT_DIRECTORY ${PLUGIN_DIR}
45         )
46
47         # Try to force output to ${PLUGIN_DIR} without the configuration
48         # type appended. Needed for CPack on Windows.
49         foreach(_config_type ${CMAKE_CONFIGURATION_TYPES})
50                 string(TOUPPER ${_config_type} _config_upper)
51                 set_target_properties(${_plugin} PROPERTIES
52                         LIBRARY_OUTPUT_DIRECTORY_${_config_upper} ${CMAKE_BINARY_DIR}/run/${_config_type}/${PLUGIN_VERSION_DIR}
53                 )
54         endforeach()
55
56         target_link_libraries(${_plugin} epan)
57         add_dependencies(plugins ${_plugin})
58 endmacro()