From cb345eb4bd0149b4a71d6069f957600a83cc3417 Mon Sep 17 00:00:00 2001 From: Maarten Bezemer Date: Sun, 16 Nov 2014 16:07:45 +0100 Subject: Use LocatePythonModule to find make-dissector-reg.py in order to make UseMakeDissectorReg.cmake more generally (out-of-source) usable. Add make-dissector-reg.py to the Debian packages. Making it possible to generate out-of-source wireshark plugins. Change-Id: I0bbe5b46205d39e229d31812341540b26a7336d6 Reviewed-on: https://code.wireshark.org/review/5802 Reviewed-by: Anders Broman --- CMakeLists.txt | 2 ++ cmake/modules/LocatePythonModule.cmake | 51 +++++++++++++++++++++++++++++++++ cmake/modules/UseMakeDissectorReg.cmake | 8 ++++-- debian/rules | 3 +- debian/wireshark-dev.install | 3 +- 5 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 cmake/modules/LocatePythonModule.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c094e27c92..8f676ea1f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1799,6 +1799,8 @@ install( ${CMAKE_MODULE_PATH}/FindWireshark.cmake ${CMAKE_MODULE_PATH}/FindWSWinLibs.cmake ${CMAKE_MODULE_PATH}/UseAsn2Wrs.cmake + ${CMAKE_MODULE_PATH}/LocatePythonModule.cmake + ${CMAKE_MODULE_PATH}/UseMakeDissectorReg.cmake ${CMAKE_BINARY_DIR}/WiresharkConfig.cmake ${CMAKE_BINARY_DIR}/WiresharkConfigVersion.cmake DESTINATION diff --git a/cmake/modules/LocatePythonModule.cmake b/cmake/modules/LocatePythonModule.cmake new file mode 100644 index 0000000000..813cf25b53 --- /dev/null +++ b/cmake/modules/LocatePythonModule.cmake @@ -0,0 +1,51 @@ +#LOCATE_PYTHON_MODULE( [PATHS ... ] [REQUIRED]) +# +# This function tries to find the given python module. +# If found the path is provided in and <_FOUND> is set to TRUE. +# +# After PATHS additional paths for python to search can be provided. +# When REQUIRED is set, the function will abort the cmake execution is the module is not found +function(LOCATE_PYTHON_MODULE module) + find_package(PythonInterp) + + # Parse (additional) arguments + set(options REQUIRED) + set(multiValueArgs PATHS) + cmake_parse_arguments(LPM "${options}" "" "${multiValueArgs}" ${ARGN}) + + string(TOUPPER ${module} module_upper) + if(NOT PY_${module_upper}) + + if(LPM_PATHS) + # Append LPM_PATHS to PYTHONPATH to search at provided location (first) + file(TO_CMAKE_PATH "$ENV{PYTHONPATH}" CMAKE_PATH) + list(INSERT CMAKE_PATH 0 ${LPM_PATHS}) + file(TO_NATIVE_PATH "${CMAKE_PATH}" NATIVE_PATH) + if(UNIX) + string(REPLACE ";" ":" NATIVE_PATH "${NATIVE_PATH}") + endif(UNIX) + set(ENV{PYTHONPATH} "${NATIVE_PATH}") + endif(LPM_PATHS) + + # Use the (native) python impl module to find the location of the requested module + execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" + "import imp; print imp.find_module('${module}')[1]" + RESULT_VARIABLE _${module}_status + OUTPUT_VARIABLE _${module}_location + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + + if(NOT _${module}_status) + set(PY_${module_upper} ${_${module}_location} CACHE STRING + "Location of Python module ${module}") + set(${module_upper}_FOUND TRUE) + message(STATUS "Found python module ${module}: ${PY_${module_upper}}") + else(NOT _${module}_status) + set(${module_upper}_FOUND FALSE) + if(LPM_REQUIRED) + message(FATAL_ERROR "Could NOT find python module ${module}") + else(LPM_REQUIRED) + message(STATUS "Could NOT find python module ${module}") + endif(LPM_REQUIRED) + endif(NOT _${module}_status) + endif(NOT PY_${module_upper}) +endfunction(LOCATE_PYTHON_MODULE) diff --git a/cmake/modules/UseMakeDissectorReg.cmake b/cmake/modules/UseMakeDissectorReg.cmake index 6c1cda5cba..d805ef20e1 100644 --- a/cmake/modules/UseMakeDissectorReg.cmake +++ b/cmake/modules/UseMakeDissectorReg.cmake @@ -1,5 +1,8 @@ # MACRO(REGISTER_DISSECTOR_FILES _outputfile _registertype ) + include(LocatePythonModule) + locate_python_module(make-dissector-reg REQUIRED PATHS ${CMAKE_SOURCE_DIR}/tools) + if(${_registertype} STREQUAL "dissectors" ) set( _makeregistertype "dissectorsinfile" ) set( _ftmp "${CMAKE_CURRENT_BINARY_DIR}/_regc.tmp" ) @@ -18,13 +21,12 @@ MACRO(REGISTER_DISSECTOR_FILES _outputfile _registertype ) OUTPUT ${_outputfile} COMMAND ${PYTHON_EXECUTABLE} - ${CMAKE_SOURCE_DIR}/tools/make-dissector-reg.py + ${PY_MAKE-DISSECTOR-REG} ${CMAKE_CURRENT_SOURCE_DIR} ${_makeregistertype} ${_sources} DEPENDS ${_depends} - ${CMAKE_SOURCE_DIR}/tools/make-dissector-reg.py + ${PY_MAKE-DISSECTOR-REG} ) ENDMACRO(REGISTER_DISSECTOR_FILES) - diff --git a/debian/rules b/debian/rules index 171d2596b9..e89902ee60 100755 --- a/debian/rules +++ b/debian/rules @@ -55,6 +55,7 @@ override_dh_install: override_dh_fixperms: dh_fixperms - chmod 644 debian/wireshark-dev/usr/share/pyshared/wireshark_be.py \ + chmod 644 debian/wireshark-dev/usr/share/pyshared/make-dissector-reg.py \ + debian/wireshark-dev/usr/share/pyshared/wireshark_be.py \ debian/wireshark-dev/usr/share/pyshared/wireshark_gen.py diff --git a/debian/wireshark-dev.install b/debian/wireshark-dev.install index 728d1c682f..2705f2945c 100644 --- a/debian/wireshark-dev.install +++ b/debian/wireshark-dev.install @@ -1,7 +1,8 @@ tools/idl2wrs usr/bin tools/idl2deb usr/bin tools/asn2deb usr/bin +tools/make-dissector-reg.py usr/share/pyshared tools/wireshark_be.py usr/share/pyshared tools/wireshark_gen.py usr/share/pyshared tools/asn2wrs.py usr/share/pyshared -usr/lib/*/wireshark/*.cmake \ No newline at end of file +usr/lib/*/wireshark/*.cmake -- cgit v1.2.1