-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMdtPostInstall.cmake.in
115 lines (106 loc) · 4.94 KB
/
MdtPostInstall.cmake.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#.rst:
# MdtPostInstall
# --------------
#
# Run some tasks that can be done only once Mdt library is installed.
#
# This script has only sense when using a Qt library that is installed
# on a location not known by the environnment (LD_LIBRARY_PATH, PATH).
#
# On Linux, path to the used Qt installation is set to the RPATH of Mdt libraries.
# On Windows, mdtenv.bat script is generated.
# For all platforms, QtPath.conf is also created.
#
# Set some CMake variable that are not available in script mode
set(CMAKE_FIND_LIBRARY_PREFIXES "@CMAKE_FIND_LIBRARY_PREFIXES@")
set(CMAKE_FIND_LIBRARY_SUFFIXES "@CMAKE_FIND_LIBRARY_SUFFIXES@")
set(CMAKE_CXX_COMPILER "@CMAKE_CXX_COMPILER@")
# On Linux, we will need patchelf later
if(UNIX AND NOT APPLE)
find_program(PATCHELF_EXECUTABLE NAMES patchelf)
if(NOT EXISTS "${PATCHELF_EXECUTABLE}")
message(FATAL_ERROR "Could not find patchelf")
endif()
endif()
# Check that we are in a Mdt installation directory and set Mdt path
# Note: add_library(), which may be used by find_package(), is not scriptable
set(MDT_PATH "${CMAKE_CURRENT_LIST_DIR}")
set(MDT_LIB_PATH "${MDT_PATH}/lib")
if(NOT EXISTS "${MDT_LIB_PATH}")
message(FATAL_ERROR "This script must be located at the root of the Mdt installation (could not find lib directory)")
endif()
find_library(MDT_TEST_LIBRARY NAMES Mdt0Application_Core PATHS "${MDT_LIB_PATH}" NO_DEFAULT_PATH)
if(NOT EXISTS "${MDT_TEST_LIBRARY}")
message(FATAL_ERROR "This script must be located at the root of the Mdt installation (could not find Mdt0Application_Core library)")
endif()
set(MDT_BIN_PATH "${MDT_PATH}/bin")
if(NOT EXISTS "${MDT_BIN_PATH}")
message(FATAL_ERROR "This script must be located at the root of the Mdt installation (could not find bin directory)")
endif()
# Check that QT_PREFIX_PATH was set and that it points to a Qt installation
if(NOT QT_PREFIX_PATH)
message(FATAL_ERROR "QT_PREFIX_PATH is missing, please specify it with -D QT_PREFIX_PATH=\"/path/to/Qt\" (Example: -D QT_PREFIX_PATH=\"/opt/Qt5/5.9.1/gcc_64\")")
endif()
get_filename_component(QT_PATH "${QT_PREFIX_PATH}" ABSOLUTE)
set(QT_LIB_PATH "${QT_PATH}/lib")
if(NOT EXISTS "${QT_LIB_PATH}")
message(FATAL_ERROR "Specified QT_PREFIX_PATH is not a Qt installation (could not find lib directory)")
endif()
find_library(QT_TEST_LIBRARY NAMES Qt5Core PATHS "${QT_LIB_PATH}" NO_DEFAULT_PATH)
if(NOT EXISTS "${QT_TEST_LIBRARY}")
message(FATAL_ERROR "Specified QT_PREFIX_PATH is not a Qt installation (could not find Qt5Core library)")
endif()
set(QT_BIN_PATH "${QT_PATH}/bin")
if(NOT EXISTS "${QT_BIN_PATH}")
message(FATAL_ERROR "Specified QT_PREFIX_PATH is not a Qt installation (could not find bin directory)")
endif()
find_program(QMAKE_EXECUTABLE NAMES qmake PATHS "${QT_BIN_PATH}" NO_DEFAULT_PATH)
if(NOT EXISTS "${QMAKE_EXECUTABLE}")
message(FATAL_ERROR "Specified QT_PREFIX_PATH is not a Qt installation (could not find qmake)")
endif()
# On Linux, patch RPATH of Mdt libraries and executables to find Qt
if(UNIX AND NOT APPLE)
message(STATUS "Patching Mdt libraries")
file(GLOB mdt_libraries LIST_DIRECTORIES false "${MDT_LIB_PATH}/libMdt*.so.[0-9].[0-9].[0-9]")
foreach(mdt_library ${mdt_libraries})
set(rpath "\$ORIGIN:${QT_LIB_PATH}")
execute_process(COMMAND "${PATCHELF_EXECUTABLE}" "--set-rpath" "${rpath}" "${mdt_library}" OUTPUT_VARIABLE rpath_raw RESULT_VARIABLE retval ERROR_VARIABLE error_string)
if( NOT (${retval} EQUAL 0) )
message(FATAL_ERROR "Running patchelf failed: ${error_string}")
endif()
endforeach()
message(STATUS "Patching Mdt executables")
file(GLOB mdt_executables LIST_DIRECTORIES false "${MDT_BIN_PATH}/*")
foreach(mdt_executable ${mdt_executables})
set(rpath "\$ORIGIN/../lib:${QT_LIB_PATH}")
execute_process(COMMAND "${PATCHELF_EXECUTABLE}" "--set-rpath" "${rpath}" "${mdt_executable}" OUTPUT_VARIABLE rpath_raw RESULT_VARIABLE retval ERROR_VARIABLE error_string)
if( NOT (${retval} EQUAL 0) )
message(FATAL_ERROR "Running patchelf failed: ${error_string}")
endif()
endforeach()
endif()
# Write the QtPrefixPath file
message(STATUS "Writing QtPrefixPath.txt")
file(WRITE "${MDT_PATH}/QtPrefixPath.txt" "${QT_PATH}")
# On Windows, find the compiler provided by Qt
if(WIN32)
get_filename_component(COMPILER_NAME "${CMAKE_CXX_COMPILER}" NAME)
find_program(
COMPILER_BIN_DIR
NAMES "${COMPILER_NAME}"
PATHS "${QT_PREFIX_PATH}/../../Tools"
PATH_SUFFIXES "mingw530_32/bin" "mingw531_32/bin"
)
endif(WIN32)
# On Windows, write mdtenv.bat
if(WIN32)
# Generate env script
string(REPLACE "/" "\\" compiler_bin_dir_win "${COMPILER_BIN_DIR}")
string(REPLACE "/" "\\" qt_bin_dir_win "${QT_BIN_PATH}")
string(REPLACE "/" "\\" mdt_bin_dir_win "${MDT_BIN_PATH}")
set(env_script_content "\@echo off\r\nset PATH=${compiler_bin_dir_win};${qt_bin_dir_win};${mdt_bin_dir_win}")
# Write env script
message(STATUS "Writing mdtenv.bat")
set(env_script_path "${MDT_PATH}/mdtenv.bat")
file(WRITE "${env_script_path}" "${env_script_content};%PATH%")
endif(WIN32)