cmake_minimum_required(VERSION 3.13) project(WEP 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 ) endforeach() if(APPLE) set_target_properties(sol PROPERTIES OUTPUT_NAME Solitaire) set_target_properties(freecell PROPERTIES OUTPUT_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) add_custom_command( OUTPUT ${shouting}.PNG COMMAND ico2png ${shouting}.ICO DEPENDS ${shouting}.ICO VERBATIM ) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${game}.iconset) add_custom_command( OUTPUT ${game}.iconset/icon_32x32.png COMMAND cp ${shouting}.PNG ${game}.iconset/icon_32x32.png DEPENDS ${shouting}.PNG VERBATIM ) add_custom_command( OUTPUT ${game}.icns COMMAND iconutil -c icns ${game}.iconset DEPENDS ${game}.iconset/icon_32x32.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)