ZoriaRPG

WIP Cmake file for ZC+MinGW 2

Mar 30th, 2020
673
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. cmake_minimum_required(VERSION 3.5)
  2. set(CMAKE_CONFIGURATION_TYPES Debug Release CACHE TYPE INTERNAL FORCE)
  3. project (ZeldaClassic)
  4.  
  5. set(USE_PCH FALSE CACHE BOOL "Use precompiled headers")
  6. set(UNITY_BUILD FALSE CACHE BOOL "Unity build")
  7.  
  8. set(CMAKE_CXX_STANDARD 98)
  9. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  10. option(WANT_ZSCRIPT "Enable ZScript Compiler" on)
  11.  
  12. if(UNIX AND NOT APPLE)
  13.     set(LINUX TRUE)
  14. endif()
  15.  
  16. function(enable_unity_build UB_SUFFIX SOURCE_VARIABLE_NAME)
  17.   set(files ${${SOURCE_VARIABLE_NAME}})
  18.   # Generate a unique filename for the unity build translation unit
  19.   set(unit_build_file ${CMAKE_CURRENT_BINARY_DIR}/UB_${UB_SUFFIX}.cpp)
  20.   # Exclude all translation units from compilation
  21.   set_source_files_properties(${files} PROPERTIES HEADER_FILE_ONLY true)
  22.   # Open the ub file
  23.   FILE(WRITE ${unit_build_file} "// Unity Build generated by CMake\n")
  24.   FILE(APPEND ${unit_build_file} "#include \"${CMAKE_SOURCE_DIR}/src/precompiled.h\"\n")
  25.   # Add include statement for each translation unit
  26.   foreach(source_file ${files} )
  27.     FILE( APPEND ${unit_build_file} "#include <${CMAKE_CURRENT_SOURCE_DIR}/${source_file}>\n")
  28.   endforeach(source_file)
  29.   # Complement list of translation units with the name of ub
  30.   set(${SOURCE_VARIABLE_NAME} ${${SOURCE_VARIABLE_NAME}} ${unit_build_file} PARENT_SCOPE)
  31. endfunction(enable_unity_build)
  32.  
  33. #############################################################
  34. # Header and source file lists
  35. #############################################################
  36.  
  37. include_directories(./allegro/include)
  38. include_directories(./include/lpng1212)
  39. include_directories(./include/zlib123)
  40. include_directories(./include/loadpng)
  41. include_directories(./include/jpgalleg-2.5)
  42. include_directories(./include/dumb)
  43. include_directories(./include/alogg)
  44. include_directories(./include/almp3)
  45. include_directories(./include/gme)
  46.  
  47. set(ZCSOUNDSOURCES
  48.     src/zcmusic.cpp
  49.     src/zcmusicd.cpp
  50.     src/alleg_compat.cpp
  51. )
  52.  
  53. set(ROMVIEW_MODULES
  54.     ${CMAKE_SOURCE_DIR}/modules/romview/RomviewCore.txt
  55.     ${CMAKE_SOURCE_DIR}/modules/romview/RomviewGUI.txt
  56. )
  57.  
  58. set(ZELDA_MODULES
  59.     ${CMAKE_SOURCE_DIR}/modules/zelda/ZeldaCore.txt
  60.     ${CMAKE_SOURCE_DIR}/modules/zelda/ZeldaGUI.txt
  61.     ${CMAKE_SOURCE_DIR}/modules/zelda/ZeldaSprite.txt
  62.     ${CMAKE_SOURCE_DIR}/modules/zelda/ZeldaSubscreen.txt
  63. )
  64.  
  65. set(ZQUEST_MODULES
  66.     ${CMAKE_SOURCE_DIR}/modules/zquest/ZQuestCore.txt
  67.     ${CMAKE_SOURCE_DIR}/modules/zquest/ZQuestGUI.txt
  68.     ${CMAKE_SOURCE_DIR}/modules/zquest/ZQuestMisc.txt
  69.     ${CMAKE_SOURCE_DIR}/modules/zquest/ZQuestZScript.txt
  70.     ${CMAKE_SOURCE_DIR}/modules/zquest/ZQuestZScriptNP.txt
  71. )
  72.  
  73. foreach(module ${ROMVIEW_MODULES} ${ZELDA_MODULES} ${ZQUEST_MODULES})
  74.     include(${module})
  75.     set_source_files_properties(${module} PROPERTIES HEADER_FILE_ONLY true)
  76. endforeach()
  77.  
  78. #############################################################
  79. # Build the ZScript parser
  80. #############################################################
  81.  
  82. find_package(BISON QUIET)
  83. find_package(FLEX QUIET)
  84.  
  85. if(${BISON_FOUND} AND ${FLEX_FOUND} AND WANT_ZSCRIPT)
  86.     if(MSVC)
  87.         set(FLEXFLAGS "--wincompat")
  88.     endif()
  89.     FLEX_TARGET(ZScriptLexer ${CMAKE_SOURCE_DIR}/src/parser/ffscript.lpp ${CMAKE_SOURCE_DIR}/src/parser/lex.yy.cpp COMPILE_FLAGS ${FLEXFLAGS})
  90.     BISON_TARGET(ZScriptParser ${CMAKE_SOURCE_DIR}/src/parser/ffscript.ypp ${CMAKE_SOURCE_DIR}/src/parser/y.tab.cpp COMPILE_FLAGS -v)
  91.     add_flex_bison_dependency(ZScriptLexer ZScriptParser)
  92. else()
  93.     message(WARNING "Flex and Bison not found. ZQuest will be compiled without the ZScript parser.")
  94.     set(ZQUEST_ZSCRIPT_SOURCES ${ZQUEST_ZSCRIPT_SOURCES_NOPARSER})
  95. endif()
  96.  
  97.  
  98. #############################################################
  99. # Global settings for the different platforms
  100. #############################################################
  101.  
  102.  
  103. # Windows
  104.  
  105. if(MSVC)
  106.     set(ALLEGROLIB "$<$<CONFIG:DEBUG>:${CMAKE_SOURCE_DIR}/libs/win32dbg/alleg44-debug.lib>"
  107.                    "$<$<CONFIG:RELEASE>:${CMAKE_SOURCE_DIR}/libs/win32/alleg44.lib>")
  108.                    
  109.  
  110.     add_definitions(-DALLEGRO_MSVC)
  111.  
  112.     set(IMAGELIBS "$<$<CONFIG:DEBUG>:${CMAKE_SOURCE_DIR}/libs/win32dbg/al_gif.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32dbg/libpng.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32dbg/zlibd.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32dbg/loadpng.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32dbg/libjpgal.lib>"
  113.                   "$<$<CONFIG:RELEASE>:${CMAKE_SOURCE_DIR}/libs/win32/al_gif.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32/libpng.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32/zlib.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32/loadpng.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32/libjpgal.lib>")
  114.  
  115.     set(SOUNDLIBS "$<$<CONFIG:DEBUG>:${CMAKE_SOURCE_DIR}/libs/win32dbg/aldmd.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32dbg/almp3.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32dbg/alogg.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32dbg/dumbd.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32dbg/gme.lib>"
  116.                   "$<$<CONFIG:RELEASE>:${CMAKE_SOURCE_DIR}/libs/win32/aldmb.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32/almp3.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32/alogg.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32/dumb.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32/gme.lib>")
  117.  
  118.     if(MSVC_VERSION GREATER 1500)
  119.         add_definitions(-DALLEGRO_HAVE_STDINT_H)
  120.     endif()
  121.  
  122.     add_compile_options("$<$<CONFIG:DEBUG>:/MTd>")
  123.     add_compile_options("$<$<CONFIG:RELEASE>:/MT>")
  124.  
  125.     # REQUIRED or else MSVC throws internal compiler error(!)
  126.     add_compile_options("$<$<CONFIG:RELEASE>:/fp:fast>")
  127.     add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  128.     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:LIBCD /SUBSYSTEM:WINDOWS /DEBUG")
  129.  
  130.     if(USE_PCH)
  131.         set(ZCPrecompiledBinary "${CMAKE_CURRENT_BINARY_DIR}/zcprecompiled.pch")
  132.         set(ZQPrecompiledBinary "${CMAKE_CURRENT_BINARY_DIR}/zqprecompiled.pch")
  133.         set_source_files_properties(src/precompiledzc.cpp PROPERTIES COMPILE_FLAGS "/Ycprecompiled.h /Fp\"${ZCPrecompiledBinary}\"" OBJECT_OUTPUTS "${ZCPrecompiledBinary}")
  134.         set_source_files_properties(src/precompiledzq.cpp PROPERTIES COMPILE_FLAGS "/Ycprecompiled.h /Fp\"${ZQPrecompiledBinary}\"" OBJECT_OUTPUTS "${ZQPrecompiledBinary}")
  135.         list(APPEND ZELDAEXTRASOURCES src/precompiledzc.cpp)
  136.         list(APPEND ZQUESTEXTRASOURCES src/precompiledzq.cpp)
  137.     endif()
  138.  
  139. elseif(MINGW)
  140.  
  141.     set(ALLEGRO_MINGW32 1)
  142.     set(ALLEGRO_WINDOWS 1)
  143.     # Guess MINGDIR from the value of CMAKE_C_COMPILER if it's not set.
  144.     if("$ENV{MINGDIR}" STREQUAL "")
  145.         string(REGEX REPLACE "/bin/[^/]*$" "" MINGDIR "${CMAKE_C_COMPILER}")
  146.         message(STATUS "Guessed MinGW directory: ${MINGDIR}")
  147.     else("$ENV{MINGDIR}" STREQUAL "")
  148.         file(TO_CMAKE_PATH "$ENV{MINGDIR}" MINGDIR)
  149.         message(STATUS "Using MINGDIR: ${MINGDIR}")
  150.     endif("$ENV{MINGDIR}" STREQUAL "")
  151.  
  152.     # Search in MINGDIR for headers and libraries.
  153.     set(CMAKE_PREFIX_PATH "${MINGDIR}")
  154.  
  155.     # Install to MINGDIR
  156.     if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  157.         set(CMAKE_INSTALL_PREFIX ${MINGDIR})
  158.     endif()
  159.  
  160.     message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
  161.    
  162.     set(ALLEGROLIB
  163.         ${CMAKE_SOURCE_DIR}/libs/mingw/liballeg.a
  164.     )
  165.                    
  166.     set(IMAGELIBS
  167.         ${CMAKE_SOURCE_DIR}/libs/mingw/libpng.a
  168.         ${CMAKE_SOURCE_DIR}/libs/mingw/libz.a
  169.         ${CMAKE_SOURCE_DIR}/libs/mingw/libldpng.a
  170.         $${CMAKE_SOURCE_DIR}/libs/mingw/libjpgal.a
  171.     )
  172.  
  173.     #${CMAKE_SOURCE_DIR}/libs/mingw/al_gif.lib
  174.     #${CMAKE_SOURCE_DIR}/libs/win32/al_gif.lib
  175.    
  176.     set(SOUNDLIBS
  177.         ${CMAKE_SOURCE_DIR}/libs/mingw/libaldmb.a
  178.         ${CMAKE_SOURCE_DIR}/libs/mingw/libalmp3.a
  179.         ${CMAKE_SOURCE_DIR}/libs/mingw/libalogg.a
  180.         ${CMAKE_SOURCE_DIR}/libs/mingw/libdumb.a
  181.         ${CMAKE_SOURCE_DIR}/libs/mingw/libgme.a
  182.     )
  183.    
  184.     add_definitions(-DALLEGRO_MSVC) # Mistakenly used in the source.
  185.     execute_process(COMMAND "${CMAKE_SOURCE_DIR}/allegro/configure --enable-static=yes --enable-shared=no --enable-ossdigi=no --enable-ossmidi=no --enable-esddigi=no --enable-artsdigi=no --enable-sgialdigi=no --enable-jackdigi=no --enable-xwin-dga2=no --enable-vga=no --enable-svgalib=no" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/allegro")
  186.  
  187.  
  188.    
  189. # Linux
  190.  
  191. elseif(LINUX)
  192.     link_directories(/usr/lib/i386-linux-gnu)
  193.     link_directories(./libs/linux)
  194.     set(ALLEGROLIB alleg)
  195.     add_definitions(-DALLEGRO_UNIX)
  196.     add_definitions(-DALLEGRO_LINUX) # Mistakenly used in the source.
  197.     execute_process(COMMAND "${CMAKE_SOURCE_DIR}/allegro/configure --enable-static=yes --enable-shared=no --enable-ossdigi=no --enable-ossmidi=no --enable-esddigi=no --enable-artsdigi=no --enable-sgialdigi=no --enable-jackdigi=no --enable-xwin-dga2=no --enable-vga=no --enable-svgalib=no" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/allegro")
  198.  
  199.     set(IMAGELIBS algif ldpng jpgal png z)
  200.     set(SOUNDLIBS aldmb almp3 alogg dumb gme asound)
  201.     set(X11_LIBRARIES X11 Xext Xcursor Xxf86vm pthread Xpm dl)
  202.  
  203.     add_compile_options("-m32")
  204.     SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32 -static-libgcc -export-dynamic")
  205.     SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32 -static-libgcc")
  206. endif()
  207.  
  208.  
  209. #############################################################
  210. # Sound Library
  211. #############################################################
  212.  
  213. if(MSVC AND (MSVC_VERSION GREATER 1600))
  214.     set(ZCSOUNDLIBSEXTRA legacy_stdio_definitions)
  215. endif()
  216. add_library(zcsound SHARED ${ZCSOUNDSOURCES})
  217. target_link_libraries(zcsound ${ALLEGROLIB} ${SOUNDLIBS} ${ZCSOUNDLIBSEXTRA})
  218.  
  219. #############################################################
  220. # Romview
  221. #############################################################
  222.  
  223. if(MSVC)
  224.     list(APPEND ROMVIEWEXTRASOURCES rv_icon.rc)
  225. elseif(LINUX)
  226.     list(APPEND ROMVIEWEXTRASOURCES rv_icon.c)
  227.     set(ROMVIEWLIBSEXTRA ${X11_LIBRARIES})
  228. endif()
  229.  
  230. if(UNITY_BUILD)
  231.     enable_unity_build(RomviewCore ROMVIEW_CORE_SOURCES)
  232.     enable_unity_build(RomviewGUI ROMVIEW_GUI_SOURCES)
  233. endif()
  234.  
  235. add_executable(romview ${ROMVIEW_CORE_SOURCES} ${ROMVIEW_GUI_SOURCES} ${ROMVIEWEXTRASOURCES} ${ROMVIEW_MODULES})
  236.  
  237. target_link_libraries(romview ${IMAGELIBS} ${ALLEGROLIB} ${SOUNDLIBS} ${ROMVIEWLIBSEXTRA})
  238.  
  239. #############################################################
  240. # Zelda
  241. #############################################################
  242.  
  243.  
  244.  
  245.  
  246. if(MSVC)
  247.     list(APPEND ZELDAEXTRASOURCES zc_icon.rc)
  248.  
  249. elseif(LINUX)
  250.     list(APPEND ZELDAEXTRASOURCES zc_icon.c src/single_instance_unix.cpp)
  251.     set(ZELDALIBSEXTRA ${X11_LIBRARIES})
  252. endif()
  253.  
  254. if(UNITY_BUILD)
  255.     enable_unity_build(ZeldaCore ZELDA_CORE_SOURCES)
  256.     enable_unity_build(ZeldaGUI ZELDA_GUI_SOURCES)
  257.     enable_unity_build(ZeldaSprite ZELDA_SPRITE_SOURCES)
  258.     enable_unity_build(ZeldaSubscreen ZELDA_SUBSCREEN_SOURCES)
  259. endif()
  260.  
  261. add_executable(zelda ${ZELDA_CORE_SOURCES} ${ZELDA_GUI_SOURCES} ${ZELDA_SPRITE_SOURCES} ${ZELDA_SUBSCREEN_SOURCES} ${ZELDA_SCRIPTING_SOURCES} ${ZELDAEXTRASOURCES} ${ZELDA_MODULES})
  262.  
  263. if(WIN32)
  264.     target_link_libraries(zelda zcsound winmm ${IMAGELIBS} ${ALLEGROLIB} ${ZELDALIBSEXTRA})
  265. elseif(LINUX)
  266.     target_link_libraries(zelda zcsound ${IMAGELIBS} ${ALLEGROLIB} ${ZELDALIBSEXTRA})
  267. endif()
  268.  
  269.  
  270. if(MSVC AND USE_PCH)
  271.     set_target_properties(zelda PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h /Fp\"${ZCPrecompiledBinary}\"" OBJECT_DEPENDS "${ZCPrecompiledBinary}")
  272.     target_compile_definitions(zelda PRIVATE ZC_PCH)
  273. endif()
  274.  
  275. #############################################################
  276. # ZQuest
  277. #############################################################
  278.  
  279. if(MSVC)
  280.     list(APPEND ZQUESTEXTRASOURCES zq_icon.rc)
  281. elseif(LINUX)
  282.     list(APPEND ZQUESTEXTRASOURCES zq_icon.c src/single_instance_unix.cpp)
  283.     set(ZQUESTLIBSEXTRA ${X11_LIBRARIES})
  284. endif()
  285.  
  286. if(UNITY_BUILD)
  287.     enable_unity_build(ZQuestCore ZQUEST_CORE_SOURCES)
  288.     enable_unity_build(ZQuestGUI ZQUEST_GUI_SOURCES)
  289.     enable_unity_build(ZQuestMisc ZQUEST_MISC_SOURCES)
  290.     enable_unity_build(ZQuestZScript ZQUEST_ZSCRIPT_SOURCES)
  291. endif()
  292.  
  293. add_executable(zquest ${ZQUEST_CORE_SOURCES} ${ZQUEST_GUI_SOURCES} ${ZQUEST_MISC_SOURCES} ${ZQUEST_ZSCRIPT_SOURCES} ${ZQUESTEXTRASOURCES} ${BISON_ZScriptParser_OUTPUTS} ${FLEX_ZScriptLexer_OUTPUTS} ${ZQUEST_MODULES})
  294.  
  295. target_link_libraries(zquest zcsound ${IMAGELIBS} ${ALLEGROLIB} ${ZQUESTLIBSEXTRA})
  296. if(MSVC AND USE_PCH)
  297.     set_target_properties(zquest PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h /Fp\"${ZQPrecompiledBinary}\"" OBJECT_DEPENDS "${ZQPrecompiledBinary}")
  298.     target_compile_definitions(zquest PRIVATE ZC_PCH)
  299. endif()
  300.  
  301. if(MSVC)
  302.     target_compile_definitions(zcsound PRIVATE ZCM_DLL)
  303.     target_compile_definitions(zelda PRIVATE ZCM_DLL_IMPORT)
  304.     target_compile_definitions(zquest PRIVATE ZCM_DLL_IMPORT)
  305. endif()
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×