]> git.lyx.org Git - lyx.git/blob - development/autotests/CMakeLists.txt
b5b1423f7a26b8c905c6c4ede31a8e0f89e5fe08
[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 set(LYX_HOME "out-home")
8 set(LOCALE_DIR "${CMAKE_CURRENT_BINARY_DIR}/locale")
9 file(MAKE_DIRECTORY "${LOCALE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}")
10
11 if(QT_USES_X11)
12   set(Missing)
13   set(XVFBDLIBS)
14   # Make sure, the needed programs are in PATH
15   find_program(PCREGREP_EXE "pcregrep")
16   if (NOT PCREGREP_EXE)
17     list(APPEND Missing "pcregrep")
18   endif()
19   find_program(WMCTRL_EXE "wmctrl")
20   if(NOT WMCTRL_EXE)
21     list(APPEND Missing "wmctrl")
22   endif()
23   # This is needed to build xvkbd
24   # Programs pcregrep wmctrl and xvkbd are used in subsequent scripts
25   # while testing
26
27   # Check for needed libraries for xvkbd
28   # do not add autotests, if any of them is lacking
29
30   find_package(X11)
31   if(NOT X11_FOUND)
32     list(APPEND Missing "X11")
33   endif()
34   find_package(PkgConfig)
35   if(PKG_CONFIG_FOUND)
36     foreach(_lb "xaw7" "xmu" "xtst")
37       pkg_check_modules(${_lb}LIB ${_lb})
38       if(${_lb}LIB_LIBRARIES)
39         list(APPEND XVFBDLIBS ${${_lb}LIB_LIBRARIES})
40       else()
41         list(APPEND Missing ${_lb})
42       endif()
43     endforeach()
44   else()
45     foreach(_lb "Xaw7" "Xmu")
46       find_library(${_lb}LIB ${_lb})
47       if(${_lb}LIB)
48         list(APPEND XVFBDLIBS ${${_lb}LIB})
49       else()
50         list(APPEND Missing ${_lb})
51       endif()
52     endforeach()
53     foreach(_lb Xt XTest X11)
54       if(X11_${_lb}_LIB)
55         list(APPEND XVFBDLIBS ${X11_${_lb}_LIB})
56       else()
57         list(APPEND Missing ${_lb})
58       endif()
59     endforeach()
60   endif()
61   if (XVFBDLIBS)
62     list(REMOVE_DUPLICATES XVFBDLIBS)
63   endif()
64
65   if(Missing)
66     message(STATUS "Missing Libraries or programs to create xvkbd: ${Missing}")
67     message(STATUS "cmake build is therefore omitting keytests")
68   endif()
69
70   if(NOT Missing)
71     project(keytest)
72
73     add_subdirectory(xvkbd)
74
75     set(KEYTEST "${CMAKE_CURRENT_SOURCE_DIR}/keytest.py")
76     file(GLOB TESTST RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*-in.txt")
77     file(GLOB TESTSS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*-in.sh")
78     list(REMOVE_ITEM TESTST hello-world-in.txt first-time-in.txt)
79     list(SORT TESTST)
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 keytest/${_t}
84         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
85         COMMAND ${CMAKE_COMMAND}
86         -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
87         -DAUTOTEST_ROOT=${TOP_SRC_DIR}/development/autotests
88         -DPO_BUILD_DIR=${TOP_BINARY_DIR}/po
89         -DKEYTEST_INFILE=${_tf}
90         -DBINDIR=$<TARGET_FILE_DIR:${_lyx}>
91         -DLYX=${_lyx}
92         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
93         -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
94         -DKEYTEST_OUTFILE=${_t}-out.txt
95         -DPACKAGE=${PACKAGE}
96         -DLOCALE_DIR=${LOCALE_DIR}
97         -P ${TOP_SRC_DIR}/development/autotests/single-test.cmake)
98       settestlabel(keytest/${_t} "key")
99       set_tests_properties(keytest/${_t} PROPERTIES RUN_SERIAL ON)
100     endforeach()
101   endif()
102 endif()
103
104 find_package(Perl)
105
106 if(PERL_FOUND)
107   set(DVI_FORMATS "dvi" "dvi3")
108   set(PDF_FORMATS "pdf" "pdf2" "pdf3" "pdf4" "pdf5")
109 else()
110   set(DVI_FORMATS "dvi")
111   set(PDF_FORMATS "pdf" "pdf2" "pdf3")
112 endif()
113
114 macro(getoutputformats filepath varname)
115   file(STRINGS "${filepath}" lines)
116   # What should we test, if default_output_format is not defined?
117   # For now we test everything ...
118   set(out_formats "xhtml" ${DVI_FORMATS} ${PDF_FORMATS})
119   foreach(_l ${lines})
120     if(_l MATCHES "^\\\\default_output_format +\([^ ]+\)")
121       set(_format ${CMAKE_MATCH_1})
122       if(_format STREQUAL "default")
123         set(out_formats "xhtml" ${DVI_FORMATS} ${PDF_FORMATS})
124       elseif(_format MATCHES "pdf")
125         set(found "xhtml" ${PDF_FORMATS})
126       elseif(_format MATCHES "dvi")
127         set(out_formats "xhtml" ${DVI_FORMATS})
128       else()
129         # Respect all other output formats
130         # like "eps3", "xhtml"
131         set(out_formats ${_format})
132       endif()
133       break()
134     endif()
135   endforeach()
136   set(${varname} ${out_formats})
137 endmacro()
138
139 macro(findexpr found testname listname)
140   set(_found 0)
141   foreach(_itrx ${${listname}})
142     set(_itr "^${_itrx}$")
143     if(${testname} MATCHES ${_itr})
144       set(_found 1)
145       break()
146     endif()
147   endforeach()
148   set(${found} ${_found})
149 endmacro()
150   
151 macro(maketestname testname reverted listreverted listignored)
152   findexpr(mfound ${testname} ${listignored})
153   if (NOT mfound)
154     findexpr(mfound ${testname} ${listreverted})
155     list(FIND ${listreverted} ${${testname}} _idx)
156     if (NOT mfound)
157       set(${reverted} 0)
158     else()
159       set(${reverted} 1)
160       set(${testname} "INVERTED_SEE-README.ctest_${${testname}}")
161     endif()
162   else()
163     set(${testname} "")
164   endif()
165 endmacro()
166
167 macro(loadTestList filename resList)
168   # Create list of strings from a file without comments
169   file(STRINGS ${filename} tempList)
170   set(${resList})
171   foreach(_l ${tempList})
172     string(REGEX REPLACE "[ \t]*#.*" "" _newl "${_l}")
173     if(_newl)
174       list(APPEND ${resList} "${_newl}")
175     endif()
176   endforeach()
177 endmacro()
178
179 loadTestList(revertedTests revertedTests)
180 loadTestList(ignoredTests ignoredTests)
181
182 foreach(libsubfolder doc examples templates)
183   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/lib/${libsubfolder}")
184   file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
185   list(SORT lyx_files)
186   # Now create 2 lists. One for files in a language dir, one without
187   set(lang_lyx_files)
188   set(nolang_lyx_files)
189   foreach(f ${lyx_files})
190     string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
191     if(_v)
192       list(APPEND lang_lyx_files ${f})
193     else()
194       list(APPEND nolang_lyx_files ${f})
195     endif()
196   endforeach()
197   foreach(f ${nolang_lyx_files} ${lang_lyx_files})
198     # Strip extension
199     string(REGEX REPLACE "\\.lyx$" "" f ${f})
200     set(TestName "export/${libsubfolder}/${f}_lyx16")
201     maketestname(TestName reverted revertedTests ignoredTests)
202     if(TestName)
203       add_test(NAME ${TestName}
204         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
205         COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
206             -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
207             -Dlyx=$<TARGET_FILE:${_lyx}>
208             -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
209             -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
210             -Dformat=lyx16x
211             -Dextension=16.lyx
212             -Dfile=${f}
213             -Dreverted=${reverted}
214             -DTOP_SRC_DIR=${TOP_SRC_DIR}
215             -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
216             -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
217       setmarkedtestlabel(${TestName} ${reverted} "export")
218     endif()
219     if(LYX_PYTHON_EXECUTABLE)
220       # For use of lyx2lyx we need the python executable
221       set(TestName "lyx2lyx/${libsubfolder}/${f}")
222       maketestname(TestName reverted revertedTests ignoredTests)
223       if(TestName)
224         add_test(NAME ${TestName}
225           WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
226           COMMAND ${CMAKE_COMMAND}
227             "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
228             "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
229             "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
230             "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
231             -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
232         setmarkedtestlabel(${TestName} ${reverted} "lyx2lyx")
233       endif()
234     endif()
235     set(TestName "check_load/${libsubfolder}/${f}")
236     maketestname(TestName reverted revertedTests ignoredTests)
237     if(TestName)
238       add_test(NAME ${TestName}
239         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
240         COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
241           -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
242           -Dlyx=$<TARGET_FILE:${_lyx}>
243           -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
244           -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
245           -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
246       setmarkedtestlabel(${TestName} ${reverted} "load")
247     endif()
248     getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist)
249     foreach(format ${formatlist})
250       if(format MATCHES "dvi3|pdf4|pdf5")
251         set(fonttypes "texF" "systemF")
252       else()
253         set(fonttypes "defaultF")
254       endif()
255       foreach(fonttype ${fonttypes})
256         if(fonttype MATCHES "defaultF")
257           set(TestName "export/${libsubfolder}/${f}_${format}")
258         else()
259           set(TestName "export/${libsubfolder}/${f}_${format}_${fonttype}")
260         endif()
261         maketestname(TestName reverted revertedTests ignoredTests)
262         if(TestName)
263           add_test(NAME ${TestName}
264             WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
265             COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
266             -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
267             -Dlyx=$<TARGET_FILE:${_lyx}>
268             -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
269             -Dformat=${format}
270             -Dfonttype=${fonttype}
271             -Dextension=${format}
272             -Dfile=${f}
273             -Dreverted=${reverted}
274             -DTOP_SRC_DIR=${TOP_SRC_DIR}
275             -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
276             -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
277           setmarkedtestlabel(${TestName} ${reverted} "export")
278         endif()
279       endforeach()
280     endforeach()
281   endforeach()
282 endforeach()
283