]> git.lyx.org Git - features.git/blob - development/autotests/CMakeLists.txt
Cmake build tests: Unify use of userdir
[features.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}")
10
11 if(Q_WS_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     endforeach()
99   endif()
100 endif()
101
102 macro(getoutputformats filepath varname)
103   file(STRINGS "${filepath}" lines)
104   set(out_formats "xhtml" "pdf" "pdf2" "pdf5")
105   set(${varname} ${out_formats})
106   foreach(_l ${lines})
107     if(_l MATCHES "^\\\\default_output_format +\([^ ]+\)")
108       if(CMAKE_MATCH_1 STREQUAL "default")
109         set(found ${out_formats})
110       elseif(CMAKE_MATCH_1 STREQUAL "xhtml")
111         set(found "xhtml")
112       else()
113         set(found "xhtml" ${CMAKE_MATCH_1})
114       endif()
115       set(${varname} ${found})
116       break()
117     endif()
118   endforeach()
119 endmacro()
120
121 macro(maketestname testname reverted listreverted listignored)
122   list(FIND ${listignored} ${${testname}} _idx)
123   if (${_idx} LESS 0)
124     list(FIND ${listreverted} ${${testname}} _idx)
125     if (${_idx} LESS 0)
126       set(${reverted} 0)
127     else()
128       set(${reverted} 1)
129       set(${testname} "INVERTED_SEE-README.ctest_${${testname}}")
130     endif()
131   else()
132     set(${testname} "")
133   endif()
134 endmacro()
135
136 macro(loadTestList filename resList)
137   # Create list of strings from a file without comments
138   file(STRINGS ${filename} tempList)
139   set(${resList})
140   foreach(_l ${tempList})
141     string(REGEX REPLACE "[ \t]*#.*" "" _newl "${_l}")
142     if(_newl)
143       list(APPEND ${resList} "${_newl}")
144     endif()
145   endforeach()
146 endmacro()
147
148 loadTestList(revertedTests revertedTests)
149 loadTestList(ignoredTests ignoredTests)
150
151 foreach(libsubfolder doc examples templates)
152   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/lib/${libsubfolder}")
153   file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
154   list(SORT lyx_files)
155   # Now create 2 lists. One for files in a language dir, one without
156   set(lang_lyx_files)
157   set(nolang_lyx_files)
158   foreach(f ${lyx_files})
159     string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
160     if(_v)
161       list(APPEND lang_lyx_files ${f})
162     else()
163       list(APPEND nolang_lyx_files ${f})
164     endif()
165   endforeach()
166   foreach(f ${nolang_lyx_files} ${lang_lyx_files})
167     # Strip extension
168     string(REGEX REPLACE "\\.lyx$" "" f ${f})
169     set(TestName "export/${libsubfolder}/${f}_lyx16")
170     maketestname(TestName reverted revertedTests ignoredTests)
171     if(TestName)
172       add_test(NAME ${TestName}
173         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
174         COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
175             -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
176             -Dlyx=$<TARGET_FILE:${_lyx}>
177             -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
178             -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
179             -Dformat=lyx16x
180             -Dextension=16.lyx
181             -Dfile=${f}
182             -Dreverted=${reverted}
183             -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
184     endif()
185     set(TestName "lyx2lyx/${libsubfolder}/${f}")
186     maketestname(TestName reverted revertedTests ignoredTests)
187     if(TestName)
188       add_test(NAME ${TestName}
189         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
190         COMMAND ${CMAKE_COMMAND} -DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx
191           -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
192           -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
193           -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
194     endif()
195     set(TestName "check_load/${libsubfolder}/${f}")
196     maketestname(TestName reverted revertedTests ignoredTests)
197     if(TestName)
198       add_test(NAME ${TestName}
199         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
200         COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
201           -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
202           -Dlyx=$<TARGET_FILE:${_lyx}>
203           -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
204           -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
205           -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
206     else()
207       message("ignored test")
208     endif()
209     getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist)
210     foreach(format ${formatlist})
211       set(TestName "export/${libsubfolder}/${f}_${format}")
212       maketestname(TestName reverted revertedTests ignoredTests)
213       if(TestName)
214         add_test(NAME ${TestName}
215           WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
216           COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
217             -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
218             -Dlyx=$<TARGET_FILE:${_lyx}>
219             -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
220             -Dformat=${format}
221             -Dextension=${format}
222             -Dfile=${f}
223             -Dreverted=${reverted}
224             -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
225       endif()
226     endforeach()
227   endforeach()
228 endforeach()
229