]> git.lyx.org Git - lyx.git/blob - development/autotests/CMakeLists.txt
1a7f711408b55a0c9bbc82548d541647a0dc68fa
[lyx.git] / development / autotests / CMakeLists.txt
1 # This file is part of LyX, the document processor.
2 # Licence details can be found in the file COPYING.
3 #
4 # Copyright (c) 2012 Kornel Benko kornel@lyx.org
5 #
6
7 if(Q_WS_X11)
8   set(Missing)
9   set(XVFBDLIBS)
10   # Make sure, the needed programs are in PATH
11   find_program(PCREGREP_EXE "pcregrep")
12   if (NOT PCREGREP_EXE)
13     list(APPEND Missing "pcregrep")
14   endif()
15   find_program(WMCTRL_EXE "wmctrl")
16   if(NOT WMCTRL_EXE)
17     list(APPEND Missing "wmctrl")
18   endif()
19   # This is needed to build xvkbd
20   # Programs pcregrep wmctrl and xvkbd are used in subsequent scripts
21   # while testing
22
23   # Check for needed libraries for xvkbd
24   # do not add autotests, if any of them is lacking
25
26   find_package(X11)
27   if(NOT X11_FOUND)
28     list(APPEND Missing "X11")
29   endif()
30   find_package(PkgConfig)
31   if(PKG_CONFIG_FOUND)
32     foreach(_lb "xaw7" "xmu" "xtst")
33       pkg_check_modules(${_lb}LIB ${_lb})
34       if(${_lb}LIB_LIBRARIES)
35         list(APPEND XVFBDLIBS ${${_lb}LIB_LIBRARIES})
36       else()
37         list(APPEND Missing ${_lb})
38       endif()
39     endforeach()
40   else()
41     foreach(_lb "Xaw7" "Xmu")
42       find_library(${_lb}LIB ${_lb})
43       if(${_lb}LIB)
44         list(APPEND XVFBDLIBS ${${_lb}LIB})
45       else()
46         list(APPEND Missing ${_lb})
47       endif()
48     endforeach()
49     foreach(_lb Xt XTest X11)
50       if(X11_${_lb}_LIB)
51         list(APPEND XVFBDLIBS ${X11_${_lb}_LIB})
52       else()
53         list(APPEND Missing ${_lb})
54       endif()
55     endforeach()
56   endif()
57   if (XVFBDLIBS)
58     list(REMOVE_DUPLICATES XVFBDLIBS)
59   endif()
60
61   if(Missing)
62     message(STATUS "Missing Libraries or programs to create xvkbd: ${Missing}")
63     message(STATUS "cmake build is therefore omiting autotests")
64   endif()
65
66   if(NOT Missing)
67     project(autotests)
68
69     add_subdirectory(xvkbd)
70
71     set(KEYTEST "${CMAKE_CURRENT_SOURCE_DIR}/keytest.py")
72     set(LYX_HOME "out-home")
73     set(LYX_USERDIR "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}/.lyx")
74     set(LOCALE_DIR "${CMAKE_CURRENT_BINARY_DIR}/locale") 
75     file(GLOB TESTST RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*-in.txt")
76     file(GLOB TESTSS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*-in.sh")
77     list(REMOVE_ITEM TESTST hello-world-in.txt first-time-in.txt)
78     list(SORT TESTST)
79     file(MAKE_DIRECTORY "${LYX_USERDIR}" "${LOCALE_DIR}")
80
81     foreach(_tf first-time-in.txt hello-world-in.txt ${TESTST})
82       string(REGEX REPLACE "-in\\.(txt|sh)" "" _t ${_tf})
83       add_test(NAME autotests/${_t}
84         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
85         COMMAND ${CMAKE_COMMAND}
86         -DAUTOTEST_ROOT=${TOP_SRC_DIR}/development/autotests
87         -DPO_BUILD_DIR=${TOP_BINARY_DIR}/po
88         -DKEYTEST_INFILE=${_tf}
89         -DBINDIR=$<TARGET_FILE_DIR:${_lyx}>
90         -DLYX=${_lyx}
91         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
92         -DKEYTEST_OUTFILE=${_t}-out.txt
93         -DPACKAGE=${PACKAGE}
94         -DLOCALE_DIR=${LOCALE_DIR}
95         -P ${TOP_SRC_DIR}/development/autotests/single-test.cmake)
96     endforeach()
97   endif()
98 endif()
99
100 macro(getoutputformats filepath varname)
101   file(STRINGS "${filepath}" lines)
102   set(${varname} "pdf") # try at least this one
103   foreach(_l ${lines})
104     if(_l MATCHES "^\\\\default_output_format +\([^ ]+\)")
105       if(CMAKE_MATCH_1 STREQUAL "default")
106         set(found "xhtml" "pdf" "pdf2" "pdf5")
107       elseif(CMAKE_MATCH_1 STREQUAL "xhtml")
108         set(found "xhtml")
109       else()
110         set(found "xhtml" ${CMAKE_MATCH_1})
111       endif()
112       set(${varname} ${found})
113       break()
114     endif()
115   endforeach()
116 endmacro()
117
118 foreach(libsubfolder doc examples templates)
119   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/lib/${libsubfolder}")
120   file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
121   list(SORT lyx_files)
122   # Now create 2 lists. One for files in a language dir, one without
123   set(lang_lyx_files)
124   set(nolang_lyx_files)
125   foreach(f ${lyx_files})
126     string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
127     if(_v)
128       list(APPEND lang_lyx_files ${f})
129     else()
130       list(APPEND nolang_lyx_files ${f})
131     endif()
132   endforeach()
133   foreach(f ${nolang_lyx_files} ${lang_lyx_files})
134     # Strip extension
135     string(REGEX REPLACE "\\.lyx$" "" f ${f})
136     add_test(NAME export/${libsubfolder}/${f}_lyx16
137       WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
138       COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
139           -Dlyx=$<TARGET_FILE:${_lyx}>
140           -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
141           -Dformat=lyx16x
142           -Dextension=16.lyx
143           -Dfile=${f}
144           -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
145     getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist)
146     foreach(format ${formatlist})
147       add_test(NAME export/${libsubfolder}/${f}_${format}
148         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
149         COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
150             -Dlyx=$<TARGET_FILE:${_lyx}>
151             -Dformat=${format}
152             -Dextension=${format}
153             -Dfile=${f}
154             -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
155     endforeach()
156   endforeach()
157 endforeach()
158