aboutsummaryrefslogtreecommitdiff
path: root/cmake/platforms
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/platforms')
-rw-r--r--cmake/platforms/emscripten.cmake47
-rw-r--r--cmake/platforms/nestedvm.cmake60
-rw-r--r--cmake/platforms/osx.cmake58
-rw-r--r--cmake/platforms/unix.cmake68
-rw-r--r--cmake/platforms/windows.cmake40
5 files changed, 273 insertions, 0 deletions
diff --git a/cmake/platforms/emscripten.cmake b/cmake/platforms/emscripten.cmake
new file mode 100644
index 0000000..d6b5cd2
--- /dev/null
+++ b/cmake/platforms/emscripten.cmake
@@ -0,0 +1,47 @@
+set(platform_common_sources emcc.c)
+set(platform_gui_libs)
+set(platform_libs)
+set(CMAKE_EXECUTABLE_SUFFIX ".js")
+
+set(emcc_export_list
+ # Event handlers for mouse and keyboard input
+ _mouseup
+ _mousedown
+ _mousemove
+ _key
+ # Callback when the program activates timing
+ _timer_callback
+ # Callback from button presses in the UI outside the canvas
+ _command
+ # Game-saving and game-loading functions
+ _get_save_file
+ _free_save_file
+ _load_game
+ # Callbacks to return values from dialog boxes
+ _dlg_return_sval
+ _dlg_return_ival
+ # Callbacks when the resizing controls are used
+ _resize_puzzle
+ _restore_puzzle_size
+ # Main program, run at initialisation time
+ _main)
+
+list(TRANSFORM emcc_export_list PREPEND \")
+list(TRANSFORM emcc_export_list APPEND \")
+string(JOIN "," emcc_export_string ${emcc_export_list})
+set(CMAKE_C_LINK_FLAGS "-s ASM_JS=1 -s EXPORTED_FUNCTIONS='[${emcc_export_string}]'")
+message("link=${CMAKE_C_LINK_EXECUTABLE}")
+
+set(build_cli_programs FALSE)
+
+function(get_platform_puzzle_extra_source_files OUTVAR NAME)
+ set(${OUTVAR} PARENT_SCOPE)
+endfunction()
+
+function(set_platform_puzzle_target_properties NAME TARGET)
+ em_link_pre_js(${TARGET} ${CMAKE_SOURCE_DIR}/emccpre.js)
+ em_link_js_library(${TARGET} ${CMAKE_SOURCE_DIR}/emcclib.js)
+endfunction()
+
+function(build_platform_extras)
+endfunction()
diff --git a/cmake/platforms/nestedvm.cmake b/cmake/platforms/nestedvm.cmake
new file mode 100644
index 0000000..e5de2ee
--- /dev/null
+++ b/cmake/platforms/nestedvm.cmake
@@ -0,0 +1,60 @@
+set(platform_common_sources nestedvm.c printing.c)
+set(platform_libs -lm)
+
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/applet.manifest
+ "Main-Class: PuzzleApplet\n")
+
+include(FindJava)
+add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/PuzzleApplet.class
+ COMMAND ${Java_JAVAC_EXECUTABLE}
+ -source 1.7 -target 1.7 -d . -cp ${NESTEDVM}/build
+ ${CMAKE_SOURCE_DIR}/PuzzleApplet.java
+ DEPENDS ${CMAKE_SOURCE_DIR}/PuzzleApplet.java)
+
+function(get_platform_puzzle_extra_source_files OUTVAR NAME)
+ set(${OUTVAR} PARENT_SCOPE)
+endfunction()
+
+function(set_platform_puzzle_target_properties NAME TARGET)
+ set(build_subdir ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}-tmp)
+
+ add_custom_command(OUTPUT ${build_subdir}
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${build_subdir})
+ add_custom_command(OUTPUT ${build_subdir}/PuzzleApplet.class
+ COMMAND ${CMAKE_SOURCE_DIR}/cmake/glob-symlinks.py
+ ${CMAKE_BINARY_DIR} applet.manifest
+ ${CMAKE_BINARY_DIR} PuzzleApplet\\*.class
+ ${NESTEDVM}/build org/ibex/nestedvm/Registers.class
+ ${NESTEDVM}/build org/ibex/nestedvm/UsermodeConstants.class
+ ${NESTEDVM}/build org/ibex/nestedvm/Runtime*.class
+ ${NESTEDVM}/build org/ibex/nestedvm/util/Platform\\*.class
+ ${NESTEDVM}/build org/ibex/nestedvm/util/Seekable\\*.class
+ WORKING_DIRECTORY ${build_subdir}
+ DEPENDS
+ ${build_subdir}
+ ${CMAKE_BINARY_DIR}/PuzzleApplet.class
+ ${CMAKE_SOURCE_DIR}/cmake/glob-symlinks.py)
+
+ add_custom_command(OUTPUT ${build_subdir}/PuzzleEngine.class
+ COMMAND ${Java_JAVA_EXECUTABLE}
+ -cp ${NESTEDVM}/build:${NESTEDVM}/upstream/build/classgen/build
+ org.ibex.nestedvm.Compiler -outformat class -d .
+ PuzzleEngine ${CMAKE_CURRENT_BINARY_DIR}/${EXENAME}
+ DEPENDS
+ ${build_subdir}
+ ${CMAKE_CURRENT_BINARY_DIR}/${EXENAME}
+ WORKING_DIRECTORY ${build_subdir})
+
+ add_custom_target(${TARGET}-jar ALL
+ COMMAND ${Java_JAR_EXECUTABLE}
+ cfm ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jar
+ applet.manifest PuzzleEngine.class PuzzleApplet*.class org
+ WORKING_DIRECTORY ${build_subdir}
+ DEPENDS
+ ${CMAKE_BINARY_DIR}/PuzzleApplet.class
+ ${build_subdir}/PuzzleApplet.class
+ ${build_subdir}/PuzzleEngine.class)
+endfunction()
+
+function(build_platform_extras)
+endfunction()
diff --git a/cmake/platforms/osx.cmake b/cmake/platforms/osx.cmake
new file mode 100644
index 0000000..4577a73
--- /dev/null
+++ b/cmake/platforms/osx.cmake
@@ -0,0 +1,58 @@
+set(CMAKE_OSX_DEPLOYMENT_TARGET 10.6)
+find_program(HALIBUT halibut REQUIRED)
+set(CPACK_GENERATOR DragNDrop)
+set(CPACK_PACKAGE_FILE_NAME Puzzles)
+set(CPACK_DMG_VOLUME_NAME "Simon Tatham's Puzzle Collection")
+include(CPack)
+set(build_individual_puzzles FALSE)
+
+function(get_platform_puzzle_extra_source_files OUTVAR NAME)
+ set(${OUTVAR} PARENT_SCOPE)
+endfunction()
+
+function(set_platform_puzzle_target_properties NAME TARGET)
+endfunction()
+
+function(build_platform_extras)
+ write_generated_games_header()
+
+ set(resources
+ ${CMAKE_CURRENT_SOURCE_DIR}/osx/Puzzles.icns)
+ set_source_files_properties(${resources} PROPERTIES
+ MACOSX_PACKAGE_LOCATION Resources)
+
+ add_executable(puzzles MACOSX_BUNDLE
+ osx.m list.c ${puzzle_sources}
+ ${resources})
+
+ set_target_properties(puzzles PROPERTIES
+ OUTPUT_NAME Puzzles
+ MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/osx/Info.plist)
+
+ target_compile_definitions(puzzles PRIVATE COMBINED)
+ target_include_directories(puzzles PRIVATE ${generated_include_dir})
+ target_link_libraries(puzzles common ${platform_gui_libs} ${platform_libs}
+ "-framework Cocoa")
+
+ get_property(bundle_basename TARGET puzzles PROPERTY OUTPUT_NAME)
+ set(help_dir ${CMAKE_CURRENT_BINARY_DIR}/${bundle_basename}.app/Contents/Resources/Help)
+ message(${help_dir})
+ add_custom_command(OUTPUT ${help_dir}
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${help_dir}
+ DEPENDS puzzles)
+ add_custom_command(OUTPUT ${help_dir}/index.html
+ COMMAND ${HALIBUT} --html
+ ${CMAKE_CURRENT_SOURCE_DIR}/osx-help.but
+ ${CMAKE_CURRENT_SOURCE_DIR}/puzzles.but
+ DEPENDS
+ ${help_dir}
+ ${CMAKE_CURRENT_SOURCE_DIR}/osx-help.but
+ ${CMAKE_CURRENT_SOURCE_DIR}/puzzles.but
+ WORKING_DIRECTORY ${help_dir})
+ add_custom_target(osx_help ALL
+ DEPENDS ${help_dir}/index.html)
+
+ install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Puzzles.app
+ USE_SOURCE_PERMISSIONS
+ DESTINATION .)
+endfunction()
diff --git a/cmake/platforms/unix.cmake b/cmake/platforms/unix.cmake
new file mode 100644
index 0000000..1bed675
--- /dev/null
+++ b/cmake/platforms/unix.cmake
@@ -0,0 +1,68 @@
+find_package(PkgConfig REQUIRED)
+
+set(PUZZLES_GTK_FOUND FALSE)
+macro(try_gtk_package VER PACKAGENAME)
+ if(NOT PUZZLES_GTK_FOUND AND
+ (NOT DEFINED PUZZLES_GTK_VERSION OR
+ PUZZLES_GTK_VERSION STREQUAL ${VER}))
+ pkg_check_modules(GTK ${PACKAGENAME})
+ if(GTK_FOUND)
+ set(PUZZLES_GTK_FOUND TRUE)
+ endif()
+ endif()
+endmacro()
+
+try_gtk_package(3 gtk+-3.0)
+try_gtk_package(2 gtk+-2.0)
+
+if(NOT PUZZLES_GTK_FOUND)
+ message(FATAL_ERROR "Unable to find any usable version of GTK.")
+endif()
+
+include_directories(${GTK_INCLUDE_DIRS})
+link_directories(${GTK_LIBRARY_DIRS})
+
+set(platform_common_sources gtk.c printing.c)
+set(platform_gui_libs ${GTK_LIBRARIES})
+
+set(platform_libs -lm)
+
+set(build_icons TRUE)
+
+function(try_append_cflag flag)
+ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
+ try_compile(compile_passed ${CMAKE_BINARY_DIR}
+ SOURCES ${CMAKE_SOURCE_DIR}/cmake/testbuild.c
+ OUTPUT_VARIABLE test_compile_output
+ CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${GTK_INCLUDE_DIRS}")
+ if(compile_passed)
+ set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} PARENT_SCOPE)
+ endif()
+endfunction()
+if (CMAKE_C_COMPILER_ID MATCHES "GNU" OR
+ CMAKE_C_COMPILER_ID MATCHES "Clang")
+ try_append_cflag(-Wall)
+ try_append_cflag(-Werror)
+ try_append_cflag(-std=c89)
+ try_append_cflag(-pedantic)
+ try_append_cflag(-Wwrite-strings)
+endif()
+
+function(get_platform_puzzle_extra_source_files OUTVAR NAME)
+ if(build_icons AND EXISTS ${CMAKE_SOURCE_DIR}/icons/${NAME}.sav)
+ build_icon(${NAME})
+ set(c_icon_file ${CMAKE_BINARY_DIR}/icons/${NAME}-icon.c)
+ else()
+ set(c_icon_file ${CMAKE_SOURCE_DIR}/no-icon.c)
+ endif()
+
+ set(${OUTVAR} ${c_icon_file} PARENT_SCOPE)
+endfunction()
+
+function(set_platform_puzzle_target_properties NAME TARGET)
+ install(TARGETS ${TARGET})
+endfunction()
+
+function(build_platform_extras)
+endfunction()
diff --git a/cmake/platforms/windows.cmake b/cmake/platforms/windows.cmake
new file mode 100644
index 0000000..dd27148
--- /dev/null
+++ b/cmake/platforms/windows.cmake
@@ -0,0 +1,40 @@
+set(platform_common_sources windows.c printing.c)
+
+set(platform_gui_libs
+ user32.lib gdi32.lib comctl32.lib comdlg32.lib winspool.lib)
+
+set(platform_libs)
+
+add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
+
+function(get_platform_puzzle_extra_source_files OUTVAR NAME)
+ set(${OUTVAR} ${CMAKE_SOURCE_DIR}/puzzles.rc PARENT_SCOPE)
+endfunction()
+
+function(set_platform_puzzle_target_properties NAME TARGET)
+ if(DEFINED ICO_DIR AND EXISTS ${ICO_DIR}/${NAME}.ico)
+ target_compile_definitions(${TARGET} PRIVATE ICON_FILE=\"${ICO_DIR}/${NAME}.ico\")
+ endif()
+ set_target_properties(${TARGET} PROPERTIES WIN32_EXECUTABLE ON)
+endfunction()
+
+function(build_platform_extras)
+ write_generated_games_header()
+
+ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gamedesc.txt "")
+ list(SORT puzzle_names)
+ foreach(name ${puzzle_names})
+ file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/gamedesc.txt "\
+${name}:\
+${exename_${name}}.exe:\
+${displayname_${name}}:\
+${description_${name}}:\
+${objective_${name}}\n")
+ endforeach()
+
+ add_executable(puzzles windows.c list.c ${puzzle_sources})
+ target_compile_definitions(puzzles PRIVATE COMBINED)
+ target_include_directories(puzzles PRIVATE ${generated_include_dir})
+ target_link_libraries(puzzles common ${platform_gui_libs} ${platform_libs})
+ set_target_properties(puzzles PROPERTIES WIN32_EXECUTABLE ON)
+endfunction()