Wireshark-dev: Re: [Wireshark-dev] Contributing to #17949 and #17947

From: Guy Harris <gharris@xxxxxxxxx>
Date: Mon, 14 Mar 2022 10:57:11 -0700
On Mar 14, 2022, at 8:25 AM, Roland Knall <rknall@xxxxxxxxx> wrote:

> As for the issues, 17947 will be a huge undertaking. Just embedding the CMake and make it moveable is not enough, there are a lot of sub-methods that have to be made aware of this move as well. Not saying it cannot be done, just that this task may appear smaller than it actually is.

CMAKE_SOURCE_DIR:

	https://cmake.org/cmake/help/v3.23/variable/CMAKE_SOURCE_DIR.html#variable:CMAKE_SOURCE_DIR

is defined as "the full path to the top level of the current CMake source tree.", and CMAKE_CURRENT_SOURCE_DIR:

	https://cmake.org/cmake/help/v3.23/variable/CMAKE_CURRENT_SOURCE_DIR.html#variable:CMAKE_CURRENT_SOURCE_DIR

is defined as "the full path to the source directory that is currently being processed by cmake".

I infer that this means that, in a CMakeLists.txt file in a subdirectory, CMAKE_SOURCE_DIR will be the full path to the top of the Wireshark project source tree, containing, for example, the "manuf" file, and CMAKE_CURRENT_SOURCE_DIR will be the full path to that subdirectory.  For example, epan/dissectors/CMakeLists.txt contains the code

add_custom_command(
	OUTPUT dissectors.c
	COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/make-regs.py dissectors dissectors.c @dissectors.in.txt
	DEPENDS ${CMAKE_SOURCE_DIR}/tools/make-regs.py ${ALL_DISSECTOR_SRC}
		"${CMAKE_CURRENT_BINARY_DIR}/dissectors.in.txt"
	COMMENT "Making dissectors.c"
)

and wiretap/CMakeLists.txt contains the code

add_custom_command(
	OUTPUT wtap_modules.c
	COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/make-regs.py wtap_modules wtap_modules.c @wtap_modules.in.txt
	DEPENDS ${CMAKE_SOURCE_DIR}/tools/make-regs.py ${WIRETAP_MODULE_FILES}
		"${CMAKE_CURRENT_BINARY_DIR}/wtap_modules.in.txt"
	COMMENT "Making wtap_modules.c"
)

and *both* of those code sequences be able to refer to the top-level source directory of Wireshark.  make-regs.py is a tool used from *more than one* subdirectory of Wireshark, so it does *not* belong in any of those subdirectories, it belongs in a general directory of tools, so there *must* be a way for CMakeLists.txt files in subdirectories of the Wireshark source tree to refer to a directory of tools that's *not* in those subdirectories, but is, instead, in a separate subdirectory of the Wireshark source tree.

See the comments I have added to #17947.