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)
13 set(HOST x86_64-w64-mingw32)
14 set(INSTALLERSUFFIX "win64")
16 set(HOST i686-w64-mingw32)
17 set(INSTALLERSUFFIX "win32")
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)
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
47 " MYNSISTEMPLATE "${MYNSISTEMPLATE}")
49 string(REPLACE "Function .onInit" "Function .onInit
51 \${GetOptions} \$0 \"/no_vtk\" \$1
53 !insertmacro UnselectSection \${vtk}
55 \${GetOptions} \$0 \"/no_gnuplot\" \$1
57 !insertmacro UnselectSection \${gnuplot}
59 \${GetOptions} \$0 \"/no_wxmaxima\" \$1
61 !insertmacro UnselectSection \${wxmaxima}
63 \${GetOptions} \$0 \"/?\" \$1
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\"
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.
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")
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;")
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")
119 set(USE_WXMAXIMA_GIT YES)
120 set(MAXIMAVERSION "current")
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}")
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")
139 execute_process(COMMAND ${GIT_EXECUTABLE} describe --dirty
140 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
141 OUTPUT_VARIABLE GIT_DESCRIBE
143 OUTPUT_STRIP_TRAILING_WHITESPACE)
145 string(REPLACE "-" "_" GIT_DESCRIBE ${GIT_DESCRIBE})
146 set(MAXIMA_SINGLEPAGE_HTML "share/maxima/${GIT_DESCRIBE}/doc/html/maxima_singlepage.html")
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 # Seems difficult. On Ubuntu 22.04 and 20.04 (64bit) the library libgcc is called libgcc_s_seh-1.dll.
156 # On Ubuntu 20.04 (32bit) it is libgcc_s_sjlj-1.dll - that file does not exist in Ubuntu 22.04, there it is most likely libgcc_s_dw2-1.dll
158 execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-file-name=libgcc_s_seh-1.dll OUTPUT_VARIABLE MINGW_LIBGCC OUTPUT_STRIP_TRAILING_WHITESPACE)
160 execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-file-name=libgcc_s_sjlj-1.dll OUTPUT_VARIABLE MINGW_LIBGCC OUTPUT_STRIP_TRAILING_WHITESPACE)
161 if("${MINGW_LIBGCC}" STREQUAL "libgcc_s_sjlj-1.dll")
162 # "${CMAKE_CXX_COMPILER}" -print-file-name=libgcc_s_sjlj-1.dll prints the string, if the file was not found. Otherwise the full path to the file.
163 execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-file-name=libgcc_s_dw2-1.dll OUTPUT_VARIABLE MINGW_LIBGCC OUTPUT_STRIP_TRAILING_WHITESPACE)
167 execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-file-name=libstdc++-6.dll OUTPUT_VARIABLE MINGW_LIBSTDCPP OUTPUT_STRIP_TRAILING_WHITESPACE)
169 message(STATUS "Found libstdc++ at ${MINGW_LIBSTDCPP}")
171 message(STATUS "Found libgcc at ${MINGW_LIBGCC}")
173 add_subdirectory("wine/")
175 find_program(SEVENZIP_EXE NAMES 7z)
178 message(STATUS "Found 7z at ${SEVENZIP_EXE}")
180 message(FATAL_ERROR "7z not found. It is required for crosscompiling Maxima.")
183 # Avoid warnings in CMake >= 3.24:
184 # FIXME: Policy OLD is needed for texinfo, it does not build with the policy NEW
185 # But policy OLD is deprecated and may be removed in future CMake versions, see:
186 # https://cmake.org/cmake/help/latest/policy/CMP0135.html
187 # Hopefully texinfo solves that issue.
188 if (${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.24)
189 cmake_policy(SET CMP0135 OLD)
192 include(ExternalProject)
195 # Clisp (already a binary package just extract it...)
197 # What is the difference between clisp-2.49-win32-mingw-big.zip and clisp-2.49-win32-mingw-small.zip?
198 # What should be used for running Maxima?
199 externalproject_add(clisp
201 DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/downloads
207 install(DIRECTORY ${CMAKE_BINARY_DIR}/clisp-prefix/src/clisp/ DESTINATION clisp-${CLISPVERSION} COMPONENT Clisp)
209 add_subdirectory("sbcl/")
211 add_subdirectory("gnuplot/")
213 add_subdirectory("tcltk/")
215 add_subdirectory("texinfo/")
217 add_subdirectory("wxwidgets/")
219 add_subdirectory("wxmaxima/")
222 add_subdirectory("vtk/")
225 set(VTK_STYLE "display: none;")
229 add_subdirectory("abcl/")
230 set(ABCL_ENABLE "--enable-abcl")
231 set(ABCL_DEPENDS "abcl")
232 set(ABCL_JAR "--with-abcl-jar=${CMAKE_BINARY_DIR}/abcl/abcl-prefix/src/abcl/abcl.jar")
239 configure_file("${CMAKE_SOURCE_DIR}/wine-clisp.sh.tmpl" "${CMAKE_BINARY_DIR}/wine-clisp.sh")
240 configure_file("${CMAKE_SOURCE_DIR}/wine-lisp.sh.tmpl" "${CMAKE_BINARY_DIR}/wine-lisp.sh")
241 configure_file("${CMAKE_SOURCE_DIR}/wine-sbcl.sh.tmpl" "${CMAKE_BINARY_DIR}/wine-sbcl.sh")
243 externalproject_add(maxima
244 # first copy the maxima source to a build directory, since out-of-source-builds do not work
245 DOWNLOAD_COMMAND rsync -a --exclude=crosscompile-windows/build/ "${CMAKE_SOURCE_DIR}/../" "${CMAKE_BINARY_DIR}/maxima-prefix/src/maxima"
246 DEPENDS clisp sbcl tcl tk texinfo ${ABCL_DEPENDS}
248 CONFIGURE_COMMAND sh -c "test -x ./bootstrap && ./bootstrap || return 0"
249 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}
250 # clisp-depends.mk is generated with "\" as path separator, not "/" - correct that...
251 BUILD_COMMAND LANG=C $(MAKE) -C src clisp-depends.mk
252 COMMAND sed -i s+\\\\+/+g src/clisp-depends.mk
253 COMMAND PATH=${CMAKE_BINARY_DIR}/texinfo-installroot/bin:$ENV{PATH} LANG=C $(MAKE)
254 COMMAND PATH=${CMAKE_BINARY_DIR}/texinfo-installroot/bin:$ENV{PATH} LANG=C $(MAKE) pdf
255 INSTALL_COMMAND PATH=${CMAKE_BINARY_DIR}/texinfo-installroot/bin:$ENV{PATH} LANG=C $(MAKE) install DESTDIR=${CMAKE_BINARY_DIR}/maxima-installroot/
256 COMMAND PATH=${CMAKE_BINARY_DIR}/texinfo-installroot/bin:$ENV{PATH} LANG=C $(MAKE) extradocinstall DESTDIR=${CMAKE_BINARY_DIR}/maxima-installroot/
259 option(STRIP_HELPERPROGRAMS "Strip the included helper programs (winkill, winkill_lib, maxima_longnames)." YES)
261 # crosscompiling winkill with autoconf does not work, compile it using CMake.
262 add_library(winkill_lib SHARED ${CMAKE_SOURCE_DIR}/../interfaces/xmaxima/win32/winkill_lib.c)
263 add_executable(winkill ${CMAKE_SOURCE_DIR}/../interfaces/xmaxima/win32/winkill.c)
264 set_target_properties(winkill_lib PROPERTIES PREFIX "") # remove 'lib' prefix from libwinkill_lib.dll
265 target_link_libraries(winkill winkill_lib)
267 # convert windows short names to long names (e.g.
268 # "C:/Users/TESTTE~1/AppData/Local/Temp" to "C:/Users/test test/AppData/Local/Temp")
269 # CLISP can (currently not handle short names.
270 add_executable(maxima_longnames maxima_longnames.c)
271 if(STRIP_HELPERPROGRAMS)
272 add_custom_command(TARGET winkill POST_BUILD COMMAND ${CMAKE_STRIP} winkill.exe)
273 add_custom_command(TARGET winkill_lib POST_BUILD COMMAND ${CMAKE_STRIP} winkill_lib.dll)
274 add_custom_command(TARGET maxima_longnames POST_BUILD COMMAND ${CMAKE_STRIP} maxima_longnames.exe)
276 install(TARGETS winkill winkill_lib maxima_longnames COMPONENT Maxima RUNTIME DESTINATION bin LIBRARY DESTINATION bin/)
277 install(FILES "${CMAKE_SOURCE_DIR}/../interfaces/xmaxima/win32/win_signals.lisp" DESTINATION bin/ COMPONENT Maxima)
280 install(DIRECTORY ${CMAKE_BINARY_DIR}/maxima-installroot/${WINDOWS_DRIVELETTER}:/maxima-${MAXIMAVERSION}/
281 DESTINATION . COMPONENT Maxima PATTERN "binary-abcl" EXCLUDE)
283 install(DIRECTORY ${CMAKE_BINARY_DIR}/maxima-installroot/${WINDOWS_DRIVELETTER}:/maxima-${MAXIMAVERSION}/
284 DESTINATION . COMPONENT ABCL PATTERN "binary-abcl")
287 install(FILES "${CMAKE_SOURCE_DIR}/xmaxima.bat" DESTINATION bin/ COMPONENT Maxima)
288 install(FILES "${CMAKE_BINARY_DIR}/maxima-prefix/src/maxima/doc/info/maxima.pdf" DESTINATION share/doc/ COMPONENT Maxima)
289 configure_file("${CMAKE_SOURCE_DIR}/lispselector.tcl" "${CMAKE_BINARY_DIR}/lispselector.tcl")
290 install(FILES "${CMAKE_BINARY_DIR}/lispselector.tcl" DESTINATION bin/ COMPONENT Maxima)
291 install(FILES "${CMAKE_SOURCE_DIR}/lispselector.bat" DESTINATION bin/ COMPONENT Maxima)
295 # Include DLLs from the current Mingw environment.
296 install(FILES "${MINGW_LIBSTDCPP}" "${MINGW_LIBGCC}" DESTINATION bin/ COMPONENT Maxima)
298 configure_file("${CMAKE_SOURCE_DIR}/licenses.html" "${CMAKE_BINARY_DIR}/licenses.html")
299 install(FILES "${CMAKE_BINARY_DIR}/licenses.html" DESTINATION share/doc/ COMPONENT Maxima)
301 file(COPY "${CMAKE_SOURCE_DIR}/../COPYING" DESTINATION "${CMAKE_BINARY_DIR}")
302 file(READ "${CMAKE_SOURCE_DIR}/LICENSE_APPENDIX.txt" LICENSE_APPENDIX)
303 file(APPEND "${CMAKE_BINARY_DIR}/COPYING" "${LICENSE_APPENDIX}")
305 set(CPACK_GENERATOR "NSIS;ZIP")
306 set(CPACK_PACKAGE_VERSION "${MAXIMAVERSION}")
307 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Maxima")
308 set(CPACK_PACKAGE_VENDOR "Maxima Team")
309 set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/../README")
310 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_BINARY_DIR}/COPYING")
311 set(CPACK_PACKAGE_INSTALL_DIRECTORY "maxima-${CPACK_PACKAGE_VERSION}")
312 set(CPACK_NSIS_INSTALL_ROOT "${WINDOWS_DRIVELETTER}:")
313 set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
314 set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/maxima-icon.bmp")
315 set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/../interfaces/xmaxima\\\\maxima-icon.ico")
316 set(CPACK_NSIS_MUI_UNIICON "${CPACK_NSIS_MUI_ICON}")
317 set(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\maxima-command.ico")
318 set(CPACK_NSIS_DISPLAY_NAME "Maxima computer algebra system")
319 set(CPACK_PACKAGE_EXECUTABLES "..\\\\bin\\\\wxmaxima" "wxMaxima (GUI for Maxima)")
320 set(CPACK_NSIS_URL_INFO_ABOUT "https://maxima.sourceforge.io")
321 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")
322 set(CPACK_PACKAGE_FILE_NAME "maxima-${CPACK_PACKAGE_VERSION}-${INSTALLERSUFFIX}")
323 set(CPACK_NSIS_COMPRESSOR "/SOLID lzma")
326 set(CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP "${CMAKE_SOURCE_DIR}/maxima-installerimage.bmp")
329 cpack_add_component(Maxima
330 DESCRIPTION "The Maxima computer algebra system.\nRequired."
334 cpack_add_component(VTK
335 DESCRIPTION "VTK is an advanced graphic toolkit for draw().\nOptional.")
338 cpack_add_component(Gnuplot
339 DESCRIPTION "Gnuplot is the main graphic toolkit.\nInstallation is strongly recommended.")
341 cpack_add_component(wxMaxima
342 DESCRIPTION "wxMaxima is an advanced GUI for Maxima based on wxWidgets.\nInstallation is strongly recommended.")
344 cpack_add_component(Clisp
345 DESCRIPTION "The CLISP Lisp compiler.\nRequired."
348 cpack_add_component(SBCL
349 DESCRIPTION "The SBCL Lisp compiler.\nRequired."
352 cpack_add_component(TclTk
353 DISPLAY_NAME "Tcl/Tk"
354 DESCRIPTION "The TCL/TK scripting language.\nRequired."
357 cpack_add_component(ABCL
358 DESCRIPTION "The ABCL Lisp compiler.\nA Java installation is required.\nOptional.")