"Fossies" - the Fresh Open Source Software Archive

Member "dbus-1.13.18/cmake/modules/Macros.cmake" (1 Jul 2020, 11191 Bytes) of package /linux/misc/dbus-1.13.18.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) CMake source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "Macros.cmake": 1.13.16_vs_1.13.18.

    1 option(DBUS_USE_WINE "set to 1 or ON to support running test cases with Wine" OFF)
    2 
    3 if(DBUS_BUILD_TESTS AND CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
    4     if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
    5         find_file(WINE_EXECUTABLE
    6             NAMES wine
    7             PATHS /usr/bin /usr/local/bin
    8             NO_CMAKE_FIND_ROOT_PATH
    9         )
   10         find_file(BINFMT_WINE_SUPPORT_FILE
   11             NAMES DOSWin wine Wine windows Windows
   12             PATHS /proc/sys/fs/binfmt_misc
   13             NO_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH
   14         )
   15         if(EXISTS BINFMT_WINE_SUPPORT_FILE)
   16             file(READ ${BINFMT_WINE_SUPPORT_FILE} CONTENT)
   17             if(${CONTENT} MATCHES "enabled")
   18                 set(HAVE_BINFMT_WINE_SUPPORT 1)
   19             endif()
   20         endif()
   21         if(WINE_EXECUTABLE)
   22             list(APPEND FOOTNOTES "NOTE: The requirements to run cross compiled applications on your host system are achieved. You may run 'make check'.")
   23         endif()
   24         if(NOT WINE_EXECUTABLE)
   25             list(APPEND FOOTNOTES "NOTE: You may install the Windows emulator 'wine' to be able to run cross compiled test applications.")
   26         endif()
   27         if(NOT HAVE_BINFMT_WINE_SUPPORT)
   28             list(APPEND FOOTNOTES "NOTE: You may activate binfmt_misc support for wine to be able to run cross compiled test applications directly.")
   29         endif()
   30     else()
   31         list(APPEND FOOTNOTES "NOTE: You will not be able to run cross compiled applications on your host system.")
   32     endif()
   33 
   34     # setup z drive required by wine
   35     set(Z_DRIVE_IF_WINE "z:")
   36     if(DBUS_USE_WINE AND WINE_EXECUTABLE)
   37         set(TEST_WRAPPER "${WINE_EXECUTABLE}")
   38     endif()
   39 endif()
   40 
   41 macro(add_test_executable _target _source)
   42     set(_sources "${_source}")
   43     if(WIN32 AND NOT MSVC)
   44         # avoid triggering UAC
   45         add_uac_manifest(_sources)
   46     endif()
   47     add_executable(${_target} ${_sources})
   48     target_link_libraries(${_target} ${ARGN})
   49     if(CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
   50         # run tests with binfmt_misc
   51         if(HAVE_BINFMT_WINE_SUPPORT)
   52             add_test(NAME ${_target} COMMAND $<TARGET_FILE:${_target}> --tap)
   53         else()
   54             add_test(NAME ${_target} COMMAND ${TEST_WRAPPER} ${Z_DRIVE_IF_WINE}$<TARGET_FILE:${_target}> --tap)
   55         endif()
   56     else()
   57         add_test(
   58             NAME ${_target}
   59             COMMAND $<TARGET_FILE:${_target}> --tap
   60             WORKING_DIRECTORY ${DBUS_TEST_WORKING_DIR}
   61         )
   62     endif()
   63     set(_env)
   64     list(APPEND _env "DBUS_SESSION_BUS_ADDRESS=")
   65     list(APPEND _env "DBUS_FATAL_WARNINGS=1")
   66     list(APPEND _env "DBUS_TEST_DAEMON=${DBUS_TEST_DAEMON}")
   67     list(APPEND _env "DBUS_TEST_DATA=${DBUS_TEST_DATA}")
   68     list(APPEND _env "DBUS_TEST_DBUS_LAUNCH=${DBUS_TEST_DBUS_LAUNCH}")
   69     list(APPEND _env "DBUS_TEST_EXEC=${DBUS_TEST_EXEC}")
   70     list(APPEND _env "DBUS_TEST_HOMEDIR=${DBUS_TEST_HOMEDIR}")
   71     list(APPEND _env "DBUS_TEST_UNINSTALLED=1")
   72     set_tests_properties(${_target} PROPERTIES ENVIRONMENT "${_env}")
   73 endmacro()
   74 
   75 macro(add_helper_executable _target _source)
   76     set(_sources "${_source}")
   77     if(WIN32 AND NOT MSVC)
   78         # avoid triggering UAC
   79         add_uac_manifest(_sources)
   80     endif()
   81     add_executable(${_target} ${_sources})
   82     target_link_libraries(${_target} ${ARGN})
   83 endmacro()
   84 
   85 macro(add_session_test_executable _target _source)
   86     set(_sources "${_source}")
   87     if(WIN32 AND NOT MSVC)
   88         # avoid triggering UAC
   89         add_uac_manifest(_sources)
   90     endif()
   91     add_executable(${_target} ${_sources})
   92     target_link_libraries(${_target} ${ARGN})
   93     add_test(NAME ${_target}
   94         COMMAND
   95         ${TEST_WRAPPER}
   96         ${DBUS_TEST_RUN_SESSION}
   97         --config-file=${DBUS_TEST_DATA}/valid-config-files/tmp-session.conf
   98         --dbus-daemon=${DBUS_TEST_DAEMON}
   99         ${Z_DRIVE_IF_WINE}$<TARGET_FILE:${_target}>
  100         --tap
  101         WORKING_DIRECTORY ${DBUS_TEST_WORKING_DIR}
  102     )
  103     set(_env)
  104     list(APPEND _env "DBUS_SESSION_BUS_PID=")
  105     list(APPEND _env "DBUS_SESSION_BUS_ADDRESS=")
  106     list(APPEND _env "DBUS_FATAL_WARNINGS=1")
  107     list(APPEND _env "DBUS_TEST_DAEMON=${DBUS_TEST_DAEMON}")
  108     list(APPEND _env "DBUS_TEST_DATA=${DBUS_TEST_DATA}")
  109     list(APPEND _env "DBUS_TEST_HOMEDIR=${DBUS_TEST_HOMEDIR}")
  110     set_tests_properties(${_target} PROPERTIES ENVIRONMENT "${_env}")
  111 endmacro()
  112 
  113 #
  114 # generate compiler flags from MSVC warning identifiers (e.g. '4114') or gcc warning keys (e.g. 'pointer-sign')
  115 #
  116 # @param target the variable name which will contain the warnings flags
  117 # @param warnings a string with space delimited warnings
  118 # @param disabled_warnings a string with space delimited disabled warnings
  119 # @param error_warnings a string with space delimited warnings which should result into compile errors
  120 #
  121 macro(generate_warning_cflags target warnings disabled_warnings error_warnings)
  122     if(DEBUG_MACROS)
  123         message("generate_warning_cflags got: ${warnings} - ${disabled_warnings} - ${error_warnings}")
  124     endif()
  125     if(MSVC)
  126         # level 1 is default
  127         set(enabled_prefix "/w1")
  128         set(error_prefix "/we")
  129         set(disabled_prefix "/wd")
  130     else()
  131         set(enabled_prefix "-W")
  132         set(error_prefix "-Werror=")
  133         set(disabled_prefix "-Wno-")
  134     endif()
  135 
  136     set(temp)
  137     string(REPLACE " " ";" warnings_list "${warnings}")
  138     foreach(warning ${warnings_list})
  139         string(STRIP ${warning} _warning)
  140         if(_warning)
  141             set(temp "${temp} ${enabled_prefix}${_warning}")
  142         endif()
  143     endforeach()
  144 
  145     string(REPLACE " " ";" disabled_warnings_list "${disabled_warnings}")
  146     foreach(warning ${disabled_warnings_list})
  147         string(STRIP ${warning} _warning)
  148         if(_warning)
  149             set(temp "${temp} ${disabled_prefix}${_warning}")
  150         endif()
  151     endforeach()
  152 
  153     string(REPLACE " " ";" error_warnings_list "${error_warnings}")
  154     foreach(warning ${error_warnings_list})
  155         string(STRIP ${warning} _warning)
  156         if(_warning)
  157             set(temp "${temp} ${error_prefix}${_warning}")
  158         endif()
  159     endforeach()
  160     set(${target} "${temp}")
  161     if(DEBUG_MACROS)
  162         message("generate_warning_cflags return: ${${target}}")
  163     endif()
  164 endmacro()
  165 
  166 #
  167 # Avoid triggering UAC
  168 #
  169 # This macro adds an rc file to _sources that is
  170 # linked to a target and prevents UAC from making
  171 # requests for administrator access.
  172 #
  173 macro(add_uac_manifest _sources)
  174     # 1 is the resource ID, ID_MANIFEST
  175     # 24 is the resource type, RT_MANIFEST
  176     # constants are used because of a bug in windres
  177     # see https://stackoverflow.com/questions/33000158/embed-manifest-file-to-require-administrator-execution-level-with-mingw32
  178     get_filename_component(UAC_FILE ${CMAKE_SOURCE_DIR}/tools/Win32.Manifest REALPATH)
  179     set(outfile ${CMAKE_BINARY_DIR}/disable-uac.rc)
  180     if(NOT EXISTS outfile)
  181         file(WRITE ${outfile} "1 24 \"${UAC_FILE}\"\n")
  182     endif()
  183     list(APPEND ${_sources} ${outfile})
  184 endmacro()
  185 
  186 macro(add_executable_version_info _sources _name)
  187     set(DBUS_VER_INTERNAL_NAME "${_name}")
  188     set(DBUS_VER_ORIGINAL_NAME "${DBUS_VER_INTERNAL_NAME}${CMAKE_EXECUTABLE_SUFFIX}")
  189     set(DBUS_VER_FILE_TYPE "VFT_APP")
  190     configure_file(${CMAKE_SOURCE_DIR}/dbus/versioninfo.rc.in ${CMAKE_CURRENT_BINARY_DIR}/versioninfo-${DBUS_VER_INTERNAL_NAME}.rc)
  191     # version info and uac manifest can be combined in a binary because they use different resource types
  192     list(APPEND ${_sources} ${CMAKE_CURRENT_BINARY_DIR}/versioninfo-${DBUS_VER_INTERNAL_NAME}.rc)
  193 endmacro()
  194 
  195 macro(add_library_version_info _sources _name)
  196     set(DBUS_VER_INTERNAL_NAME "${_name}")
  197     set(DBUS_VER_ORIGINAL_NAME "${DBUS_VER_INTERNAL_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}")
  198     set(DBUS_VER_FILE_TYPE "VFT_DLL")
  199     configure_file(${CMAKE_SOURCE_DIR}/dbus/versioninfo.rc.in ${CMAKE_CURRENT_BINARY_DIR}/versioninfo-${DBUS_VER_INTERNAL_NAME}.rc)
  200     # version info and uac manifest can be combined in a binary because they use different resource types
  201     list(APPEND ${_sources} ${CMAKE_CURRENT_BINARY_DIR}/versioninfo-${DBUS_VER_INTERNAL_NAME}.rc)
  202 endmacro()
  203 
  204 #
  205 # provide option with three states AUTO, ON, OFF
  206 #
  207 macro(add_auto_option _name _text _default)
  208     if(NOT DEFINED ${_name})
  209         set(${_name} ${_default} CACHE STRING "${_text}" FORCE)
  210     else()
  211         set(${_name} ${_default} CACHE STRING "${_text}")
  212     endif()
  213     set_property(CACHE ${_name} PROPERTY STRINGS AUTO ON OFF)
  214 endmacro()
  215 
  216 
  217 #
  218 # Ensure that if a tristate ON/OFF/AUTO feature is set to ON,
  219 # its requirements have been met. Fail with a fatal error if not.
  220 #
  221 # _name: name of a variable ENABLE_FOO representing a tristate ON/OFF/AUTO feature
  222 # _text: human-readable description of the feature enabled by _name, for the
  223 #        error message
  224 # _var: name of a variable representing a system property we checked for,
  225 #       such as an executable that must exist for the feature enabled by _name to work
  226 # _vartext: what we checked for, for the error message
  227 #
  228 macro(check_auto_option _name _text _var _vartext)
  229     set(_nameval ${${_name}})
  230     set(_varval ${${_var}})
  231     #message("debug: _name ${_name} ${_nameval}  _var ${_var} ${_varval}")
  232     if(${_nameval} AND NOT ${_nameval} STREQUAL "AUTO" AND NOT ${_varval})
  233         message(FATAL_ERROR "${_text} requested but ${_vartext} not found")
  234     endif()
  235 endmacro()
  236 
  237 #
  238 # Provide option that takes a path
  239 #
  240 macro(add_path_option _name _text _default)
  241     if(NOT DEFINED ${_name})
  242         set(${_name} ${_default} CACHE STRING "${_text}" FORCE)
  243     else()
  244         set(${_name} ${_default} CACHE STRING "${_text}")
  245     endif()
  246 endmacro()
  247 
  248 #
  249 # create directory on install
  250 #
  251 macro(install_dir filepath)
  252     install(CODE "
  253     set(_path \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${filepath}\")
  254     if(NOT EXISTS \"\${_path}\")
  255         execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory \"\${_path}\")
  256         message(\"-- Creating directory: \${_path}\")
  257     else()
  258         message(\"-- Up-to-date: \${_path}\")
  259     endif()
  260     ")
  261 endmacro()
  262 
  263 #
  264 # create symlink on install
  265 #
  266 macro(install_symlink filepath sympath)
  267     install(CODE "
  268     set(_sympath \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${sympath}\")
  269     file(REMOVE \"\${_sympath}\")
  270     execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink \"${filepath}\" \"\${_sympath}\" RESULT_VARIABLE result)
  271     if(NOT result)
  272         message(\"-- Creating symlink: \${_sympath} -> ${filepath}\")
  273     else()
  274         message(FATAL ERROR \"-- Failed to create symlink: \${_sympath} -> ${filepath}\")
  275     endif()
  276     ")
  277 endmacro()
  278 
  279 #
  280 # add system service <file> PATH <install path> LINKS [multi-user.target.wants [...]]
  281 #
  282 macro(add_systemd_service file)
  283     set(options)
  284     set(oneValueArgs PATH)
  285     set(multiValueArgs LINKS)
  286     cmake_parse_arguments(_ "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  287     set(_targetdir ${__PATH})
  288     install(FILES ${file} DESTINATION ${_targetdir})
  289     get_filename_component(_name ${file} NAME)
  290     foreach(l ${__LINKS})
  291         set(_linkdir ${_targetdir}/${l})
  292         install_dir(${_linkdir})
  293         install_symlink(../${_name} ${_linkdir}/${_name})
  294     endforeach()
  295 endmacro()