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)
81 option(WITH_CCL64 "Include CCL64 in the installer." NO)
83 # SBCL and CLISP have both advantages and disadvantages:
84 # - SBCL is fast, but sometimes runs out of memory in places it really shouldn't
85 # (Loading LAPACK on IA32, for example) and isn't too happy with changing to
86 # non-ascii-non-unicode pathnames (which wxMaxima works around by now, though,
87 # and which Xmaxima doesn't evven try to do)
88 # - CLISP is slow. And version 2.49 only sends valid output over the network
89 # if the front-end is slow enough. Test cases: Running a demo, all commands
90 # with loads of compiler output (load("draw"); for the first time) or just
91 # receiving a batch of new autocompletion symbols. Since the libraries the
92 # front-ends use have evolved in the last years it has become easy to
93 # trigger this => Setting SBCL to be the default.
94 # - ABCL (optional) is a Java based Lisp.
96 set(WITH_DEFAULT_LISP "sbcl" CACHE STRING "Which Lisp should be used by default (clisp/sbcl/abcl)?")
97 set_property(CACHE WITH_DEFAULT_LISP PROPERTY STRINGS "clisp" "sbcl" "abcl")
101 set(WITH_DEFAULT_LISP "sbcl" CACHE STRING "Which Lisp should be used by default (clisp/sbcl)?")
102 set_property(CACHE WITH_DEFAULT_LISP PROPERTY STRINGS "clisp" "sbcl")
103 set(ABCL_STYLE "display: none;")
107 # If you want to use a updated version of a program,
108 # update the version number and the checksum.
109 # If no further patches are needed, you should get a
110 # updated setup-file automatically.
112 # current program versions
113 set(CLISPVERSION 2.49)
116 # MD5 checksums for the current program versions.
117 set(CLISP_MD5 "8d58d64f83dd7ad01c054aecc16c1f52")
120 set(USE_WXMAXIMA_GIT YES)
121 set(MAXIMAVERSION "current")
123 # Get Maxima version from configure.ac
124 file(STRINGS "${CMAKE_SOURCE_DIR}/../configure.ac" CONFIGUREAC REGEX "AC_INIT\\(.*\\)")
125 string(REGEX REPLACE "AC_INIT\\(\\[maxima\\],[ \t\r\n]*\\[(.*)\\]\\)" "\\1" MAXIMAVERSION ${CONFIGUREAC})
126 message(STATUS "Maxima version (from configure.ac): ${MAXIMAVERSION}")
129 # The HTML documentation is installed in a directory depending on "git describe",
130 # when building from Git, e.g.:
131 # share/maxima/branch_5_45_base_99_g0b3357e40_dirty/doc/html/maxima_singlepage.html
132 # Otherwise the version number is included, e.g something like:
133 # share/maxima/5.45.1/doc/html/maxima_singlepage.html
134 # Set it first to the second variant, if Git is found and we are building
135 # from a Git tree use the result of "git describe --dirty" in the path instead - where
136 # "-" are changed to "_" (see commit d5d04f2 and the file '../configure.ac').
137 set(MAXIMA_SINGLEPAGE_HTML "share/maxima/${MAXIMAVERSION}/doc/html/maxima_singlepage.html")
140 execute_process(COMMAND ${GIT_EXECUTABLE} describe --dirty
141 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
142 OUTPUT_VARIABLE GIT_DESCRIBE
144 OUTPUT_STRIP_TRAILING_WHITESPACE)
146 string(REPLACE "-" "_" GIT_DESCRIBE ${GIT_DESCRIBE})
147 set(MAXIMA_SINGLEPAGE_HTML "share/maxima/${GIT_DESCRIBE}/doc/html/maxima_singlepage.html")
152 set(CLISP_URL "https://downloads.sourceforge.net/project/clisp/clisp/${CLISPVERSION}/clisp-${CLISPVERSION}-win32-mingw-big.zip")
155 # Where are libgcc and libstdc++?
156 # Seems difficult. On Ubuntu 22.04 and 20.04 (64bit) the library libgcc is called libgcc_s_seh-1.dll.
157 # 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
159 execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-file-name=libgcc_s_seh-1.dll OUTPUT_VARIABLE MINGW_LIBGCC OUTPUT_STRIP_TRAILING_WHITESPACE)
161 execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-file-name=libgcc_s_sjlj-1.dll OUTPUT_VARIABLE MINGW_LIBGCC OUTPUT_STRIP_TRAILING_WHITESPACE)
162 if("${MINGW_LIBGCC}" STREQUAL "libgcc_s_sjlj-1.dll")
163 # "${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.
164 execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-file-name=libgcc_s_dw2-1.dll OUTPUT_VARIABLE MINGW_LIBGCC OUTPUT_STRIP_TRAILING_WHITESPACE)
168 execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-file-name=libstdc++-6.dll OUTPUT_VARIABLE MINGW_LIBSTDCPP OUTPUT_STRIP_TRAILING_WHITESPACE)
170 message(STATUS "Found libstdc++ at ${MINGW_LIBSTDCPP}")
172 message(STATUS "Found libgcc at ${MINGW_LIBGCC}")
174 add_subdirectory("wine/")
176 find_program(SEVENZIP_EXE NAMES 7z)
179 message(STATUS "Found 7z at ${SEVENZIP_EXE}")
181 message(FATAL_ERROR "7z not found. It is required for crosscompiling Maxima.")
184 # Avoid warnings in CMake >= 3.24:
185 # FIXME: Policy OLD is needed for texinfo, it does not build with the policy NEW
186 # But policy OLD is deprecated and may be removed in future CMake versions, see:
187 # https://cmake.org/cmake/help/latest/policy/CMP0135.html
188 # Hopefully texinfo solves that issue.
189 if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.24)
190 cmake_policy(SET CMP0135 OLD)
193 include(ExternalProject)
196 # Clisp (already a binary package just extract it...)
198 # What is the difference between clisp-2.49-win32-mingw-big.zip and clisp-2.49-win32-mingw-small.zip?
199 # What should be used for running Maxima?
200 externalproject_add(clisp
202 DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/downloads
208 install(DIRECTORY ${CMAKE_BINARY_DIR}/clisp-prefix/src/clisp/ DESTINATION clisp-${CLISPVERSION} COMPONENT Clisp)
210 add_subdirectory("sbcl/")
212 add_subdirectory("gnuplot/")
214 add_subdirectory("tcltk/")
216 add_subdirectory("texinfo/")
218 add_subdirectory("wxwidgets/")
220 add_subdirectory("wxmaxima/")
223 add_subdirectory("vtk/")
226 set(VTK_STYLE "display: none;")
230 add_subdirectory("abcl/")
231 set(ABCL_ENABLE "--enable-abcl")
232 set(ABCL_DEPENDS "abcl")
233 set(ABCL_JAR "--with-abcl-jar=${CMAKE_BINARY_DIR}/abcl/abcl-prefix/src/abcl/abcl.jar")
240 add_subdirectory("ccl/")
241 set(CCL64_ENABLE "--enable-ccl64")
242 set(CCL64_DEPENDS "ccl")
243 set(CCL64_EXECUTABLE "--with-ccl64=${CMAKE_BINARY_DIR}/wine-ccl.sh")
244 configure_file("${CMAKE_SOURCE_DIR}/wine-ccl.sh.tmpl" "${CMAKE_BINARY_DIR}/wine-ccl.sh")
248 set(CCL64_DEPENDS "")
249 set(CCL64_EXECUTABLE "")
253 configure_file("${CMAKE_SOURCE_DIR}/wine-clisp.sh.tmpl" "${CMAKE_BINARY_DIR}/wine-clisp.sh")
254 configure_file("${CMAKE_SOURCE_DIR}/wine-lisp.sh.tmpl" "${CMAKE_BINARY_DIR}/wine-lisp.sh")
255 configure_file("${CMAKE_SOURCE_DIR}/wine-sbcl.sh.tmpl" "${CMAKE_BINARY_DIR}/wine-sbcl.sh")
257 externalproject_add(maxima
258 # first copy the maxima source to a build directory, since out-of-source-builds do not work
259 DOWNLOAD_COMMAND rsync -a --exclude=crosscompile-windows/build/ "${CMAKE_SOURCE_DIR}/../" "${CMAKE_BINARY_DIR}/maxima-prefix/src/maxima"
260 DEPENDS clisp sbcl tcl tk texinfo ${ABCL_DEPENDS} ${CCL64_DEPENDS}
262 CONFIGURE_COMMAND sh -c "test -x ./bootstrap && ./bootstrap || return 0"
263 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}" ${CCL64_ENABLE} "${CCL64_EXECUTABLE}" --with-default-lisp=${WITH_DEFAULT_LISP} --prefix=${WINDOWS_DRIVELETTER}:/maxima-${MAXIMAVERSION}
264 # clisp-depends.mk is generated with "\" as path separator, not "/" - correct that...
265 BUILD_COMMAND LANG=C $(MAKE) -C src clisp-depends.mk
266 COMMAND sed -i s+\\\\+/+g src/clisp-depends.mk
267 COMMAND PATH=${CMAKE_BINARY_DIR}/texinfo-installroot/bin:$ENV{PATH} LANG=C $(MAKE)
268 COMMAND PATH=${CMAKE_BINARY_DIR}/texinfo-installroot/bin:$ENV{PATH} LANG=C $(MAKE) pdf
269 INSTALL_COMMAND PATH=${CMAKE_BINARY_DIR}/texinfo-installroot/bin:$ENV{PATH} LANG=C $(MAKE) install DESTDIR=${CMAKE_BINARY_DIR}/maxima-installroot/
270 COMMAND PATH=${CMAKE_BINARY_DIR}/texinfo-installroot/bin:$ENV{PATH} LANG=C $(MAKE) extradocinstall DESTDIR=${CMAKE_BINARY_DIR}/maxima-installroot/
274 option(STRIP_HELPERPROGRAMS "Strip the included helper programs (winkill, winkill_lib, maxima_longnames)." YES)
276 # crosscompiling winkill with autoconf does not work, compile it using CMake.
277 add_library(winkill_lib SHARED ${CMAKE_SOURCE_DIR}/../interfaces/xmaxima/win32/winkill_lib.c)
278 add_executable(winkill ${CMAKE_SOURCE_DIR}/../interfaces/xmaxima/win32/winkill.c)
279 set_target_properties(winkill_lib PROPERTIES PREFIX "") # remove 'lib' prefix from libwinkill_lib.dll
280 target_link_libraries(winkill winkill_lib)
282 # convert windows short names to long names (e.g.
283 # "C:/Users/TESTTE~1/AppData/Local/Temp" to "C:/Users/test test/AppData/Local/Temp")
284 # CLISP can (currently not handle short names.
285 add_executable(maxima_longnames maxima_longnames.c)
286 if(STRIP_HELPERPROGRAMS)
287 add_custom_command(TARGET winkill POST_BUILD COMMAND ${CMAKE_STRIP} winkill.exe)
288 add_custom_command(TARGET winkill_lib POST_BUILD COMMAND ${CMAKE_STRIP} winkill_lib.dll)
289 add_custom_command(TARGET maxima_longnames POST_BUILD COMMAND ${CMAKE_STRIP} maxima_longnames.exe)
291 install(TARGETS winkill winkill_lib maxima_longnames COMPONENT Maxima RUNTIME DESTINATION bin LIBRARY DESTINATION bin/)
292 install(FILES "${CMAKE_SOURCE_DIR}/../interfaces/xmaxima/win32/win_signals.lisp" DESTINATION bin/ COMPONENT Maxima)
295 install(DIRECTORY ${CMAKE_BINARY_DIR}/maxima-installroot/${WINDOWS_DRIVELETTER}:/maxima-${MAXIMAVERSION}/
296 DESTINATION . COMPONENT Maxima PATTERN "binary-abcl" EXCLUDE PATTERN "binary-ccl64" EXCLUDE)
298 install(DIRECTORY ${CMAKE_BINARY_DIR}/maxima-installroot/${WINDOWS_DRIVELETTER}:/maxima-${MAXIMAVERSION}/
299 DESTINATION . COMPONENT ABCL PATTERN "binary-abcl")
302 install(DIRECTORY ${CMAKE_BINARY_DIR}/maxima-installroot/${WINDOWS_DRIVELETTER}:/maxima-${MAXIMAVERSION}/
303 DESTINATION . COMPONENT CCL64 PATTERN "binary-ccl64")
306 install(FILES "${CMAKE_SOURCE_DIR}/xmaxima.bat" DESTINATION bin/ COMPONENT Maxima)
307 install(FILES "${CMAKE_BINARY_DIR}/maxima-prefix/src/maxima/doc/info/maxima.pdf" DESTINATION share/doc/ COMPONENT Maxima)
308 configure_file("${CMAKE_SOURCE_DIR}/lispselector.tcl" "${CMAKE_BINARY_DIR}/lispselector.tcl")
309 install(FILES "${CMAKE_BINARY_DIR}/lispselector.tcl" DESTINATION bin/ COMPONENT Maxima)
310 install(FILES "${CMAKE_SOURCE_DIR}/lispselector.bat" DESTINATION bin/ COMPONENT Maxima)
314 # Include DLLs from the current Mingw environment.
315 install(FILES "${MINGW_LIBSTDCPP}" "${MINGW_LIBGCC}" DESTINATION bin/ COMPONENT Maxima)
317 configure_file("${CMAKE_SOURCE_DIR}/licenses.html" "${CMAKE_BINARY_DIR}/licenses.html")
318 install(FILES "${CMAKE_BINARY_DIR}/licenses.html" DESTINATION share/doc/ COMPONENT Maxima)
320 file(COPY "${CMAKE_SOURCE_DIR}/../COPYING" DESTINATION "${CMAKE_BINARY_DIR}")
321 file(READ "${CMAKE_SOURCE_DIR}/LICENSE_APPENDIX.txt" LICENSE_APPENDIX)
322 file(APPEND "${CMAKE_BINARY_DIR}/COPYING" "${LICENSE_APPENDIX}")
324 set(CPACK_GENERATOR "NSIS;ZIP")
325 set(CPACK_PACKAGE_VERSION "${MAXIMAVERSION}")
326 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Maxima")
327 set(CPACK_PACKAGE_VENDOR "Maxima Team")
328 set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/../README")
329 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_BINARY_DIR}/COPYING")
330 set(CPACK_PACKAGE_INSTALL_DIRECTORY "maxima-${CPACK_PACKAGE_VERSION}")
331 set(CPACK_NSIS_INSTALL_ROOT "${WINDOWS_DRIVELETTER}:")
332 set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
333 set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/maxima-icon.bmp")
334 set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/../interfaces/xmaxima\\\\maxima-icon.ico")
335 set(CPACK_NSIS_MUI_UNIICON "${CPACK_NSIS_MUI_ICON}")
336 set(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\maxima-command.ico")
337 set(CPACK_NSIS_DISPLAY_NAME "Maxima computer algebra system")
338 set(CPACK_PACKAGE_EXECUTABLES "..\\\\bin\\\\wxmaxima" "wxMaxima (GUI for Maxima)")
339 set(CPACK_NSIS_URL_INFO_ABOUT "https://maxima.sourceforge.io")
340 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")
341 set(CPACK_PACKAGE_FILE_NAME "maxima-${CPACK_PACKAGE_VERSION}-${INSTALLERSUFFIX}")
342 set(CPACK_NSIS_COMPRESSOR "/SOLID lzma")
345 set(CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP "${CMAKE_SOURCE_DIR}/maxima-installerimage.bmp")
348 cpack_add_component(Maxima
349 DESCRIPTION "The Maxima computer algebra system.\nRequired."
353 cpack_add_component(VTK
354 DESCRIPTION "VTK is an advanced graphic toolkit for draw().\nOptional.")
357 cpack_add_component(Gnuplot
358 DESCRIPTION "Gnuplot is the main graphic toolkit.\nInstallation is strongly recommended.")
360 cpack_add_component(wxMaxima
361 DESCRIPTION "wxMaxima is an advanced GUI for Maxima based on wxWidgets.\nInstallation is strongly recommended.")
363 cpack_add_component(Clisp
364 DESCRIPTION "The CLISP Lisp compiler.\nRequired."
367 cpack_add_component(SBCL
368 DESCRIPTION "The SBCL Lisp compiler.\nRequired."
371 cpack_add_component(TclTk
372 DISPLAY_NAME "Tcl/Tk"
373 DESCRIPTION "The TCL/TK scripting language.\nRequired."
376 cpack_add_component(ABCL
377 DESCRIPTION "The ABCL Lisp compiler.\nA Java installation is required.\nOptional.")
380 cpack_add_component(CCL64
381 DESCRIPTION "The CCL (64Bit) Lisp compiler.\nOptional.")