"Fossies" - the Fresh Open Source Software Archive

Member "gnucash-3.7/common/cmake_modules/GncAddTest.cmake" (7 Sep 2019, 6448 Bytes) of package /linux/misc/gnucash-3.7.tar.bz2:


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 "GncAddTest.cmake": 3.6_vs_3.7.

    1 
    2 
    3 function(get_guile_env)
    4   set(_GNC_MODULE_PATH ${LIBDIR_BUILD}:${LIBDIR_BUILD}/gnucash)
    5   if (WIN32)
    6     set(_GNC_MODULE_PATH ${CMAKE_BINARY_DIR}/bin)
    7   endif()
    8   set(env "")
    9   list(APPEND env "GNC_UNINSTALLED=yes")
   10   list(APPEND env "GNC_BUILDDIR=${CMAKE_BINARY_DIR}")
   11   if (APPLE)
   12     list(APPEND env "DYLD_LIBRARY_PATH=${_GNC_MODULE_PATH}")
   13   endif()
   14   if (UNIX)
   15     list(APPEND env LD_LIBRARY_PATH=${_GNC_MODULE_PATH})
   16   endif()
   17   if (MINGW64)
   18     set(fpath "")
   19     set(path $ENV{PATH})
   20     list(INSERT path 0 ${CMAKE_BINARY_DIR}/bin)
   21     foreach(dir ${path})
   22       string(REGEX REPLACE "^([A-Za-z]):" "/\\1" dir ${dir})
   23       string(REGEX REPLACE "\\\\" "/" dir ${dir})
   24       set(fpath "${fpath}${dir}:")
   25     endforeach(dir)
   26     list(APPEND env "PATH=${fpath}")
   27     set(compiled_path "${LIBDIR_BUILD}/gnucash/scm/ccache/${GUILE_EFFECTIVE_VERSION}")
   28     string(REGEX REPLACE "^([A-Za-z]):" "/\\1" compiled_path ${compiled_path})
   29     list(APPEND env GUILE_LOAD_COMPILED_PATH=${compiled_path})
   30   endif(MINGW64)
   31   list(APPEND env "GNC_MODULE_PATH=${_GNC_MODULE_PATH}")
   32   list(APPEND env "GUILE=${GUILE_EXECUTABLE}")
   33 
   34   if (NOT WIN32)
   35     list(APPEND env "GUILE_LOAD_COMPILED_PATH=${LIBDIR_BUILD}/gnucash/scm/ccache/${GUILE_EFFECTIVE_VERSION}")
   36   endif()
   37   set(guile_load_paths "")
   38   list(APPEND guile_load_paths ${CMAKE_CURRENT_SOURCE_DIR}/mod-foo)
   39   list(APPEND guile_load_paths ${CMAKE_CURRENT_SOURCE_DIR}/mod-bar)
   40   list(APPEND guile_load_paths ${CMAKE_CURRENT_SOURCE_DIR}/mod-baz)
   41   if (WIN32)
   42     list(APPEND guile_load_paths ${CMAKE_BINARY_DIR}/share/gnucash/scm)
   43   endif()
   44   set(guile_load_path "${guile_load_paths}")
   45   if (MINGW64)
   46     set(new_path "")
   47     foreach(load_item ${guile_load_path})
   48       string(REGEX REPLACE "^([A-Za-z]):" "/\\1" load_item ${load_item})
   49       list(APPEND new_path ${load_item})
   50     endforeach(load_item)
   51     set(guile_load_path ${new_path})
   52   endif (MINGW64)
   53   if (WIN32 AND NOT MINGW64)
   54     string(REPLACE ";" "\\\\;" GUILE_LOAD_PATH "${guile_load_path}")
   55   else()
   56     string(REPLACE ";" ":" GUILE_LOAD_PATH "${guile_load_path}")
   57   endif()
   58   list(APPEND env GUILE_LOAD_PATH=${GUILE_LOAD_PATH})
   59   set(GUILE_ENV ${env} PARENT_SCOPE)
   60 endfunction()
   61 
   62 
   63 function(gnc_add_test _TARGET _SOURCE_FILES TEST_INCLUDE_VAR_NAME TEST_LIBS_VAR_NAME)
   64   set(HAVE_ENV_VARS FALSE)
   65   if (${ARGC} GREATER 4)
   66     # Extra arguments are treated as environment variables
   67     set(HAVE_ENV_VARS TRUE)
   68   endif()
   69   set(TEST_INCLUDE_DIRS ${${TEST_INCLUDE_VAR_NAME}})
   70   set(TEST_LIBS ${${TEST_LIBS_VAR_NAME}})
   71   set_source_files_properties (${_SOURCE_FILES} PROPERTIES OBJECT_DEPENDS ${CONFIG_H})
   72   add_executable(${_TARGET} EXCLUDE_FROM_ALL ${_SOURCE_FILES})
   73   target_link_libraries(${_TARGET} ${TEST_LIBS})
   74   target_include_directories(${_TARGET} PRIVATE ${TEST_INCLUDE_DIRS})
   75   if (${HAVE_ENV_VARS})
   76     add_test(${_TARGET} ${CMAKE_COMMAND} -E env "GNC_UNINSTALLED=YES;GNC_BUILDDIR=${CMAKE_BINARY_DIR};${ARGN}"
   77       ${CMAKE_BINARY_DIR}/bin/${_TARGET}
   78     )
   79     set_tests_properties(${_TARGET} PROPERTIES ENVIRONMENT "GNC_UNINSTALLED=YES;GNC_BUILDDIR=${CMAKE_BINARY_DIR};${ARGN}")
   80   else()
   81     add_test(NAME ${_TARGET} COMMAND ${_TARGET})
   82     set_tests_properties(${_TARGET} PROPERTIES ENVIRONMENT "GNC_UNINSTALLED=YES;GNC_BUILDDIR=${CMAKE_BINARY_DIR}")
   83   endif()
   84   add_dependencies(check ${_TARGET})
   85 endfunction()
   86 
   87 function(gnc_add_test_with_guile _TARGET _SOURCE_FILES TEST_INCLUDE_VAR_NAME TEST_LIBS_VAR_NAME)
   88   get_guile_env()
   89   gnc_add_test(${_TARGET} "${_SOURCE_FILES}" "${TEST_INCLUDE_VAR_NAME}" "${TEST_LIBS_VAR_NAME}"
   90     "${GUILE_ENV};${ARGN}"
   91   )
   92 endfunction()
   93 
   94 
   95 function(gnc_add_scheme_test _TARGET _SOURCE_FILE)
   96   add_test(${_TARGET} ${CMAKE_COMMAND} -E env
   97     ${GUILE_EXECUTABLE} --debug -l ${CMAKE_CURRENT_SOURCE_DIR}/${_SOURCE_FILE} -c "(exit (run-test))"
   98   )
   99   get_guile_env()
  100   set_tests_properties(${_TARGET} PROPERTIES ENVIRONMENT "${GUILE_ENV};${ARGN}")
  101 endfunction()
  102 
  103 function(gnc_add_scheme_tests _SOURCE_FILES)
  104   foreach(test_file ${_SOURCE_FILES})
  105     get_filename_component(basename ${test_file} NAME_WE)
  106     gnc_add_scheme_test(${basename} ${test_file})
  107   endforeach()
  108 endfunction()
  109 
  110 function(gnc_gtest_configure)
  111   message(STATUS "Checking for GTEST")
  112   if (NOT DEFINED ${GTEST_ROOT})
  113     set(GTEST_ROOT $ENV{GTEST_ROOT})
  114   endif()
  115   if (NOT DEFINED ${GMOCK_ROOT})
  116     set(GMOCK_ROOT $ENV{GMOCK_ROOT})
  117   endif()
  118   find_path(GTEST_INCLUDE_DIR gtest/gtest.h
  119     HINTS ${GTEST_ROOT}/include ${GMOCK_ROOT}/gtest/include /usr/include)
  120   find_path(GTEST_SRC_DIR src/gtest-all.cc
  121     HINTS ${GTEST_ROOT} ${GMOCK_ROOT}/gtest /usr/src/gtest)
  122   find_library(GTEST_SHARED_LIB gtest)
  123   find_library(GTEST_MAIN_LIB gtest_main)
  124   if ((GTEST_SHARED_LIB OR GTEST_SRC_DIR) AND GTEST_INCLUDE_DIR)
  125     set(THREADS_PREFER_PTHREAD_FLAG ON)
  126     find_package(Threads REQUIRED)
  127     set(GTEST_FOUND YES CACHE INTERNAL "Found GTest")
  128     if(GTEST_SHARED_LIB)
  129       set(GTEST_LIB "${GTEST_MAIN_LIB};${GTEST_SHARED_LIB}" PARENT_SCOPE)
  130       unset(GTEST_SRC_DIR CACHE)
  131     else()
  132       set(lib_gtest_SOURCES
  133         "${GTEST_SRC_DIR}/src/gtest_main.cc"
  134         "${GTEST_SRC_DIR}/src/gtest-all.cc"
  135         PARENT_SCOPE)
  136       set(GTEST_LIB "${CMAKE_BINARY_DIR}/common/test-core/libgtest.a" PARENT_SCOPE)
  137     endif()
  138   else()
  139     message(FATAL_ERROR "GTEST not found. Please install it or set GTEST_ROOT or GMOCK_ROOT")
  140   endif()
  141 
  142   message(STATUS "Checking for GMOCK")
  143   find_path(GMOCK_INCLUDE_DIR gmock/gmock.h
  144     HINTS ${GMOCK_ROOT}/include /usr/include)
  145   unset(GMOCK_SRC_DIR CACHE)
  146   find_library(GMOCK_SHARED_LIB gmock)
  147   find_library(GMOCK_MAIN_LIB gmock_main)
  148   find_path(GMOCK_SRC_DIR src/gmock-all.cc
  149     HINTS ${GMOCK_ROOT} /usr/src/gmock)
  150   if (GMOCK_SRC_DIR)
  151     set(GMOCK_MAIN_SRC_DIR "${GMOCK_SRC_DIR}/src")
  152   else()
  153     find_path(GMOCK_SRC_DIR gmock-all.cc
  154       HINTS ${GMOCK_ROOT} /usr/src/gmock)
  155     if (GMOCK_SRC_DIR)
  156       set(GMOCK_MAIN_SRC_DIR "${GMOCK_SRC_DIR}")
  157     endif()
  158   endif()
  159   if (GMOCK_INCLUDE_DIR AND (GMOCK_SHARED_LIB OR GMOCK_SRC_DIR))
  160     set(GMOCK_FOUND YES PARENT_SCOPE)
  161     if(GMOCK_SHARED_LIB)
  162       set(GMOCK_LIB "${GMOCK_SHARED_LIB};${GMOCK_MAIN_LIB}" PARENT_SCOPE)
  163       unset(GMOCK_SRC_DIR CACHE)
  164     else()
  165       set(GMOCK_SRC "${GMOCK_MAIN_SRC_DIR}/gmock-all.cc" PARENT_SCOPE)
  166       set(GMOCK_LIB "${CMAKE_BINARY_DIR}/common/test-core/libgmock.a" PARENT_SCOPE)
  167     endif()
  168   else()
  169     message(FATAL_ERROR "GMOCK not found. Please install it or set GMOCK_ROOT")
  170   endif()
  171 endfunction()