Commit f4055e27 authored by Ben Boeckel's avatar Ben Boeckel
Browse files

linux: remove forward executables

Instead, use `$ORIGIN` rpath entries.

Fixes: #18894
parent f66169a4
......@@ -30,11 +30,6 @@ set(sources
ParaViewMainWindow.h
ParaViewMainWindow.ui)
set(paraview_forward_executable OFF)
if (UNIX AND NOT APPLE)
set(paraview_forward_executable ON)
endif ()
find_package(Qt5 REQUIRED QUIET COMPONENTS Core Widgets)
if (APPLE)
......@@ -64,8 +59,7 @@ paraview_client_add(
APPLICATION_ICON "${CMAKE_CURRENT_SOURCE_DIR}/pvIcon.ico"
SOURCES ${sources}
PLUGINS_TARGET paraview_plugins
APPLICATION_XMLS ${xmls}
FORWARD_EXECUTABLE "${paraview_forward_executable}")
APPLICATION_XMLS ${xmls})
find_package(Qt5 REQUIRED QUIET COMPONENTS Widgets)
......
......@@ -38,7 +38,6 @@ paraview_client_add(
[BUNDLE_DESTINATION <directory>]
[RUNTIME_DESTINATION <directory>]
[LIBRARY_DESTINATION <directory>]
[FORWARD_EXECUTABLE <ON|OFF>]
```
* `NAME`: (Required) The name of the application. This is used as the target
......@@ -77,16 +76,14 @@ paraview_client_add(
bundle executable.
* `RUNTIME_DESTINATION`: (Defaults to `${CMAKE_INSTALL_BINDIR}`) Where to
place the binary.
* `LIBRARY_DESTINATION`: (Defaults to `${CMAKE_INSTALL_LIBDIR}`) Where to
place libraries. Only used if `FORWARD_EXECUTABLE` is `ON`.
* `FORWARD_EXECUTABLE`: (Deprecated) (Defaults to `OFF`) On non-macOS Unix
platforms, create a binary to set up `LD_LIBRARY_PATH` for the real
executable.
* `LIBRARY_DESTINATION`: (Defaults to `${CMAKE_INSTALL_LIBDIR}`) Where
libraries are placed. Sets up `RPATH` on ELF platforms (e.g., Linux and the
BSD family).
#]==]
function (paraview_client_add)
cmake_parse_arguments(_paraview_client
""
"NAME;APPLICATION_NAME;ORGANIZATION;TITLE;SPLASH_IMAGE;BUNDLE_DESTINATION;BUNDLE_ICON;BUNDLE_PLIST;APPLICATION_ICON;MAIN_WINDOW_CLASS;MAIN_WINDOW_INCLUDE;VERSION;FORCE_UNIX_LAYOUT;PLUGINS_TARGET;DEFAULT_STYLE;FORWARD_EXECUTABLE;RUNTIME_DESTINATION;LIBRARY_DESTINATION;NAMESPACE;EXPORT"
"NAME;APPLICATION_NAME;ORGANIZATION;TITLE;SPLASH_IMAGE;BUNDLE_DESTINATION;BUNDLE_ICON;BUNDLE_PLIST;APPLICATION_ICON;MAIN_WINDOW_CLASS;MAIN_WINDOW_INCLUDE;VERSION;FORCE_UNIX_LAYOUT;PLUGINS_TARGET;DEFAULT_STYLE;RUNTIME_DESTINATION;LIBRARY_DESTINATION;NAMESPACE;EXPORT"
"REQUIRED_PLUGINS;OPTIONAL_PLUGINS;APPLICATION_XMLS;SOURCES;QCH_FILE"
${ARGN})
......@@ -148,12 +145,6 @@ function (paraview_client_add)
"${CMAKE_INSTALL_LIBDIR}")
endif ()
if (NOT DEFINED _paraview_client_FORWARD_EXECUTABLE)
#message(DEPRECATION
# "The `FORWARD_EXECUTABLE` argument is deprecated.")
set(_paraview_client_FORWARD_EXECUTABLE OFF)
endif ()
if (NOT DEFINED _paraview_client_MAIN_WINDOW_CLASS)
if (DEFINED _paraview_client_MAIN_WINDOW_INCLUDE)
message(FATAL_ERROR
......@@ -307,6 +298,19 @@ IDI_ICON1 ICON \"${_paraview_client_APPLICATION_ICON}\"\n")
"${CMAKE_CURRENT_BINARY_DIR}/pq${_paraview_client_NAME}Initializer.h"
@ONLY)
# Set up rpaths
set(CMAKE_BUILD_RPATH_USE_ORIGIN 1)
if (UNIX AND NOT APPLE)
file(RELATIVE_PATH _paraview_client_relpath
"/prefix/${_paraview_client_RUNTIME_DESTINATION}"
"/prefix/${_paraview_client_LIBRARY_DESTINATION}")
set(_paraview_client_origin_rpath
"$ORIGIN/${_paraview_client_relpath}")
list(APPEND CMAKE_INSTALL_RPATH
"${_paraview_client_origin_rpath}")
endif ()
if (_paraview_client_resource_files)
source_group("resources"
FILES
......@@ -338,53 +342,6 @@ IDI_ICON1 ICON \"${_paraview_client_APPLICATION_ICON}\"\n")
"${_paraview_client_PLUGINS_TARGET}")
endif ()
# Set up the forwarding executable
set(_paraview_client_destination "${_paraview_client_RUNTIME_DESTINATION}")
if (BUILD_SHARED_LIBS AND UNIX AND NOT APPLE AND _paraview_client_FORWARD_EXECUTABLE)
set(_paraview_client_build_dir "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
set(_paraview_client_build_path "\"${_paraview_client_build_dir}\"")
foreach (_paraview_client_build_path_dir IN LISTS )
string(APPEND _paraview_client_build_path
",\"${_paraview_client_build_path_dir}\"")
endforeach ()
set(_paraview_client_install_dir "../${_paraview_client_LIBRARY_DESTINATION}")
set(_paraview_client_install_path "\"${_paraview_client_install_dir}\"")
foreach (_paraview_client_install_path_dir IN LISTS )
string(APPEND _paraview_client_install_path
",\"${_paraview_client_install_path_dir}\"")
endforeach ()
# Set up variables expected in paraview_launcher.c.in
foreach(suffix build_dir build_path install_dir install_path NAME)
set(_paraview_launcher_${suffix} ${_paraview_client_${suffix}})
endforeach ()
configure_file(
"${_ParaViewClient_cmake_dir}/paraview_launcher.c.in"
"${CMAKE_CURRENT_BINARY_DIR}/${_paraview_client_NAME}_launcher.c"
@ONLY)
add_executable("${_paraview_client_NAME}-launcher"
"${CMAKE_CURRENT_BINARY_DIR}/${_paraview_client_NAME}_launcher.c")
# https://gitlab.kitware.com/cmake/cmake/issues/18049
#target_link_libraries("${_paraview_client_NAME}-launcher"
# PRIVATE
# VTK::vtksys)
target_include_directories("${_paraview_client_NAME}-launcher"
PRIVATE
"$<TARGET_PROPERTY:VTK::vtksys,INTERFACE_INCLUDE_DIRECTORIES>")
set_target_properties("${_paraview_client_NAME}-launcher"
PROPERTIES
OUTPUT_NAME "${_paraview_client_NAME}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/launcher")
add_dependencies("${_paraview_client_NAME}-launcher"
"${_paraview_client_NAME}")
install(
TARGETS "${_paraview_client_NAME}-launcher"
RUNTIME DESTINATION "${_paraview_client_RUNTIME_DESTINATION}")
set(_paraview_client_destination "${_paraview_client_LIBRARY_DESTINATION}")
endif ()
set(_paraview_client_export)
if (DEFINED _paraview_client_EXPORT)
set(_paraview_client_export
......@@ -395,7 +352,7 @@ IDI_ICON1 ICON \"${_paraview_client_APPLICATION_ICON}\"\n")
TARGETS "${_paraview_client_NAME}"
${_paraview_client_export}
${_paraview_client_bundle_args}
RUNTIME DESTINATION "${_paraview_client_destination}")
RUNTIME DESTINATION "${_paraview_client_RUNTIME_DESTINATION}")
if (APPLE)
if (DEFINED _paraview_client_BUNDLE_ICON)
......
......@@ -31,7 +31,6 @@ set(paraview_cmake_module_files
# Client API
paraview_client_initializer.cxx.in
paraview_client_initializer.h.in
paraview_launcher.c.in
paraview_client_main.cxx.in
ParaViewClient.cmake
paraview_servermanager_convert_categoryindex.xsl
......
/*=========================================================================
Program: @_paraview_client_NAME@
Module: @_paraview_client_NAME@_launcher.c
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#define vtksys_SHARED_FORWARD_DIR_BUILD "@_paraview_launcher_build_dir@"
#define vtksys_SHARED_FORWARD_PATH_BUILD @_paraview_launcher_build_path@
#define vtksys_SHARED_FORWARD_PATH_INSTALL @_paraview_launcher_install_path@
#define vtksys_SHARED_FORWARD_EXE_BUILD "@_paraview_launcher_build_dir@/@_paraview_launcher_NAME@"
#define vtksys_SHARED_FORWARD_EXE_INSTALL "@_paraview_launcher_install_dir@/@_paraview_launcher_NAME@"
#define vtksys_SHARED_FORWARD_OPTION_PRINT "--print"
#define vtksys_SHARED_FORWARD_OPTION_LDD "--ldd"
#include <libgen.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <vtksys/SharedForward.h>
int get_driver_cache_user_path(char *driver_cache_path)
{
const char *home = getenv("HOME");
if (!home)
{
home = getpwuid(getuid())->pw_dir;
}
if (!home)
{
return 0;
}
snprintf(driver_cache_path, KWSYS_SHARED_FORWARD_MAXPATH, "%s/.config/ParaView/ParaViewMesaConfig.ini", home);
//fprintf(stdout, "User cache = %s\n", driver_cache_path);
return 1;
}
int get_driver_cache_site_path(const char *this_exe_path,
char *driver_cache_path)
{
// Get directory containing true paraview executable.
char self_path[KWSYS_SHARED_FORWARD_MAXPATH] = { 0 };
char throwaway_ldpath[KWSYS_SHARED_FORWARD_MAXPATH] = { 0 };
char exe[KWSYS_SHARED_FORWARD_MAXPATH] = { 0 };
kwsys_shared_forward_self_path(this_exe_path, self_path);
kwsys_shared_forward_get_settings(self_path, throwaway_ldpath, exe);
char *dirname_exe = dirname(exe);
snprintf(driver_cache_path, KWSYS_SHARED_FORWARD_MAXPATH, "%s/ParaViewMesaConfig.ini", dirname_exe);
//fprintf(stdout, "Site cache = %s\n", driver_cache_path);
return 1;
}
int append_driver_to_ldpath(const char *this_exe_path, const char *driver)
{
char self_path[KWSYS_SHARED_FORWARD_MAXPATH] = { 0 };
char throwaway_ldpath[KWSYS_SHARED_FORWARD_MAXPATH] = { 0 };
char exe[KWSYS_SHARED_FORWARD_MAXPATH] = { 0 };
// Use default native driver, so don't update LD_LIBRARY_PATH
if (!driver || (driver && driver[0] == '\0'))
{
return 0;
}
kwsys_shared_forward_self_path(this_exe_path, self_path);
kwsys_shared_forward_get_settings(self_path, throwaway_ldpath, exe);
char *dirname_exe = dirname(exe);
strncat(kwsys_shared_forward_ldpath, dirname_exe, KWSYS_SHARED_FORWARD_MAXPATH - strlen(kwsys_shared_forward_ldpath) - strlen(dirname_exe) - 1);
strncat(kwsys_shared_forward_ldpath, "/", KWSYS_SHARED_FORWARD_MAXPATH - strlen(kwsys_shared_forward_ldpath) - 1 - 1);
strncat(kwsys_shared_forward_ldpath, driver, KWSYS_SHARED_FORWARD_MAXPATH - strlen(kwsys_shared_forward_ldpath) - strlen(driver) - 1);
strncat(kwsys_shared_forward_ldpath, kwsys_shared_forward_path_sep, KWSYS_SHARED_FORWARD_MAXPATH - strlen(kwsys_shared_forward_ldpath) - strlen(kwsys_shared_forward_path_sep) - 1);
// Checks
//fprintf(stdout, "kwsys_shared_forward_ldpath = %s\n",
// kwsys_shared_forward_ldpath);
return 1;
}
int choose_driver(const char *this_exe_path, const char *driver, int print)
{
if (driver == NULL || driver[0] == '\0')
{
return 0;
}
if (strcmp(driver, "mesa") == 0)
{
// here we don't specify any GALLIUM_DRIVER and let user
// setup the environment on their own.
append_driver_to_ldpath(this_exe_path, "mesa");
}
if (strcmp(driver, "mesa-llvm") == 0)
{
if (print == 1)
{
printf("GALLIUM_DRIVER=llvmpipe\n");
}
setenv("GALLIUM_DRIVER", "llvmpipe", /*overwrite=*/ 1);
append_driver_to_ldpath(this_exe_path, "mesa");
}
else if (strcmp(driver, "mesa-swr-avx") == 0 ||
strcmp(driver, "mesa-swr-avx2") == 0 ||
strcmp(driver, "mesa-swr") == 0)
{
if (print == 1)
{
printf("GALLIUM_DRIVER=swr\n");
}
setenv("GALLIUM_DRIVER", "swr", /*overwrite=*/ 1);
append_driver_to_ldpath(this_exe_path, "mesa");
}
return 0;
}
#define MAX_DRIVER_CHOICE 32
int main(int argc, char** argv)
{
int i = 0;
int true_argc = 0;
char **true_argv = malloc((argc + 1) * sizeof(char*));
int result = 0;
FILE *driver_cache = NULL;
char driver_choice[MAX_DRIVER_CHOICE] = { 0 };
char driver_cache_path[KWSYS_SHARED_FORWARD_MAXPATH] = { 0 };
int print = 0;
true_argv[argc] = NULL;
// Check for site-wide config first
get_driver_cache_site_path(argv[0], driver_cache_path);
driver_cache = fopen(driver_cache_path, "r");
if (driver_cache)
{
if (fgets(driver_choice, sizeof(driver_choice), driver_cache) == 0)
{
driver_choice[0] = 0;
}
fclose(driver_cache);
}
// If there is a user config, override the site config
get_driver_cache_user_path(driver_cache_path);
driver_cache = fopen(driver_cache_path, "r");
if (driver_cache)
{
if (fgets(driver_choice, sizeof(driver_choice), driver_cache) == 0)
{
driver_choice[0] = 0;
}
fclose(driver_cache);
}
// Check for a newline in the driver name
char *newline = strchr(driver_choice, '\n');
if (newline)
{
*newline = '\0';
}
// Check for single-run driver specification; forward all other args
for (; i < argc; ++i)
{
if (strcmp(argv[i], "--native") == 0)
{
driver_choice[0] = '\0';
}
else if (strcmp(argv[i], "--mesa-llvm") == 0 ||
strcmp(argv[i], "--mesa-swr-avx") == 0 ||
strcmp(argv[i], "--mesa-swr-avx2") == 0 ||
strcmp(argv[i], "--mesa-swr") == 0 ||
strcmp(argv[i], "--mesa") == 0)
{
snprintf(driver_choice, MAX_DRIVER_CHOICE, "%s", argv[i] + 2);
}
else
{
if (strcmp(argv[i], "--print") == 0)
{
print = 1;
}
true_argv[true_argc] = argv[i];
true_argc++;
}
}
true_argv[true_argc] = NULL;
choose_driver(argv[0], driver_choice, print);
result = vtksys_shared_forward_to_real(true_argc, true_argv);
free(true_argv);
return result;
}
function (paraview_add_executable name)
# Set up rpaths
set(CMAKE_BUILD_RPATH_USE_ORIGIN 1)
if (UNIX AND NOT APPLE)
file(RELATIVE_PATH _paraview_client_relpath
"/prefix/${CMAKE_INSTALL_BINDIR}"
"/prefix/${CMAKE_INSTALL_LIBDIR}")
set(_paraview_client_origin_rpath
"$ORIGIN/${_paraview_client_relpath}")
list(APPEND CMAKE_INSTALL_RPATH
"${_paraview_client_origin_rpath}")
endif()
add_executable("${name}" ${ARGN})
add_executable("ParaView::${name}" ALIAS "${name}")
......@@ -25,50 +38,9 @@ function (paraview_add_executable name)
JOB_POOL_LINK "${paraview_exe_job_link_pool}")
endif ()
set(_paraview_launcher_RUNTIME_DESTINATION
"${CMAKE_INSTALL_BINDIR}")
set(_paraview_launcher_LIBRARY_DESTINATION
"${CMAKE_INSTALL_LIBDIR}")
install(
TARGETS "${name}"
DESTINATION bin
DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT runtime
EXPORT ParaView)
# set up forwarding executables
set(_paraview_launcher_destination "${_paraview_launcher_RUNTIME_DESTINATION}")
if (BUILD_SHARED_LIBS AND UNIX AND NOT APPLE)
set(_paraview_launcher_build_dir "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
set(_paraview_launcher_build_path "\"${_paraview_launcher_build_dir}\"")
set(_paraview_launcher_install_dir "../${_paraview_launcher_LIBRARY_DESTINATION}")
set(_paraview_launcher_install_path "\"${_paraview_launcher_install_dir}\"")
set(_paraview_launcher_NAME ${name})
set(_executable_cmake_dir "${ParaView_SOURCE_DIR}/CMake")
configure_file(
"${_executable_cmake_dir}/paraview_launcher.c.in"
"${CMAKE_CURRENT_BINARY_DIR}/${name}_launcher.c"
@ONLY)
add_executable("${name}-launcher"
"${CMAKE_CURRENT_BINARY_DIR}/${name}_launcher.c")
target_include_directories("${name}-launcher"
PRIVATE
"$<TARGET_PROPERTY:VTK::vtksys,INTERFACE_INCLUDE_DIRECTORIES>")
set_target_properties("${name}-launcher"
PROPERTIES
OUTPUT_NAME "${name}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/launcher")
add_dependencies("${name}-launcher"
"${name}")
install(
TARGETS "${name}-launcher"
RUNTIME DESTINATION "${_paraview_launcher_RUNTIME_DESTINATION}")
set(_paraview_launcher_destination "${_paraview_launcher_LIBRARY_DESTINATION}")
endif()
install(
TARGETS "${name}"
# TODO - need export targets?
RUNTIME DESTINATION "${_paraview_launcher_destination}")
endfunction ()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment