cmake_minimum_required(VERSION 3.13) project(WEP VERSION 0 LANGUAGES C) find_package(SDL2 REQUIRED) add_subdirectory(cards) include_directories(cards) if(NOT MSVC) add_compile_options(-Wall -Wextra -pedantic) endif() set(games sol freecell) set(tools exe2ico ico2png) foreach(game ${games}) add_executable(${game} MACOSX_BUNDLE ${game}.c) target_link_libraries(${game} cards) # Work around possible bugs in SDL2Config.cmake if(MINGW) target_link_libraries(${game} mingw32) set_target_properties(${game} PROPERTIES WIN32_EXECUTABLE 1) endif() target_link_libraries(${game} SDL2::SDL2main SDL2::SDL2) # Avoid conflicting with SOL.EXE, FREECELL.EXE on Windows if(WIN32) set_target_properties(${game} PROPERTIES OUTPUT_NAME wep${game}) endif() set_target_properties( ${game} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/MacOSXBundleInfo.plist.in MACOSX_BUNDLE_GUI_IDENTIFIER agency.causal.wep.${game} MACOSX_BUNDLE_SHORT_VERSION_STRING "Version ${CMAKE_PROJECT_VERSION}" MACOSX_BUNDLE_COPYRIGHT "Copyright 2019 June McEnroe" ) endforeach() if(APPLE) set_target_properties( sol PROPERTIES OUTPUT_NAME Solitaire MACOSX_BUNDLE_BUNDLE_NAME Solitaire ) set_target_properties( freecell PROPERTIES OUTPUT_NAME FreeCell MACOSX_BUNDLE_BUNDLE_NAME FreeCell ) endif() foreach(tool ${tools}) add_executable(${tool} EXCLUDE_FROM_ALL tools/${tool}.c) target_link_libraries(${tool} SDL2::SDL2) endforeach() set( WEP_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH "Directory containing WEP DLLs and EXEs" ) set( SOL_DIRECTORY ${WEP_DIRECTORY} CACHE PATH "Directory containing SOL.EXE" ) set(cards_dll ${WEP_DIRECTORY}/CARDS.DLL) if(NOT EXISTS ${cards_dll}) set(cards_dll ${SOL_DIRECTORY}/SOL.EXE) endif() if(EXISTS ${cards_dll}) foreach(game ${games}) target_sources(${game} PRIVATE ${cards_dll}) set_target_properties(${game} PROPERTIES RESOURCE ${cards_dll}) endforeach() endif() set(freecell_exe ${WEP_DIRECTORY}/FREECELL.EXE) if(EXISTS ${freecell_exe}) target_sources(freecell PRIVATE ${freecell_exe}) set_target_properties( freecell PROPERTIES RESOURCE "${cards_dll};${freecell_exe}" ) endif() foreach(game ${games}) string(TOUPPER ${game} shouting) set(game_exe ${WEP_DIRECTORY}/${shouting}.EXE) if(NOT EXISTS ${game_exe}) continue() endif() add_custom_command( OUTPUT ${shouting}.ICO COMMAND exe2ico ${game_exe} DEPENDS ${game_exe} VERBATIM ) if(APPLE) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${game}.iconset) foreach(scale 1 2 4 8 16) math(EXPR size "32 * ${scale}") add_custom_command( OUTPUT ${game}.iconset/icon_${size}x${size}.png COMMAND ico2png ${shouting}.ICO ${scale}x ${game}.iconset/icon_${size}x${size}.png DEPENDS ${shouting}.ICO VERBATIM ) endforeach() add_custom_command( OUTPUT ${game}.icns COMMAND iconutil -c icns ${game}.iconset DEPENDS ${game}.iconset/icon_32x32.png ${game}.iconset/icon_64x64.png ${game}.iconset/icon_128x128.png ${game}.iconset/icon_256x256.png ${game}.iconset/icon_512x512.png VERBATIM ) target_sources(${game} PRIVATE ${game}.icns) get_property(game_resource TARGET ${game} PROPERTY RESOURCE) set_target_properties( ${game} PROPERTIES RESOURCE "${game_resource};${game}.icns" MACOSX_BUNDLE_ICON_FILE ${game}.icns ) elseif(WIN32) file( GENERATE OUTPUT ${game}.rc CONTENT "IDI_ICON1 ICON DISCARDABLE \"${shouting}.ICO\"\n" ) target_sources(${game} PRIVATE ${game}.rc ${shouting}.ICO) endif() endforeach() install(TARGETS ${games} BUNDLE DESTINATION /Applications)