# Common functions and settings for LSL # Dummy function that should be called after find_package(LSL) # Does nothing at the moment, but the entire code below should be within this # function so it's not executed by accident macro(LSLAPP_Setup_Boilerplate) endmacro() message(STATUS "Included LSL CMake helpers, rev. 12, ${CMAKE_CURRENT_LIST_DIR}") option(LSL_DEPLOYAPPLIBS "Copy library dependencies (at the moment Qt + liblsl) to the installation dir" ON) # set build type and default install dir if not done already if(NOT CMAKE_BUILD_TYPE) message(STATUS "CMAKE_BUILD_TYPE was default initialized to Release") set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE) endif() if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) # OR ((${MSVC_VERSION} GREATER_EQUAL 1910) AND ("${CMAKE_GENERATOR}" STREQUAL "Ninja")) set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Where to put redistributable binaries" FORCE) message(WARNING "CMAKE_INSTALL_PREFIX default initialized to ${CMAKE_INSTALL_PREFIX}") endif() # Generate folders for IDE targets (e.g., VisualStudio solutions) set_property(GLOBAL PROPERTY USE_FOLDERS ON) # Set runtime path, i.e. where shared libs are searched relative to the exe if(APPLE) list(APPEND CMAKE_INSTALL_RPATH "@executable_path/../LSL/lib") list(APPEND CMAKE_INSTALL_RPATH "@executable_path/../lib") list(APPEND CMAKE_INSTALL_RPATH "@executable_path/") elseif(UNIX) list(APPEND CMAKE_INSTALL_RPATH "\$ORIGIN/../LSL/lib:\$ORIGIN/../lib/:\$ORIGIN") endif() set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "limited configs" FORCE) # Qt5 set(CMAKE_INCLUDE_CURRENT_DIR ON) # Because the ui_mainwindow.h file. # Boost #SET(Boost_DEBUG OFF) #Switch this and next to ON for help debugging Boost problems. #SET(Boost_DETAILED_FAILURE_MSG ON) if(WIN32) set(Boost_USE_STATIC_LIBS ON) endif() # LSL functions, mostly for Apps # installs additional files (configuration etc.) function(installLSLAuxFiles target) get_target_property(is_bundle ${target} MACOSX_BUNDLE) set(destdir ${PROJECT_NAME}) if(LSL_UNIXFOLDERS) set(destdir bin/) elseif(is_bundle AND APPLE) set(destdir ${destdir}/${target}.app/Contents/MacOS) endif() if("${ARGV1}" STREQUAL "directory") install(DIRECTORY ${ARGV2} DESTINATION ${destdir} COMPONENT "${PROJECT_NAME}") else() install(FILES ${ARGN} DESTINATION ${destdir} COMPONENT "${PROJECT_NAME}") endif() endfunction() # installLSLApp: adds the specified target to the install list and # add some quality-of-life improvements for Qt executables function(installLSLApp target) get_target_property(TARGET_LIBRARIES ${target} LINK_LIBRARIES) string(REGEX MATCH ";Qt5::" qtapp ";${TARGET_LIBRARIES}") if(qtapp) # Enable automatic compilation of .cpp->.moc, xy.ui->ui_xy.h and resource files set_target_properties(${target} PROPERTIES AUTOMOC ON AUTOUIC ON AUTORCC ON ) endif() # add start menu shortcut if supported by installer set_property(INSTALL "${PROJECT_NAME}/$" PROPERTY CPACK_START_MENU_SHORTCUTS "${target}") if(LSL_UNIXFOLDERS) include(GNUInstallDirs) set(lsldir "\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") else() set(CMAKE_INSTALL_BINDIR ${PROJECT_NAME}) set(CMAKE_INSTALL_LIBDIR ${PROJECT_NAME}) set(lsldir "\${CMAKE_INSTALL_PREFIX}/LSL") endif() set_property(GLOBAL APPEND PROPERTY "LSLDEPENDS_${PROJECT_NAME}" liblsl) install(TARGETS ${target} COMPONENT ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}) # skip copying libraries if disabled or on Linux if(NOT LSL_DEPLOYAPPLIBS OR UNIX AND NOT APPLE) return() endif() # skip exe deployment for libraries get_target_property(target_type ${target} TYPE) if(NOT target_type STREQUAL "EXECUTABLE") return() endif() # Some Windows installers have problems with several components having the same file, # so libs shared between targets are copied into the SHAREDLIBCOMPONENT component if set if(NOT SHAREDLIBCOMPONENT) set(SHAREDLIBCOMPONENT ${target}) endif() # Copy lsl library for WIN32 or MacOS. # On Mac, dylib is only needed for macdeployqt and for non bundles when not using system liblsl. # Copy anyway, and fixup_bundle can deal with the dylib already being present. if(NOT TARGET liblsl AND NOT LSL_UNIXFOLDERS) install(FILES $ DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${SHAREDLIBCOMPONENT}) endif() if(APPLE AND NOT qtapp) # fixup_bundle appears to be broken for Qt apps. Use only for non-Qt. get_target_property(target_is_bundle ${target} MACOSX_BUNDLE) if(target_is_bundle) install(CODE " include(BundleUtilities) set(BU_CHMOD_BUNDLE_ITEMS ON) fixup_bundle(\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/${target}.app \"\" \"${lsldir}\") " COMPONENT ${PROJECT_NAME} ) endif() endif() # skip the rest if qt doesn't need to be deployed if(NOT qtapp) return() endif() cmake_minimum_required(VERSION 3.15) # generator expressions in install(CODE) if(WIN32) findQtInstallationTool("windeployqt") install(CODE " message (STATUS \"Running windeployqt on $\") execute_process( COMMAND \"${QT_DEPLOYQT_EXECUTABLE}\" --no-translations --no-system-d3d-compiler --no-opengl-sw --no-virtualkeyboard --no-compiler-runtime --dry-run --list mapping \"$\" OUTPUT_VARIABLE output OUTPUT_STRIP_TRAILING_WHITESPACE ) file(TO_CMAKE_PATH \"\${output}\" output) # convert slashes separate_arguments(_files WINDOWS_COMMAND \${output}) while(_files) list(POP_FRONT _files _src) list(POP_FRONT _files _dest) get_filename_component(_dest \${_dest} DIRECTORY RELATIVE) file(COPY \${_src} DESTINATION \${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/\${_dest}) endwhile()" COMPONENT ${SHAREDLIBCOMPONENT}) elseif(APPLE) # It should be enough to call fixup_bundle (see below), # but this fails to install qt plugins (cocoa). # Use macdeployqt instead (but this is bad at grabbing lsl dylib, so we did that above) findQtInstallationTool("macdeployqt") install(CODE " if(\${CMAKE_INSTALL_CONFIG_NAME} STREQUAL Debug) set(debug 1) endif() message(STATUS \"Running Qt Deploy Tool for $...\") execute_process(COMMAND echo \"${QT_DEPLOYQT_EXECUTABLE}\" $ -verbose=1 $<$:--use-debug-libs> ) ") endif() endfunction() function(findQtInstallationTool qtdeploytoolname) if(QT_DEPLOYQT_EXECUTABLE) return() endif() get_target_property(QT_QMAKE_EXE Qt5::qmake IMPORTED_LOCATION) get_filename_component(QT_BIN_DIR "${QT_QMAKE_EXE}" DIRECTORY) find_program (QT_DEPLOYQT_EXECUTABLE ${qtdeploytoolname} HINTS "${QT_BIN_DIR}") if (QT_DEPLOYQT_EXECUTABLE) message(STATUS "Qt deploy tool found at ${QT_DEPLOYQT_EXECUTABLE}") else() message(WARNING "Qt deploy tool wasn't found, installing ${PROJECT_NAME} will fail!") return() endif() endfunction() # default paths, versions and magic to guess it on windows # guess default paths for Windows / VC # Boost autoconfig: # Original author: Ryan Pavlik ") set(CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS ON) set(CPACK_DEB_COMPONENT_INSTALL ON) set(CPACK_DEBIAN_PACKAGE_PRIORITY optional) set(CPACK_DEBIAN_LIBLSL_PACKAGE_SHLIBDEPS ON) set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON) # include distribution name (e.g. trusty or xenial) in the file name find_program(LSB_RELEASE lsb_release) execute_process(COMMAND ${LSB_RELEASE} -cs OUTPUT_VARIABLE LSB_RELEASE_CODENAME OUTPUT_STRIP_TRAILING_WHITESPACE RESULT_VARIABLE LSB_RELEASE_RESULT ) if(LSB_RELEASE_RESULT) set(CPACK_DEBIAN_PACKAGE_RELEASE ${LSB_RELEASE_CODENAME}) endif() set(LSL_OS "Linux${lslplatform}-${LSB_RELEASE_CODENAME}") endif() set(CPACK_GENERATOR ${LSL_CPACK_DEFAULT_GEN} CACHE STRING "CPack pkg type(s) to generate") get_cmake_property(CPACK_COMPONENTS_ALL COMPONENTS) foreach(component ${CPACK_COMPONENTS_ALL}) string(TOUPPER ${component} COMPONENT) set(LSL_CPACK_FILENAME "${component}-${PROJECT_VERSION}-${LSL_OS}") get_property(LSLDEPENDS GLOBAL PROPERTY "LSLDEPENDS_${component}") if(LSLDEPENDS) list(REMOVE_DUPLICATES LSLDEPENDS) set("CPACK_COMPONENT_${COMPONENT}_DEPENDS" ${LSLDEPENDS}) endif() set("CPACK_DEBIAN_${COMPONENT}_PACKAGE_NAME" ${component}) set("CPACK_DEBIAN_${COMPONENT}_FILE_NAME" "${LSL_CPACK_FILENAME}.deb") set("CPACK_ARCHIVE_${COMPONENT}_FILE_NAME" ${LSL_CPACK_FILENAME}) #set(CPACK_DEBIAN_${component}_FILE_NAME "${FILENAME}.deb") endforeach() message(STATUS "Installing Components: ${CPACK_COMPONENTS_ALL}") include(CPack) endif() endmacro()