@@ -46,6 +46,16 @@ SOURCE_GROUP("Shaders" FILES ${SHADERS_LIBRARY_FILES})
4646
4747cxx_executable_with_flags(${VIEWER_NAME} "Apps" "${cxx_default} " "MVS;glad::glad;${GLFW_STATIC_LIBRARIES} ;${glfw3_LIBRARY} ;${GLFW3_LIBRARY} ;glfw;imgui::imgui" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H} )
4848
49+ # Build the Viewer as a GUI application on platforms that support it so
50+ # launching from the desktop does not open or attach a console/terminal.
51+ if (WIN32 )
52+ # On Windows: tell CMake/Visual Studio to build a Win32 GUI executable (no console)
53+ set_target_properties (${VIEWER_NAME} PROPERTIES WIN32_EXECUTABLE TRUE )
54+ elseif (APPLE )
55+ # On macOS: create a macOS app bundle so it's treated as a GUI app by Finder
56+ set_target_properties (${VIEWER_NAME} PROPERTIES MACOSX_BUNDLE TRUE )
57+ endif ()
58+
4959# Link portable-file-dialogs if available
5060if (portable-file-dialogs_FOUND)
5161 target_link_libraries (${VIEWER_NAME} PRIVATE portable-file-dialogs::portable-file-dialogs)
@@ -56,7 +66,76 @@ IF(CMAKE_VERSION VERSION_GREATER_EQUAL 3.16.0)
5666 TARGET_PRECOMPILE_HEADERS(${VIEWER_NAME} PRIVATE "Common.h" )
5767endif ()
5868
69+ if (APPLE )
70+ # Configure Info.plist from the templates directory and attach it to the
71+ # macOS bundle. Use the project's OpenMVS version variables and the
72+ # Viewer icon basename for the bundle icon.
73+ set (INFO_PLIST_IN "${CMAKE_CURRENT_SOURCE_DIR} /templates/Info.plist.in" )
74+ set (ICON_SRC "${CMAKE_CURRENT_SOURCE_DIR} /Viewer.icns" )
75+ get_filename_component (ICON_NAME "${ICON_SRC} " NAME_WE )
76+ # Copy the icns into the build dir and add it to the bundle resources
77+ configure_file (${ICON_SRC} ${CMAKE_CURRENT_BINARY_DIR} /Viewer.icns COPYONLY )
78+ # Add the icns as a resource so CMake includes it in the built .app
79+ target_sources (${VIEWER_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR} /Viewer.icns" )
80+ set_source_files_properties ("${CMAKE_CURRENT_BINARY_DIR} /Viewer.icns" PROPERTIES MACOSX_PACKAGE_LOCATION "Resources" )
81+ # Tell CMake which icon file to use for the bundle (filename only)
82+ set_target_properties (${VIEWER_NAME} PROPERTIES MACOSX_BUNDLE_ICON_FILE "${ICON_NAME} .icns" )
83+ configure_file (${INFO_PLIST_IN} ${CMAKE_CURRENT_BINARY_DIR} /Info.plist @ONLY)
84+ set_target_properties (${VIEWER_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_BINARY_DIR} /Info.plist" )
85+ endif ()
86+
87+ if (LINUX)
88+ # Prepare a Linux desktop entry for better integration. Exec path is configured
89+ # to the installed binary location (prefix + install bin dir). Install the
90+ # resulting .desktop file into share/applications so desktop environments pick it up.
91+ set (DESKTOP_IN "${CMAKE_CURRENT_SOURCE_DIR} /templates/openMVS-Viewer.desktop.in" )
92+ set (EXEC_PATH "${CMAKE_INSTALL_PREFIX} /${INSTALL_BIN_DIR} /${VIEWER_NAME} " )
93+ get_filename_component (ICON_NAME "${CMAKE_CURRENT_SOURCE_DIR} /Viewer.svg" NAME_WE )
94+ # Register both .mvs and .dmap MIME types so desktop environments treat
95+ # both as owned by the OpenMVS Viewer. openmvs-mime.xml.in defines both
96+ # application/x-openmvs-mvs and application/x-openmvs-dmap.
97+ set (MIME_TYPE "application/x-openmvs-mvs;application/x-openmvs-dmap" )
98+ configure_file (${DESKTOP_IN} ${CMAKE_CURRENT_BINARY_DIR} /openMVS-Viewer.desktop @ONLY)
99+ INSTALL (FILES "${CMAKE_CURRENT_BINARY_DIR} /openMVS-Viewer.desktop"
100+ DESTINATION "share/applications" COMPONENT desktop)
101+ # Install an SVG icon into hicolor icon theme (scalable) if present
102+ INSTALL (FILES "${CMAKE_CURRENT_SOURCE_DIR} /Viewer.svg"
103+ DESTINATION "share/icons/hicolor/scalable/apps" COMPONENT desktop)
104+ # Install shared-mime-info XML so the system knows about .mvs files, then
105+ # update the MIME database so the desktop file association works immediately.
106+ set (MIME_IN "${CMAKE_CURRENT_SOURCE_DIR} /templates/openmvs-mime.xml.in" )
107+ configure_file (${MIME_IN} ${CMAKE_CURRENT_BINARY_DIR} /openmvs-mime.xml @ONLY)
108+ INSTALL (FILES "${CMAKE_CURRENT_BINARY_DIR} /openmvs-mime.xml"
109+ DESTINATION "share/mime/packages" COMPONENT desktop)
110+ FIND_PROGRAM (MIME_UPDATE_CMD update-mime-database)
111+ if (MIME_UPDATE_CMD)
112+ # run update-mime-database at install time (best effort)
113+ INSTALL (CODE "execute_process(COMMAND ${MIME_UPDATE_CMD} \" ${CMAKE_INSTALL_PREFIX} /share/mime\" RESULT_VARIABLE _res) if(NOT _res EQUAL 0) message(WARNING \" update-mime-database failed: \$ {_res}\" ) endif()" )
114+ endif ()
115+ endif ()
116+
117+ if (WIN32 )
118+ # Configure a Windows registry template for packagers/installers (manual import)
119+ set (REG_IN "${CMAKE_CURRENT_SOURCE_DIR} /templates/Viewer-fileassoc.reg.in" )
120+ configure_file (${REG_IN} ${CMAKE_CURRENT_BINARY_DIR} /Viewer-fileassoc.reg @ONLY)
121+ INSTALL (FILES "${CMAKE_CURRENT_BINARY_DIR} /Viewer-fileassoc.reg"
122+ DESTINATION "share/doc/${VIEWER_NAME} " COMPONENT doc )
123+ endif ()
124+
59125# Install
60- INSTALL (TARGETS ${VIEWER_NAME}
61- EXPORT OpenMVSTargets
62- RUNTIME DESTINATION "${INSTALL_BIN_DIR} " COMPONENT bin)
126+ if (APPLE )
127+ # When installing a MACOSX_BUNDLE target, CMake requires a BUNDLE DESTINATION.
128+ # Install the .app bundle into the same bin install directory variable the project uses.
129+ INSTALL (TARGETS ${VIEWER_NAME}
130+ EXPORT OpenMVSTargets
131+ BUNDLE DESTINATION "${INSTALL_BIN_DIR} "
132+ RUNTIME DESTINATION "${INSTALL_BIN_DIR} " COMPONENT bin)
133+ INSTALL (FILES "${CMAKE_CURRENT_BINARY_DIR} /Info.plist"
134+ DESTINATION "${INSTALL_BIN_DIR} /${VIEWER_NAME} .app/Contents" COMPONENT bin)
135+ INSTALL (FILES "${CMAKE_CURRENT_SOURCE_DIR} /Viewer.icns"
136+ DESTINATION "${INSTALL_BIN_DIR} /${VIEWER_NAME} .app/Contents/Resources" COMPONENT bin)
137+ else ()
138+ INSTALL (TARGETS ${VIEWER_NAME}
139+ EXPORT OpenMVSTargets
140+ RUNTIME DESTINATION "${INSTALL_BIN_DIR} " COMPONENT bin)
141+ endif ()
0 commit comments