Skip to content

Commit

Permalink
Fix build paths for cmake's Xcode project generator on macOS.
Browse files Browse the repository at this point in the history
Multi-configuration generators (such as Xcode or VS) append the current build configuration to most paths (eg. Debug/Release). Currently this results in inconsistent paths for the application bundle and the included command line tools. This commit sets the correct path information for multi-configuration generators for macOS application bundles. The standard Makefile behaviour is untouched.

One Windows specific configuration was changed, as it was conflicting with these changes. This needs to be checked before merging.

Additionally the wrapper scripts are omitted for Xcode, as the path to the binaries depends on the configuration chosen in Xcode. Therefore it is not viable to create these scripts in the cmake run.

Bug: 11816

Change-Id: Ib43d82eb04600a0e2f2b020afb44b579ffc7a7c9
Reviewed-on: https://code.wireshark.org/review/28291
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
  • Loading branch information
neffs authored and AndersBroman committed Jun 21, 2018
1 parent 17604f1 commit 11ba10d
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 48 deletions.
62 changes: 42 additions & 20 deletions CMakeLists.txt
Expand Up @@ -1307,7 +1307,12 @@ add_subdirectory( writecap )
# application bundle, and on UNIX in general if
# WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set.
if(ENABLE_APPLICATION_BUNDLE)
set(_datafile_dir "${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Resources/share/wireshark")
if(CMAKE_CFG_INTDIR STREQUAL ".")
set(_datafile_dir "${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Resources/share/wireshark")
else()
# Xcode
set(_datafile_dir "${CMAKE_BINARY_DIR}/run/${CMAKE_CFG_INTDIR}/Wireshark.app/Contents/Resources/share/wireshark")
endif()
elseif(NOT CMAKE_CFG_INTDIR STREQUAL ".")
# Visual Studio, Xcode, etc.
set(_datafile_dir "${CMAKE_BINARY_DIR}/run/${CMAKE_CFG_INTDIR}")
Expand Down Expand Up @@ -1346,7 +1351,7 @@ if(ENABLE_PLUGINS)
# Target platform locations
# UN*X in general, including macOS if not building an app bundle:
# $DESTDIR/lib/wireshark/plugins/$VERSION
# Windows: $DESTDIR/wireshark/plubins/$VERSION
# Windows: $DESTDIR/wireshark/plugins/$VERSION
# macOS app bundle: Wireshark.app/Contents/PlugIns/wireshark
set(HAVE_PLUGINS 1)
add_custom_target(plugins)
Expand Down Expand Up @@ -1382,7 +1387,14 @@ else()
endif()

if(ENABLE_APPLICATION_BUNDLE)
set(_plugin_dir "${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/PlugIns/wireshark/${PROJECT_RELEASE_VERSION}")
if(CMAKE_CFG_INTDIR STREQUAL ".")
set(_plugin_dir "${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/PlugIns/wireshark/${PROJECT_RELEASE_VERSION}")
else()
# Xcode
set(_plugin_dir "${CMAKE_BINARY_DIR}/run/$<CONFIG>/Wireshark.app/Contents/PlugIns/wireshark/${PROJECT_RELEASE_VERSION}")
endif()
elseif(WIN32 AND NOT CMAKE_CFG_INTDIR STREQUAL ".")
set(_plugin_dir "${CMAKE_BINARY_DIR}/run/$<CONFIG>/${PLUGIN_VERSION_DIR}")
else()
set(_plugin_dir "${DATAFILE_DIR}/${PLUGIN_VERSION_DIR}")
endif()
Expand Down Expand Up @@ -2179,13 +2191,16 @@ if(BUILD_wireshark AND QT_FOUND)
wireshark PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_BINARY_DIR}/packaging/macosx/Info.plist
)
# Add a wrapper script which opens the bundle. This adds
# convenience but makes debugging more difficult.
file(REMOVE ${CMAKE_BINARY_DIR}/run/wireshark)
file(WRITE ${CMAKE_BINARY_DIR}/run/wireshark "#!/bin/sh\n")
file(APPEND ${CMAKE_BINARY_DIR}/run/wireshark "# Generated by ${CMAKE_CURRENT_LIST_FILE}\n")
file(APPEND ${CMAKE_BINARY_DIR}/run/wireshark "exec ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/MacOS/Wireshark \"\$\@\"\n")
execute_process(COMMAND chmod a+x ${CMAKE_BINARY_DIR}/run/wireshark)
if(CMAKE_CFG_INTDIR STREQUAL ".")
# Add a wrapper script which opens the bundle. This adds
# convenience but makes debugging more difficult.
# It is not created if using Xcode
file(REMOVE ${CMAKE_BINARY_DIR}/run/wireshark)
file(WRITE ${CMAKE_BINARY_DIR}/run/wireshark "#!/bin/sh\n")
file(APPEND ${CMAKE_BINARY_DIR}/run/wireshark "# Generated by ${CMAKE_CURRENT_LIST_FILE}\n")
file(APPEND ${CMAKE_BINARY_DIR}/run/wireshark "exec ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/MacOS/Wireshark \"\$\@\"\n")
execute_process(COMMAND chmod a+x ${CMAKE_BINARY_DIR}/run/wireshark)
endif()
endif()

target_link_libraries(wireshark ${wireshark_LIBS})
Expand Down Expand Up @@ -2224,16 +2239,23 @@ macro(set_extra_executable_properties _executable _folder)
set(PROGLIST ${PROGLIST} ${_executable})

if(ENABLE_APPLICATION_BUNDLE)
set_target_properties(${_executable} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY run/Wireshark.app/Contents/MacOS
)
# Add a wrapper script which runs each executable from the
# correct location. This adds convenience but makes debugging
# more difficult.
file(REMOVE ${CMAKE_BINARY_DIR}/run/${_executable})
file(WRITE ${CMAKE_BINARY_DIR}/run/${_executable} "#!/bin/sh\n")
file(APPEND ${CMAKE_BINARY_DIR}/run/${_executable} "exec ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/MacOS/${_executable} \"\$\@\"\n")
execute_process(COMMAND chmod a+x ${CMAKE_BINARY_DIR}/run/${_executable})
if(NOT CMAKE_CFG_INTDIR STREQUAL ".")
# Xcode
set_target_properties(${_executable} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY run/$<CONFIG>/Wireshark.app/Contents/MacOS
)
else ()
set_target_properties(${_executable} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY run/Wireshark.app/Contents/MacOS
)
# Add a wrapper script which runs each executable from the
# correct location. This adds convenience but makes debugging
# more difficult.
file(REMOVE ${CMAKE_BINARY_DIR}/run/${_executable})
file(WRITE ${CMAKE_BINARY_DIR}/run/${_executable} "#!/bin/sh\n")
file(APPEND ${CMAKE_BINARY_DIR}/run/${_executable} "exec ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/MacOS/${_executable} \"\$\@\"\n")
execute_process(COMMAND chmod a+x ${CMAKE_BINARY_DIR}/run/${_executable})
endif()
endif()
endmacro()

Expand Down
16 changes: 16 additions & 0 deletions README.macos
Expand Up @@ -74,6 +74,22 @@ directory;
cmake ..
make

It is also possible to use the Xcode IDE to build and debug Wireshark
using cmake's Xcode generator. Create a separate build directory, as
described above and run cmake with the "-G Xcode" argument to create
a Xcode project file in the current directory.

cmake -G Xcode ..

1. Double click Wireshark.xcodeproj

2. Choose to create schemes manually

3. Create a scheme for the ALL_BUILD target

4. Edit the scheme, go to the run configuration and select Wireshark.app
as executable

If you upgrade the major release of macOS on which you are building
Wireshark, we advise that, before you do any builds after the upgrade,
you remove the build directory and all its subdiretories, and repeat the
Expand Down
9 changes: 0 additions & 9 deletions cmake/modules/WiresharkPlugin.cmake
Expand Up @@ -44,15 +44,6 @@ macro(ADD_PLUGIN_LIBRARY _plugin _subfolder)
LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_DIR}/${_subfolder}
)

# Try to force output to ${PLUGIN_DIR} without the configuration
# type appended. Needed on Windows.
foreach(_config_type ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${_config_type} _config_upper)
set_target_properties(${_plugin} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY_${_config_upper} ${CMAKE_BINARY_DIR}/run/${_config_type}/${PLUGIN_VERSION_DIR}/${_subfolder}
)
endforeach()

add_dependencies(plugins ${_plugin})
endmacro()

Expand Down
10 changes: 10 additions & 0 deletions codecs/CMakeLists.txt
Expand Up @@ -66,6 +66,16 @@ if(ENABLE_APPLICATION_BUNDLE)
set_target_properties(wscodecs PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Frameworks
)
if(NOT CMAKE_CFG_INTDIR STREQUAL ".")
# Xcode
set_target_properties(wscodecs PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/$<CONFIG>/Wireshark.app/Contents/Frameworks
)
else()
set_target_properties(wscodecs PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Frameworks
)
endif()
endif()

target_link_libraries(wscodecs ${wscodecs_LIBS})
Expand Down
13 changes: 10 additions & 3 deletions epan/CMakeLists.txt
Expand Up @@ -313,9 +313,16 @@ set_target_properties(epan PROPERTIES
)

if(ENABLE_APPLICATION_BUNDLE)
set_target_properties(epan PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Frameworks
)
if(NOT CMAKE_CFG_INTDIR STREQUAL ".")
# Xcode
set_target_properties(epan PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/$<CONFIG>/Wireshark.app/Contents/Frameworks
)
else()
set_target_properties(epan PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Frameworks
)
endif()
endif()

ABICHECK(libwireshark)
Expand Down
27 changes: 17 additions & 10 deletions extcap/CMakeLists.txt
Expand Up @@ -47,16 +47,23 @@ macro(set_extcap_executable_properties _executable)
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/extcap
)
if(ENABLE_APPLICATION_BUNDLE)
set_target_properties(${_executable} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY run/Wireshark.app/Contents/MacOS/extcap
)
# Add a wrapper script which runs each executable from the
# correct location. This adds convenience but makes debugging
# more difficult.
file(REMOVE ${CMAKE_BINARY_DIR}/run/${_executable})
file(WRITE ${CMAKE_BINARY_DIR}/run/${_executable} "#!/bin/sh\n")
file(APPEND ${CMAKE_BINARY_DIR}/run/${_executable} "exec ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/MacOS/extcap/${_executable} \"\$\@\"\n")
execute_process(COMMAND chmod a+x ${CMAKE_BINARY_DIR}/run/${_executable})
if(NOT CMAKE_CFG_INTDIR STREQUAL ".")
# Xcode
set_target_properties(${_executable} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/$<CONFIG>/Wireshark.app/Contents/MacOS/extcap
)
else()
set_target_properties(${_executable} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/MacOS/extcap
)
# Add a wrapper script which runs each executable from the
# correct location. This adds convenience but makes debugging
# more difficult.
file(REMOVE ${CMAKE_BINARY_DIR}/run/${_executable})
file(WRITE ${CMAKE_BINARY_DIR}/run/${_executable} "#!/bin/sh\n")
file(APPEND ${CMAKE_BINARY_DIR}/run/${_executable} "exec ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/MacOS/extcap/${_executable} \"\$\@\"\n")
execute_process(COMMAND chmod a+x ${CMAKE_BINARY_DIR}/run/${_executable})
endif()
endif()
endif()
endmacro()
Expand Down
13 changes: 10 additions & 3 deletions wiretap/CMakeLists.txt
Expand Up @@ -127,9 +127,16 @@ set_target_properties(wiretap PROPERTIES
)

if(ENABLE_APPLICATION_BUNDLE)
set_target_properties(wiretap PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Frameworks
)
if(NOT CMAKE_CFG_INTDIR STREQUAL ".")
# Xcode
set_target_properties(wiretap PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/$<CONFIG>/Wireshark.app/Contents/Frameworks
)
else()
set_target_properties(wiretap PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Frameworks
)
endif()
endif()

ABICHECK(libwiretap)
Expand Down
14 changes: 11 additions & 3 deletions wsutil/CMakeLists.txt
Expand Up @@ -267,9 +267,17 @@ set_target_properties(wsutil PROPERTIES
)

if(ENABLE_APPLICATION_BUNDLE)
set_target_properties(wsutil PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Frameworks
)

if(NOT CMAKE_CFG_INTDIR STREQUAL ".")
# Xcode
set_target_properties(wsutil PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/$<CONFIG>/Wireshark.app/Contents/Frameworks
)
else()
set_target_properties(wsutil PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Frameworks
)
endif()
endif()

ABICHECK(libwsutil)
Expand Down

0 comments on commit 11ba10d

Please sign in to comment.