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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
###############################################################################
# Builds BornAgain/GUI main executable
###############################################################################
if(WIN32)
set(executable_name BornAgain)
else()
set(executable_name bornagain)
endif()
set(source_files main.cpp AppOptions.cpp)
# -----------------------------------------------------------------------------
# Qt configuration
# -----------------------------------------------------------------------------
set(CMAKE_AUTOMOC ON)
# -----------------------------------------------------------------------------
# executable icons
# -----------------------------------------------------------------------------
if(WIN32)
set(system_addons bornagain.rc)
if(NOT win32_console)
set(executable_options WIN32)
endif()
endif()
if(APPLE)
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/BornAgain.icns
PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
endif()
# -----------------------------------------------------------------------------
# executable
# -----------------------------------------------------------------------------
add_executable(${executable_name}
${executable_options}
${source_files}
${system_addons})
# -----------------------------------------------------------------------------
# dependencies
# -----------------------------------------------------------------------------
target_link_libraries(${executable_name} PRIVATE BornAgainGUI)
target_include_directories(${executable_name} PRIVATE ${CMAKE_SOURCE_DIR})
# -----------------------------------------------------------------------------
# extra target properties
# -----------------------------------------------------------------------------
if(BORNAGAIN_PYTHON)
target_compile_definitions(${executable_name} PRIVATE -DBORNAGAIN_PYTHON)
endif()
if(WIN32)
set_target_properties(${executable_name} PROPERTIES LINK_OPTIONS /ENTRY:mainCRTStartup)
if(win32_console)
set_target_properties(${executable_name} PROPERTIES COMPILE_DEFINITIONS _CONSOLE)
endif()
endif()
# -----------------------------------------------------------------------------
# runtime library paths
# -----------------------------------------------------------------------------
# See our deployment paper (Nejati et al 2024) for explanation.
if(LINUX)
# NOTE: RPATH must be set also in `GUI/CMakeLists.txt`
# Add proper RPATHs as hints to load the dependencies at run-time
# NOTE: Unlike `RUNPATH`, `RPATH` is searched for transitive dependencies;
# ie. paths in RPATH will be considered for everything that is
# dynamically loaded, even dependencies of dependencies.
# see <https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=847298>
set(link_flags "-Wl,--disable-new-dtags,-rpath,\$ORIGIN:\$ORIGIN/../lib:\$ORIGIN/../${destination_lib}")
set_target_properties(${executable_name} PROPERTIES LINK_FLAGS ${link_flags})
elseif(APPLE)
set(link_flags "-Wl,-rpath,@loader_path/../lib/")
set_target_properties(${executable_name} PROPERTIES LINK_FLAGS ${link_flags})
endif()
# -----------------------------------------------------------------------------
# installation section
# -----------------------------------------------------------------------------
install(TARGETS ${executable_name} RUNTIME DESTINATION ${destination_bin}
COMPONENT Applications)
set(image_files
${CMAKE_CURRENT_SOURCE_DIR}/BornAgain.ico
${CMAKE_CURRENT_SOURCE_DIR}/BornAgain.icns
${CMAKE_SOURCE_DIR}/GUI/images/BornAgain_48x48.png
${CMAKE_SOURCE_DIR}/GUI/images/BornAgain_64x64.png)
install(FILES ${image_files} DESTINATION ${destination_images} COMPONENT Applications)
# -----------------------------------------------------------------------------
# system dependent installation
# -----------------------------------------------------------------------------
if(WIN32)
message(STATUS "Configuring the GUI package")
foreach(comp ${QtComponents})
set(QtComp Qt6::${comp})
get_target_property(dll ${QtComp} LOCATION_Release)
get_property(dll TARGET ${QtComp} PROPERTY LOCATION_Release)
install(FILES ${dll} DESTINATION ${destination_lib} COMPONENT WinLibraries)
message(STATUS "Install Qt lib ${QtComp} (${dll})")
endforeach()
# extract Qt root-dir
# 'C:/Qt/6.2.4/msvc2019_64/lib/cmake/Qt6' => 'C:/Qt/6.2.4/msvc2019_64'
file(TO_CMAKE_PATH "${Qt_DIR}" qt_dir_str)
install(FILES ${Qt_DIR}/bin/opengl32sw.dll
DESTINATION ${destination_lib}
COMPONENT WinLibraries)
install(FILES ${Qt_PLUGINS_DIR}/platforms/qwindows.dll
DESTINATION bin/platforms
COMPONENT WinLibraries)
install(FILES ${Qt_PLUGINS_DIR}/iconengines/qsvgicon.dll
DESTINATION bin/iconengines
COMPONENT WinLibraries)
install(FILES ${Qt_PLUGINS_DIR}/imageformats/qjpeg.dll ${Qt_PLUGINS_DIR}/imageformats/qsvg.dll
DESTINATION bin/imageformats
COMPONENT WinLibraries)
set(QT_VISTA_STYLE ${Qt_PLUGINS_DIR}/styles/qwindowsvistastyle.dll)
if(EXISTS ${QT_VISTA_STYLE})
install(FILES ${QT_VISTA_STYLE} DESTINATION bin/styles COMPONENT WinLibraries)
else()
message(AUTHOR_WARNING File ${QT_VISTA_STYLE} not found.)
endif()
unset(QT_VISTA_STYLE)
endif()
if(LINUX)
set(LINUXPKG_MAIN_EXE "${CMAKE_BINARY_DIR}/bin/${executable_name}")
set(LINUXPKG_FRAMEWORK_DEST "${destination_lib}")
configure_file(${CMAKE_SOURCE_DIR}/deploy/linux/adjust_pkg_linux.sh.in
${BUILD_VAR_DIR}/adjust_pkg_linux.sh @ONLY)
endif()
# execute package-fixing script before CPack builds the final package file
#configure_file(
# ${CMAKE_SOURCE_DIR}/cmake/configurables/FixPack.cmake.in
# ${BUILD_VAR_DIR}/FixPack.cmake @ONLY)
#install(SCRIPT ${BUILD_VAR_DIR}/FixPack.cmake)
|