Updated testsuite with an expected GCL error in to_poly_share
[maxima.git] / crosscompile-windows / CMakeLists.txt
blobcb5dc7f2e5d45c374bcaa063dd6c47eb7ddb6a22
1 # CMake file for crosscompiling Maxima/wxMaxima for Windows
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (C) by Wolfgang Dautermann
4 # License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>
5 # This is free software: you are free to change and redistribute it.
6 # There is NO WARRANTY, to the extent permitted by law.
8 set(CMAKE_SYSTEM_NAME Windows)
10 option(BUILD_64BIT "Build a 64 bit installer." YES)
12 if(BUILD_64BIT)
13     set(HOST x86_64-w64-mingw32)
14     set(INSTALLERSUFFIX "win64")
15 else()
16     set(HOST i686-w64-mingw32)
17     set(INSTALLERSUFFIX "win32")
18 endif()
20 set(CMAKE_C_COMPILER   ${HOST}-gcc)
21 set(CMAKE_CXX_COMPILER ${HOST}-g++)
22 set(CMAKE_RC_COMPILER  ${HOST}-windres)
24 cmake_minimum_required(VERSION 3.10)
25 project(maxima)
27 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/ ${CMAKE_BINARY_DIR}/)
30 # On which windows drive (C:, D:, ...) will be the default installation path?
31 set(WINDOWS_DRIVELETTER "C")
34 # What is the build system?
35 execute_process(COMMAND gcc -dumpmachine OUTPUT_VARIABLE BUILDHOST OUTPUT_STRIP_TRAILING_WHITESPACE)
36 message(STATUS "Build system: ${BUILDHOST}")
38 # Output the host system, for which we are compiling
39 message(STATUS "Host system: ${HOST}")
41 find_file(NSISTEMPLATE_IN  NAMES "NSIS.template.in"
42     PATHS "${CMAKE_ROOT}/Modules/" "${CMAKE_ROOT}/Modules/Internal/CPack")
43 file(READ "${NSISTEMPLATE_IN}" MYNSISTEMPLATE)
44 string(REPLACE "RequestExecutionLevel admin" "RequestExecutionLevel admin
45 !include FileFunc.nsh
46 !include LogicLib.nsh
47 " MYNSISTEMPLATE "${MYNSISTEMPLATE}")
49 string(REPLACE "Function .onInit" "Function .onInit
50 \${GetParameters} \$0
51 \${GetOptions} \$0 \"/no_vtk\" \$1
52 \${IfNot} \${Errors}
53     !insertmacro UnselectSection \${vtk}
54 \${EndIf}
55 \${GetOptions} \$0 \"/no_gnuplot\" \$1
56 \${IfNot} \${Errors}
57     !insertmacro UnselectSection \${gnuplot}
58 \${EndIf}
59 \${GetOptions} \$0 \"/no_wxmaxima\" \$1
60 \${IfNot} \${Errors}
61     !insertmacro UnselectSection \${wxmaxima}
62 \${EndIf}
63 \${GetOptions} \$0 \"/?\" \$1
64 \${IfNot} \${Errors}
65         MessageBox MB_OK \"Installer for Maxima\$\\n\$\\nThis installer allows the following command line options:\$\\n        /S - silent install\$\\n        /D=<path> - select the install path\$\\n        /no_vtk - do not select VTK\$\\n        /no_gnuplot - do not select Gnuplot\$\\n        /no_wxmaxima - do not select wxMaxima\$\\n        /? - this help message\$\\n\$\\nMaxima Website: https://maxima.sourceforge.io\"
66         Abort
67 \${EndIf}
69 " MYNSISTEMPLATE "${MYNSISTEMPLATE}")
70 file(WRITE ${CMAKE_BINARY_DIR}/NSIS.template.in "${MYNSISTEMPLATE}")
71 message(STATUS "Copied and patched ${NSISTEMPLATE_IN} to ${CMAKE_BINARY_DIR}/NSIS.template.in")
73 option(USE_WXMAXIMA_GIT "Use wxMaxima development snapshot." NO)
74 option(USE_VTK "Use VTK." YES)
75 # the following option is used for nightly builds of the installer.
76 # it builds the current Maxima/wxMaxima Git versions and also
77 # sets the installation directory to ${WINDOWS_DRIVELETTER}:\maxima-current
78 option(BUILD_CURRENT "Build a installer for current Maxima/wxMaxima." NO)
80 option(WITH_ABCL "Include ABCL in the installer." NO)
82 # SBCL and CLISP have both advantages and disadvantages:
83 #  - SBCL is fast, but sometimes runs out of memory in places it really shouldn't
84 #    (Loading LAPACK on IA32, for example) and isn't too happy with changing to
85 #    non-ascii-non-unicode pathnames (which wxMaxima works around by now, though,
86 #    and which Xmaxima doesn't evven try to do)
87 #  - CLISP is slow. And version 2.49 only sends valid output over the network
88 #    if the front-end is slow enough. Test cases: Running a demo, all commands
89 #    with loads of compiler output (load("draw"); for the first time) or just
90 #    receiving a batch of new autocompletion symbols. Since the libraries the
91 #    front-ends use have evolved in the last years it has become easy to
92 #    trigger this => Setting SBCL to be the default.
93 #  - ABCL (optional) is a Java based Lisp.
94 if(WITH_ABCL)
95     set(WITH_DEFAULT_LISP "sbcl" CACHE STRING "Which Lisp should be used by default (clisp/sbcl/abcl)?")
96     set_property(CACHE WITH_DEFAULT_LISP PROPERTY STRINGS "clisp" "sbcl" "abcl")
97     set(ABCL_STYLE "")
98     set(ABCL_ENABLED 1)
99 else()
100     set(WITH_DEFAULT_LISP "sbcl" CACHE STRING "Which Lisp should be used by default (clisp/sbcl)?")
101     set_property(CACHE WITH_DEFAULT_LISP PROPERTY STRINGS "clisp" "sbcl")
102     set(ABCL_STYLE "display: none;")
103     set(ABCL_ENABLED 0)
104 endif()
106 # If you want to use a updated version of a program,
107 # update the version number and the checksum.
108 # If no further patches are needed, you should get a
109 # updated setup-file automatically.
111 # current program versions
112 set(CLISPVERSION 2.49)
115 # MD5 checksums for the current program versions.
116 set(CLISP_MD5 "8d58d64f83dd7ad01c054aecc16c1f52")
118 if(BUILD_CURRENT)
119     set(USE_WXMAXIMA_GIT YES)
120     set(MAXIMAVERSION "current")
121 else()
122     # Get Maxima version from configure.ac
123     file(STRINGS "${CMAKE_SOURCE_DIR}/../configure.ac" CONFIGUREAC REGEX "AC_INIT\\(.*\\)")
124     string(REGEX REPLACE "AC_INIT\\(\\[maxima\\],[ \t\r\n]*\\[(.*)\\]\\)" "\\1" MAXIMAVERSION ${CONFIGUREAC})
125     message(STATUS "Maxima version (from configure.ac): ${MAXIMAVERSION}")
126 endif()
128 # The HTML documentation is installed in a directory depending on "git describe",
129 # when building from Git, e.g.:
130 # share/maxima/branch_5_45_base_99_g0b3357e40_dirty/doc/html/maxima_singlepage.html
131 # Otherwise the version number is included, e.g something like:
132 # share/maxima/5.45.1/doc/html/maxima_singlepage.html
133 # Set it first to the second variant, if Git is found and we are building
134 # from a Git tree use the result of "git describe --dirty" in the path instead - where
135 # "-" are changed to "_" (see commit d5d04f2 and the file '../configure.ac').
136 set(MAXIMA_SINGLEPAGE_HTML "share/maxima/${MAXIMAVERSION}/doc/html/maxima_singlepage.html")
137 find_package(Git)
138 if(Git_FOUND)
139     execute_process(COMMAND ${GIT_EXECUTABLE} describe --dirty
140                     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
141                     OUTPUT_VARIABLE GIT_DESCRIBE
142                     ERROR_QUIET
143                     OUTPUT_STRIP_TRAILING_WHITESPACE)
144     if(GIT_DESCRIBE)
145         string(REPLACE "-" "_" GIT_DESCRIBE ${GIT_DESCRIBE})
146         set(MAXIMA_SINGLEPAGE_HTML "share/maxima/${GIT_DESCRIBE}/doc/html/maxima_singlepage.html")
147     endif()
148 endif()
150 # download URLs
151 set(CLISP_URL "https://downloads.sourceforge.net/project/clisp/clisp/${CLISPVERSION}/clisp-${CLISPVERSION}-win32-mingw-big.zip")
154 # Where are libgcc and libstdc++?
155 if(BUILD_64BIT)
156     execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-file-name=libgcc_s_seh-1.dll OUTPUT_VARIABLE MINGW_LIBGCC    OUTPUT_STRIP_TRAILING_WHITESPACE)
157 else()
158     execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-file-name=libgcc_s_sjlj-1.dll OUTPUT_VARIABLE MINGW_LIBGCC    OUTPUT_STRIP_TRAILING_WHITESPACE)
159 endif()
161 execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-file-name=libstdc++-6.dll     OUTPUT_VARIABLE MINGW_LIBSTDCPP OUTPUT_STRIP_TRAILING_WHITESPACE)
163 message(STATUS "Found libstdc++ at ${MINGW_LIBSTDCPP}")
165 message(STATUS "Found libgcc at ${MINGW_LIBGCC}")
167 add_subdirectory("wine/")
169 find_program(SEVENZIP_EXE NAMES 7z)
171 if(SEVENZIP_EXE)
172     message(STATUS "Found 7z at ${SEVENZIP_EXE}")
173 else()
174     message(FATAL_ERROR "7z not found. It is required for crosscompiling Maxima.")
175 endif()
177 # Avoid warnings in CMake >= 3.24:
178 # FIXME: Policy OLD is needed for texinfo, it does not build with the policy NEW
179 # But policy OLD is deprecated and may be removed in future CMake versions, see:
180 # https://cmake.org/cmake/help/latest/policy/CMP0135.html
181 # Hopefully texinfo solves that issue.
182 if (${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.24)
183     cmake_policy(SET CMP0135 OLD)
184 endif()
186 include(ExternalProject)
189 # Clisp (already a binary package just extract it...)
191 # What is the difference between clisp-2.49-win32-mingw-big.zip and clisp-2.49-win32-mingw-small.zip?
192 # What should be used for running Maxima?
193 externalproject_add(clisp
194   URL "${CLISP_URL}"
195   DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/downloads
196   URL_MD5 ${CLISP_MD5}
197   CONFIGURE_COMMAND ""
198   BUILD_COMMAND ""
199   INSTALL_COMMAND ""
201 install(DIRECTORY ${CMAKE_BINARY_DIR}/clisp-prefix/src/clisp/ DESTINATION clisp-${CLISPVERSION} COMPONENT Clisp)
203 add_subdirectory("sbcl/")
205 add_subdirectory("gnuplot/")
207 add_subdirectory("tcltk/")
209 add_subdirectory("texinfo/")
211 add_subdirectory("wxwidgets/")
213 add_subdirectory("wxmaxima/")
215 if(USE_VTK)
216     add_subdirectory("vtk/")
217     set(VTK_STYLE "")
218 else()
219     set(VTK_STYLE "display: none;")
220 endif()
222 if(WITH_ABCL)
223     add_subdirectory("abcl/")
224     set(ABCL_ENABLE "--enable-abcl")
225     set(ABCL_DEPENDS "abcl")
226     set(ABCL_JAR "--with-abcl-jar=${CMAKE_BINARY_DIR}/abcl/abcl-prefix/src/abcl/abcl.jar")
227 else()
228     set(ABCL_ENABLE "")
229     set(ABCL_DEPENDS "")
230     set(ABCL_JAR "")
231 endif()
233 configure_file("${CMAKE_SOURCE_DIR}/wine-clisp.sh.tmpl" "${CMAKE_BINARY_DIR}/wine-clisp.sh")
234 configure_file("${CMAKE_SOURCE_DIR}/wine-lisp.sh.tmpl" "${CMAKE_BINARY_DIR}/wine-lisp.sh")
235 configure_file("${CMAKE_SOURCE_DIR}/wine-sbcl.sh.tmpl" "${CMAKE_BINARY_DIR}/wine-sbcl.sh")
237 externalproject_add(maxima
238   # first copy the maxima source to a build directory, since out-of-source-builds do not work
239   DOWNLOAD_COMMAND rsync -a --exclude=crosscompile-windows/build/ "${CMAKE_SOURCE_DIR}/../"  "${CMAKE_BINARY_DIR}/maxima-prefix/src/maxima"
240   DEPENDS clisp sbcl tcl tk texinfo ${ABCL_DEPENDS}
241   BUILD_IN_SOURCE 1
242   CONFIGURE_COMMAND sh -c "test -x ./bootstrap && ./bootstrap || return 0"
243             COMMAND PATH=${CMAKE_BINARY_DIR}/texinfo-installroot/bin:$ENV{PATH} LANG=C ./configure --host=${HOST} --enable-clisp --with-clisp=${CMAKE_BINARY_DIR}/wine-clisp.sh --with-clisp-runtime=${CMAKE_BINARY_DIR}/wine-lisp.sh --enable-sbcl --with-sbcl=${CMAKE_BINARY_DIR}/wine-sbcl.sh ${ABCL_ENABLE} "${ABCL_JAR}" --with-default-lisp=${WITH_DEFAULT_LISP} --prefix=${WINDOWS_DRIVELETTER}:/maxima-${MAXIMAVERSION}
244   # clisp-depends.mk is generated with "\" as path separator, not "/" - correct that...
245   BUILD_COMMAND LANG=C $(MAKE) -C src clisp-depends.mk
246         COMMAND sed -i s+\\\\+/+g src/clisp-depends.mk
247         COMMAND PATH=${CMAKE_BINARY_DIR}/texinfo-installroot/bin:$ENV{PATH} LANG=C $(MAKE)
248         COMMAND PATH=${CMAKE_BINARY_DIR}/texinfo-installroot/bin:$ENV{PATH} LANG=C $(MAKE) pdf
249   INSTALL_COMMAND PATH=${CMAKE_BINARY_DIR}/texinfo-installroot/bin:$ENV{PATH} LANG=C $(MAKE) install DESTDIR=${CMAKE_BINARY_DIR}/maxima-installroot/
250           COMMAND PATH=${CMAKE_BINARY_DIR}/texinfo-installroot/bin:$ENV{PATH} LANG=C $(MAKE) extradocinstall DESTDIR=${CMAKE_BINARY_DIR}/maxima-installroot/
253 option(STRIP_HELPERPROGRAMS "Strip the included helper programs (winkill, winkill_lib, maxima_longnames)." YES)
255 # crosscompiling winkill with autoconf does not work, compile it using CMake.
256 add_library(winkill_lib SHARED ${CMAKE_SOURCE_DIR}/../interfaces/xmaxima/win32/winkill_lib.c)
257 add_executable(winkill ${CMAKE_SOURCE_DIR}/../interfaces/xmaxima/win32/winkill.c)
258 set_target_properties(winkill_lib PROPERTIES PREFIX "") # remove 'lib' prefix from libwinkill_lib.dll
259 target_link_libraries(winkill winkill_lib)
261 # convert windows short names to long names (e.g.
262 # "C:/Users/TESTTE~1/AppData/Local/Temp" to "C:/Users/test test/AppData/Local/Temp")
263 # CLISP can (currently not handle short names.
264 add_executable(maxima_longnames maxima_longnames.c)
265 if(STRIP_HELPERPROGRAMS)
266     add_custom_command(TARGET winkill POST_BUILD COMMAND ${CMAKE_STRIP} winkill.exe)
267     add_custom_command(TARGET winkill_lib POST_BUILD COMMAND ${CMAKE_STRIP} winkill_lib.dll)
268     add_custom_command(TARGET maxima_longnames POST_BUILD COMMAND ${CMAKE_STRIP} maxima_longnames.exe)
269 endif()
270 install(TARGETS winkill winkill_lib maxima_longnames COMPONENT Maxima RUNTIME DESTINATION bin LIBRARY DESTINATION bin/)
271 install(FILES "${CMAKE_SOURCE_DIR}/../interfaces/xmaxima/win32/win_signals.lisp" DESTINATION bin/ COMPONENT Maxima)
274 install(DIRECTORY ${CMAKE_BINARY_DIR}/maxima-installroot/${WINDOWS_DRIVELETTER}:/maxima-${MAXIMAVERSION}/
275         DESTINATION . COMPONENT Maxima PATTERN "binary-abcl" EXCLUDE)
276 if(WITH_ABCL)
277     install(DIRECTORY ${CMAKE_BINARY_DIR}/maxima-installroot/${WINDOWS_DRIVELETTER}:/maxima-${MAXIMAVERSION}/
278             DESTINATION . COMPONENT ABCL PATTERN "binary-abcl")
279 endif()
281 install(FILES "${CMAKE_SOURCE_DIR}/xmaxima.bat" DESTINATION bin/ COMPONENT Maxima)
282 install(FILES "${CMAKE_BINARY_DIR}/maxima-prefix/src/maxima/doc/info/maxima.pdf" DESTINATION share/doc/ COMPONENT Maxima)
283 configure_file("${CMAKE_SOURCE_DIR}/lispselector.tcl" "${CMAKE_BINARY_DIR}/lispselector.tcl")
284 install(FILES "${CMAKE_BINARY_DIR}/lispselector.tcl" DESTINATION bin/ COMPONENT Maxima)
285 install(FILES "${CMAKE_SOURCE_DIR}/lispselector.bat" DESTINATION bin/ COMPONENT Maxima)
289 # Include DLLs from the current Mingw environment.
290 install(FILES "${MINGW_LIBSTDCPP}" "${MINGW_LIBGCC}" DESTINATION bin/ COMPONENT Maxima)
292 configure_file("${CMAKE_SOURCE_DIR}/licenses.html" "${CMAKE_BINARY_DIR}/licenses.html")
293 install(FILES "${CMAKE_BINARY_DIR}/licenses.html" DESTINATION share/doc/ COMPONENT Maxima)
295 file(COPY "${CMAKE_SOURCE_DIR}/../COPYING" DESTINATION "${CMAKE_BINARY_DIR}")
296 file(READ "${CMAKE_SOURCE_DIR}/LICENSE_APPENDIX.txt" LICENSE_APPENDIX)
297 file(APPEND "${CMAKE_BINARY_DIR}/COPYING" "${LICENSE_APPENDIX}")
299 set(CPACK_GENERATOR "NSIS;ZIP")
300 set(CPACK_PACKAGE_VERSION "${MAXIMAVERSION}")
301 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Maxima")
302 set(CPACK_PACKAGE_VENDOR "Maxima Team")
303 set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/../README")
304 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_BINARY_DIR}/COPYING")
305 set(CPACK_PACKAGE_INSTALL_DIRECTORY "maxima-${CPACK_PACKAGE_VERSION}")
306 set(CPACK_NSIS_INSTALL_ROOT "${WINDOWS_DRIVELETTER}:")
307 set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
308 set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/maxima-icon.bmp")
309 set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/../interfaces/xmaxima\\\\maxima-icon.ico")
310 set(CPACK_NSIS_MUI_UNIICON "${CPACK_NSIS_MUI_ICON}")
311 set(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\maxima-command.ico")
312 set(CPACK_NSIS_DISPLAY_NAME "Maxima computer algebra system")
313 set(CPACK_PACKAGE_EXECUTABLES "..\\\\bin\\\\wxmaxima" "wxMaxima (GUI for Maxima)")
314 set(CPACK_NSIS_URL_INFO_ABOUT "https://maxima.sourceforge.io")
315 set(CPACK_NSIS_MENU_LINKS "bin/maxima.bat" "Maxima (command line)" "bin/xmaxima.bat" "XMaxima (simple GUI)" "https://maxima.sourceforge.io" "About Maxima" "https://wxmaxima-developers.github.io/wxmaxima/" "About wxMaxima" "${MAXIMA_SINGLEPAGE_HTML}" "Maxima documentation"  "share/doc/licenses.html" "Maxima and included software licenses" "bin/lispselector.bat" "Configure default LISP for Maxima")
316 set(CPACK_PACKAGE_FILE_NAME "maxima-${CPACK_PACKAGE_VERSION}-${INSTALLERSUFFIX}")
317 set(CPACK_NSIS_COMPRESSOR "/SOLID lzma")
320 set(CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP "${CMAKE_SOURCE_DIR}/maxima-installerimage.bmp")
321 include(CPack)
323 cpack_add_component(Maxima
324                     DESCRIPTION "The Maxima computer algebra system.\nRequired."
325                     REQUIRED)
327 if(USE_VTK)
328     cpack_add_component(VTK
329                         DESCRIPTION "VTK is an advanced graphic toolkit for draw().\nOptional.")
330 endif()
332 cpack_add_component(Gnuplot
333                     DESCRIPTION "Gnuplot is the main graphic toolkit.\nInstallation is strongly recommended.")
335 cpack_add_component(wxMaxima
336                     DESCRIPTION "wxMaxima is an advanced GUI for Maxima based on wxWidgets.\nInstallation is strongly recommended.")
338 cpack_add_component(Clisp
339                     DESCRIPTION "The CLISP Lisp compiler.\nRequired."
340                     REQUIRED)
342 cpack_add_component(SBCL
343                     DESCRIPTION "The SBCL Lisp compiler.\nRequired."
344                     REQUIRED)
346 cpack_add_component(TclTk
347                     DISPLAY_NAME "Tcl/Tk"
348                     DESCRIPTION "The TCL/TK scripting language.\nRequired."
349                     REQUIRED)
350 if(WITH_ABCL)
351     cpack_add_component(ABCL
352                         DESCRIPTION "The ABCL Lisp compiler.\nA Java installation is required.\nOptional.")
353 endif()