]> git.lyx.org Git - lyx.git/blob - development/autotests/CMakeLists.txt
I seem to need this to let the 'Lang' keyword work, within *-in.txt files.
[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   list(REMOVE_DUPLICATES XVFBDLIBS)
58
59   if(Missing)
60     message(STATUS "Missing Libraries or programms to create xvkbd: ${Missing}")
61     message(STATUS "cmake build is therefore omiting autotests")
62   endif()
63
64   if(NOT Missing)
65     project(autotests)
66
67     add_subdirectory(xvkbd)
68
69     set(KEYTEST "${CMAKE_CURRENT_SOURCE_DIR}/keytest.py")
70     set(LYX_HOME "out-home")
71     set(LYX_USERDIR "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}/.lyx")
72     set(LOCALE_DIR "${CMAKE_CURRENT_BINARY_DIR}/locale") 
73     file(GLOB TESTST RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*-in.txt")
74     file(GLOB TESTSS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*-in.sh")
75     list(REMOVE_ITEM TESTST hello-world-in.txt first-time-in.txt)
76     list(SORT TESTST)
77     file(MAKE_DIRECTORY "${LYX_USERDIR}" "${LOCALE_DIR}")
78
79     foreach(_tf first-time-in.txt hello-world-in.txt ${TESTST})
80       string(REGEX REPLACE "-in\\.(txt|sh)" "" _t ${_tf})
81       add_test(NAME autotests/${_t}
82         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
83         COMMAND ${CMAKE_COMMAND}
84         -DAUTOTEST_ROOT=${TOP_SRC_DIR}/development/autotests
85         -DPO_BUILD_DIR=${TOP_BINARY_DIR}/po
86         -DKEYTEST_INFILE=${_tf}
87         -DBINDIR=$<TARGET_FILE_DIR:${_lyx}>
88         -DLYX=${_lyx}
89         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
90         -DKEYTEST_OUTFILE=${_t}-out.txt
91         -DPACKAGE=${PACKAGE}
92         -DLOCALE_DIR=${LOCALE_DIR}
93         -P ${TOP_SRC_DIR}/development/autotests/single-test.cmake)
94     endforeach()
95   endif()
96 endif()
97
98 macro(getoutputformats filepath varname)
99   file(STRINGS "${filepath}" lines)
100   set(${varname} "pdf") # try at least this one
101   foreach(_l ${lines})
102     if(_l MATCHES "^\\\\default_output_format +\([^ ]+\)")
103       if(CMAKE_MATCH_1 STREQUAL "default")
104         set(found "xhtml" "pdf" "pdf2" "pdf5")
105       elseif(CMAKE_MATCH_1 STREQUAL "xhtml")
106         set(found "xhtml")
107       else()
108         set(found "xhtml" ${CMAKE_MATCH_1})
109       endif()
110       set(${varname} ${found})
111       break()
112     endif()
113   endforeach()
114 endmacro()
115
116 foreach(libsubfolder doc examples templates)
117   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/lib/${libsubfolder}")
118   file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
119   list(SORT lyx_files)
120   # Now create 2 lists. One for files in a language dir, one without
121   set(lang_lyx_files)
122   set(nolang_lyx_files)
123   foreach(f ${lyx_files})
124     string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
125     if(_v)
126       list(APPEND lang_lyx_files ${f})
127     else()
128       list(APPEND nolang_lyx_files ${f})
129     endif()
130   endforeach()
131   foreach(f ${nolang_lyx_files} ${lang_lyx_files})
132     # Strip extension
133     string(REGEX REPLACE "\\.lyx$" "" f ${f})
134     add_test(NAME export/${libsubfolder}/${f}_lyx16
135       WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
136       COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
137           -Dlyx=$<TARGET_FILE:${_lyx}>
138           -Dformat=lyx16x
139           -Dextension=16.lyx
140           -Dfile=${f}
141           -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
142     getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist)
143     foreach(format ${formatlist})
144       add_test(NAME export/${libsubfolder}/${f}_${format}
145         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
146         COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
147             -Dlyx=$<TARGET_FILE:${_lyx}>
148             -Dformat=${format}
149             -Dextension=${format}
150             -Dfile=${f}
151             -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
152     endforeach()
153   endforeach()
154 endforeach()
155
156