]> git.lyx.org Git - lyx.git/blob - development/autotests/CMakeLists.txt
25713c6b22509b81c09a98fceaa992e70a195c48
[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(LYX_USERDIR "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}/.lyx")
9 set(LOCALE_DIR "${CMAKE_CURRENT_BINARY_DIR}/locale")
10 file(MAKE_DIRECTORY "${LYX_USERDIR}" "${LOCALE_DIR}")
11
12 if(Q_WS_X11)
13   set(Missing)
14   set(XVFBDLIBS)
15   # Make sure, the needed programs are in PATH
16   find_program(PCREGREP_EXE "pcregrep")
17   if (NOT PCREGREP_EXE)
18     list(APPEND Missing "pcregrep")
19   endif()
20   find_program(WMCTRL_EXE "wmctrl")
21   if(NOT WMCTRL_EXE)
22     list(APPEND Missing "wmctrl")
23   endif()
24   # This is needed to build xvkbd
25   # Programs pcregrep wmctrl and xvkbd are used in subsequent scripts
26   # while testing
27
28   # Check for needed libraries for xvkbd
29   # do not add autotests, if any of them is lacking
30
31   find_package(X11)
32   if(NOT X11_FOUND)
33     list(APPEND Missing "X11")
34   endif()
35   find_package(PkgConfig)
36   if(PKG_CONFIG_FOUND)
37     foreach(_lb "xaw7" "xmu" "xtst")
38       pkg_check_modules(${_lb}LIB ${_lb})
39       if(${_lb}LIB_LIBRARIES)
40         list(APPEND XVFBDLIBS ${${_lb}LIB_LIBRARIES})
41       else()
42         list(APPEND Missing ${_lb})
43       endif()
44     endforeach()
45   else()
46     foreach(_lb "Xaw7" "Xmu")
47       find_library(${_lb}LIB ${_lb})
48       if(${_lb}LIB)
49         list(APPEND XVFBDLIBS ${${_lb}LIB})
50       else()
51         list(APPEND Missing ${_lb})
52       endif()
53     endforeach()
54     foreach(_lb Xt XTest X11)
55       if(X11_${_lb}_LIB)
56         list(APPEND XVFBDLIBS ${X11_${_lb}_LIB})
57       else()
58         list(APPEND Missing ${_lb})
59       endif()
60     endforeach()
61   endif()
62   if (XVFBDLIBS)
63     list(REMOVE_DUPLICATES XVFBDLIBS)
64   endif()
65
66   if(Missing)
67     message(STATUS "Missing Libraries or programs to create xvkbd: ${Missing}")
68     message(STATUS "cmake build is therefore omitting keytests")
69   endif()
70
71   if(NOT Missing)
72     project(keytest)
73
74     add_subdirectory(xvkbd)
75
76     set(KEYTEST "${CMAKE_CURRENT_SOURCE_DIR}/keytest.py")
77     file(GLOB TESTST RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*-in.txt")
78     file(GLOB TESTSS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*-in.sh")
79     list(REMOVE_ITEM TESTST hello-world-in.txt first-time-in.txt)
80     list(SORT TESTST)
81     file(MAKE_DIRECTORY "${LYX_USERDIR}" "${LOCALE_DIR}")
82
83     foreach(_tf first-time-in.txt hello-world-in.txt ${TESTST})
84       string(REGEX REPLACE "-in\\.(txt|sh)" "" _t ${_tf})
85       add_test(NAME keytest/${_t}
86         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
87         COMMAND ${CMAKE_COMMAND}
88         -DAUTOTEST_ROOT=${TOP_SRC_DIR}/development/autotests
89         -DPO_BUILD_DIR=${TOP_BINARY_DIR}/po
90         -DKEYTEST_INFILE=${_tf}
91         -DBINDIR=$<TARGET_FILE_DIR:${_lyx}>
92         -DLYX=${_lyx}
93         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
94         -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
95         -DKEYTEST_OUTFILE=${_t}-out.txt
96         -DPACKAGE=${PACKAGE}
97         -DLOCALE_DIR=${LOCALE_DIR}
98         -P ${TOP_SRC_DIR}/development/autotests/single-test.cmake)
99     endforeach()
100   endif()
101 endif()
102
103 macro(getoutputformats filepath varname)
104   file(STRINGS "${filepath}" lines)
105   set(out_formats "xhtml" "pdf" "pdf2" "pdf5")
106   set(${varname} ${out_formats})
107   foreach(_l ${lines})
108     if(_l MATCHES "^\\\\default_output_format +\([^ ]+\)")
109       if(CMAKE_MATCH_1 STREQUAL "default")
110         set(found ${out_formats})
111       elseif(CMAKE_MATCH_1 STREQUAL "xhtml")
112         set(found "xhtml")
113       else()
114         set(found "xhtml" ${CMAKE_MATCH_1})
115       endif()
116       set(${varname} ${found})
117       break()
118     endif()
119   endforeach()
120 endmacro()
121
122 macro(getreverted testname reverted listreverted)
123   list(FIND ${listreverted} ${${testname}} _idx)
124   if (${_idx} LESS 0)
125     set(${reverted} 0)
126   else()
127     set(${reverted} 1)
128     set(${testname} "INVERTED_SEE-README.ctest_${${testname}}")
129   endif()
130 endmacro()
131
132 foreach(libsubfolder doc examples templates)
133   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/lib/${libsubfolder}")
134   file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
135   list(SORT lyx_files)
136   # Now create 2 lists. One for files in a language dir, one without
137   set(lang_lyx_files)
138   set(nolang_lyx_files)
139   foreach(f ${lyx_files})
140     string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
141     if(_v)
142       list(APPEND lang_lyx_files ${f})
143     else()
144       list(APPEND nolang_lyx_files ${f})
145     endif()
146   endforeach()
147   file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/revertedTests" revertedTests)
148   file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/ignoredTests" ignoredTests)
149   foreach(f ${nolang_lyx_files} ${lang_lyx_files})
150     # Strip extension
151     string(REGEX REPLACE "\\.lyx$" "" f ${f})
152     set(TestName "export/${libsubfolder}/${f}_lyx16")
153     getreverted(TestName reverted revertedTests)
154     add_test(NAME ${TestName}
155       WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
156       COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
157           -Dlyx=$<TARGET_FILE:${_lyx}>
158           -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
159           -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
160           -Dformat=lyx16x
161           -Dextension=16.lyx
162           -Dfile=${f}
163           -Dreverted=${reverted}
164           -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
165     set(TestName "lyx2lyx/${libsubfolder}/${f}")
166     getreverted(TestName reverted revertedTests)
167     add_test(NAME ${TestName}
168       WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
169       COMMAND ${CMAKE_COMMAND} -DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx
170         -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
171         -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
172     set(TestName "check_load/${libsubfolder}/${f}")
173     getreverted(TestName reverted revertedTests)
174     add_test(NAME ${TestName}
175       WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
176       COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
177         -Dlyx=$<TARGET_FILE:${_lyx}>
178         -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
179         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
180         -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
181     getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist)
182     foreach(format ${formatlist})
183       set(TestName "export/${libsubfolder}/${f}_${format}")
184       list(FIND ignoredTests ${TestName} _idx)
185       if (${_idx} LESS 0)
186         getreverted(TestName reverted revertedTests)
187         add_test(NAME ${TestName}
188           WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
189           COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
190             -Dlyx=$<TARGET_FILE:${_lyx}>
191             -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
192             -Dformat=${format}
193             -Dextension=${format}
194             -Dfile=${f}
195             -Dreverted=${reverted}
196             -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
197       endif()
198     endforeach()
199   endforeach()
200 endforeach()
201