hedgewars/CMakeLists.txt
changeset 4357 a1fcfc341a52
parent 4158 08f4627ad2b3
child 4373 fe0e3903bb9e
equal deleted inserted replaced
4355:4554c4df9f1a 4357:a1fcfc341a52
     9 
     9 
    10 #find which version of SDL_image and SDL_mixer we have (for IMG_Init and Mix_Init)
    10 #find which version of SDL_image and SDL_mixer we have (for IMG_Init and Mix_Init)
    11 #if the headers are not installed, the newer apis won't be activated
    11 #if the headers are not installed, the newer apis won't be activated
    12 find_file(sdlmixer_h SDL_mixer.h ${SDLMIXER_INCLUDE_DIR})
    12 find_file(sdlmixer_h SDL_mixer.h ${SDLMIXER_INCLUDE_DIR})
    13 if(sdlmixer_h)
    13 if(sdlmixer_h)
    14 	file(STRINGS ${sdlmixer_h} sdlmixer_version_tmp REGEX "SDL_MIXER_PATCHLEVEL[\t' ']+[0-9]+")
    14     file(STRINGS ${sdlmixer_h} sdlmixer_version_tmp REGEX "SDL_MIXER_PATCHLEVEL[\t' ']+[0-9]+")
    15 	string(REGEX MATCH ".([0-9]+)" sdlmixer_version "${sdlmixer_version_tmp}")
    15     string(REGEX MATCH ".([0-9]+)" sdlmixer_version "${sdlmixer_version_tmp}")
    16 
    16 
    17 	if(sdlmixer_version GREATER 9)
    17     if(sdlmixer_version GREATER 9)
    18 		message(STATUS "Enabling enhanced SDL_Mixer calls")
    18         message(STATUS "Enabling enhanced SDL_Mixer calls")
    19 		set(pascal_compiler_flags_cmn "-dSDL_MIXER_NEWER" ${pascal_compiler_flags_cmn})
    19         set(pascal_compiler_flags_cmn "-dSDL_MIXER_NEWER" ${pascal_compiler_flags_cmn})
    20 	endif()
    20     endif()
    21 endif()
    21 endif()
    22 
    22 
    23 find_file(sdlimage_h SDL_image.h ${SDLIMAGE_INCLUDE_DIR})
    23 find_file(sdlimage_h SDL_image.h ${SDLIMAGE_INCLUDE_DIR})
    24 if(sdlimage_h)
    24 if(sdlimage_h)
    25 	file(STRINGS ${sdlimage_h} sdlimage_version_tmp REGEX "SDL_IMAGE_PATCHLEVEL[\t' ']+[0-9]+")
    25     file(STRINGS ${sdlimage_h} sdlimage_version_tmp REGEX "SDL_IMAGE_PATCHLEVEL[\t' ']+[0-9]+")
    26 	string(REGEX MATCH ".([0-9]+)" sdlimage_version "${sdlimage_version_tmp}")
    26     string(REGEX MATCH ".([0-9]+)" sdlimage_version "${sdlimage_version_tmp}")
    27 
    27 
    28 	if(sdlimage_version GREATER 7)
    28     if(sdlimage_version GREATER 7)
    29 		message(STATUS "Enabling enhanced SDL_Image calls")
    29         message(STATUS "Enabling enhanced SDL_Image calls")
    30 		set(pascal_compiler_flags_cmn "-dSDL_IMAGE_NEWER" ${pascal_compiler_flags_cmn})
    30         set(pascal_compiler_flags_cmn "-dSDL_IMAGE_NEWER" ${pascal_compiler_flags_cmn})
    31 	endif()
    31     endif()
    32 endif()
    32 endif()
    33 
    33 
    34 #SOURCE AND PROGRAMS SECTION
    34 #SOURCE AND PROGRAMS SECTION
    35 set(fpc_tryexe fpc)
    35 set(fpc_tryexe fpc)
    36 set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwengine.pas)
    36 set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwengine.pas)
    37 
    37 
    38 set(engine_sources
    38 set(engine_sources
    39 	${hwengine_project}
    39     ${hwengine_project}
    40 	SDLh.pas
    40     SDLh.pas
    41 	uAI.pas
    41     uAI.pas
    42 	uAIActions.pas
    42     uAIActions.pas
    43 	uAIAmmoTests.pas
    43     uAIAmmoTests.pas
    44 	uAIMisc.pas
    44     uAIMisc.pas
    45 	uAmmos.pas
    45     uAmmos.pas
    46 	uChat.pas
    46     uChat.pas
    47 	uCollisions.pas
    47     uCollisions.pas
    48 	uConsole.pas
    48     uConsole.pas
    49 	uConsts.pas
    49     uConsts.pas
    50 	uFloat.pas
    50     uFloat.pas
    51 	uGame.pas
    51     uGame.pas
    52 	uGears.pas
    52     uGears.pas
    53 	uIO.pas
    53     uIO.pas
    54 	uKeys.pas
    54     uKeys.pas
    55 	uLand.pas
    55     uLand.pas
    56 	uLandGraphics.pas
    56     uLandGraphics.pas
    57 	uLandObjects.pas
    57     uLandObjects.pas
    58 	uLandTemplates.pas
    58     uLandTemplates.pas
    59 	uLandTexture.pas
    59     uLandTexture.pas
    60 	uLocale.pas
    60     uLocale.pas
    61 	uMisc.pas
    61     uMisc.pas
    62 	uMobile.pas
    62     uMobile.pas
    63 	uRandom.pas
    63     uRandom.pas
    64 	uScript.pas
    64     uScript.pas
    65 	adler32.pas
    65     adler32.pas
    66 	uSound.pas
    66     uSound.pas
    67 	uStats.pas
    67     uStats.pas
    68 	uStore.pas
    68     uStore.pas
    69 	uTeams.pas
    69     uTeams.pas
    70 	uVisualGears.pas
    70     uTypes.pas
    71 	uWorld.pas
    71     uVisualGears.pas
    72 	CCHandlers.inc
    72     uWorld.pas
    73 	GSHandlers.inc
    73     CCHandlers.inc
    74 	VGSHandlers.inc
    74     GSHandlers.inc
    75 	GearDrawing.inc
    75     VGSHandlers.inc
    76 	HHHandlers.inc
    76     GearDrawing.inc
    77 	SinTable.inc
    77     HHHandlers.inc
    78 	ArgParsers.inc
    78     SinTable.inc
    79 	options.inc
    79     ArgParsers.inc
    80 	${CMAKE_CURRENT_BINARY_DIR}/config.inc
    80     options.inc
    81 	)
    81     ${CMAKE_CURRENT_BINARY_DIR}/config.inc
       
    82     )
    82 
    83 
    83 if(BUILD_ENGINE_LIBRARY)
    84 if(BUILD_ENGINE_LIBRARY)
    84 	message(STATUS "Engine will be built as library (experimental)")
    85     message(STATUS "Engine will be built as library (experimental)")
    85 	set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwLibrary.pas)
    86     set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwLibrary.pas)
    86 	set(engine_sources ${hwengine_project} PascalExports.pas ${engine_sources})
    87     set(engine_sources ${hwengine_project} PascalExports.pas ${engine_sources})
    87 	set(pascal_compiler_flags_cmn "-dHWLIBRARY" "-k-no_order_inits" "-fPIC" ${pascal_compiler_flags_cmn})
    88     set(pascal_compiler_flags_cmn "-dHWLIBRARY" "-k-no_order_inits" "-fPIC" ${pascal_compiler_flags_cmn})
    88 endif(BUILD_ENGINE_LIBRARY)
    89 endif(BUILD_ENGINE_LIBRARY)
    89 
    90 
    90 
    91 
    91 find_program(fpc_executable ${fpc_tryexe})
    92 find_program(fpc_executable ${fpc_tryexe})
    92 
    93 
    93 if(fpc_executable)
    94 if(fpc_executable)
    94 	 exec_program(${fpc_executable} ARGS "-iV" OUTPUT_VARIABLE fpc_output)
    95     exec_program(${fpc_executable} ARGS "-iV" OUTPUT_VARIABLE fpc_output)
    95 endif(fpc_executable)
    96 endif(fpc_executable)
    96 
    97 
    97 set(noexecstack_flags "-k-z" "-knoexecstack")
    98 set(noexecstack_flags "-k-z" "-knoexecstack")
    98 file(WRITE ${EXECUTABLE_OUTPUT_PATH}/checkstack.pas "begin end.")
    99 file(WRITE ${EXECUTABLE_OUTPUT_PATH}/checkstack.pas "begin end.")
    99 
   100 
   100 exec_program(${fpc_executable} ${EXECUTABLE_OUTPUT_PATH}
   101 exec_program(${fpc_executable} ${EXECUTABLE_OUTPUT_PATH}
   101 	ARGS ${noexecstack_flags} checkstack.pas
   102     ARGS ${noexecstack_flags} checkstack.pas
   102 	OUTPUT_VARIABLE noout
   103     OUTPUT_VARIABLE noout
   103 	RETURN_VALUE testnoexecstack
   104     RETURN_VALUE testnoexecstack
   104 	)
   105     )
   105 
   106 
   106 if(${testnoexecstack})
   107 if(${testnoexecstack})
   107 	set (noexecstack_flags "")
   108     set (noexecstack_flags "")
   108 endif(${testnoexecstack})
   109 endif(${testnoexecstack})
   109 
   110 
   110 
   111 
   111 if(APPLE)
   112 if(APPLE)
   112 	string(REGEX MATCH "[pP][pP][cC]+" powerpc_build "${CMAKE_OSX_ARCHITECTURES}")
   113     string(REGEX MATCH "[pP][pP][cC]+" powerpc_build "${CMAKE_OSX_ARCHITECTURES}")
   113 	string(REGEX MATCH "[iI]386+" i386_build "${CMAKE_OSX_ARCHITECTURES}")
   114     string(REGEX MATCH "[iI]386+" i386_build "${CMAKE_OSX_ARCHITECTURES}")
   114 	string(REGEX MATCH "[xX]86_64+" x86_64_build "${CMAKE_OSX_ARCHITECTURES}")
   115     string(REGEX MATCH "[xX]86_64+" x86_64_build "${CMAKE_OSX_ARCHITECTURES}")
   115 
   116 
   116 	if(powerpc_build)
   117     if(powerpc_build)
   117 		set(powerpc_build "powerpc")
   118         set(powerpc_build "powerpc")
   118 	endif()
   119     endif()
   119 endif(APPLE)
   120 endif(APPLE)
   120 
   121 
   121 
   122 
   122 #PASCAL DETECTION SECTION
   123 #PASCAL DETECTION SECTION
   123 string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" fpc_version "${fpc_output}")
   124 string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" fpc_version "${fpc_output}")
   124 
   125 
   125 if(fpc_version)
   126 if(fpc_version)
   126 	string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" fpc_vers_major "${fpc_version}")
   127     string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" fpc_vers_major "${fpc_version}")
   127 	string(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" fpc_vers_minor "${fpc_version}")
   128     string(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" fpc_vers_minor "${fpc_version}")
   128 	string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" fpc_vers_patch "${fpc_version}")
   129     string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" fpc_vers_patch "${fpc_version}")
   129 	message(STATUS "Freepascal version detected: ${fpc_vers_major}.${fpc_vers_minor}")
   130     message(STATUS "Freepascal version detected: ${fpc_vers_major}.${fpc_vers_minor}")
   130 	math(EXPR fpc_ver "${fpc_vers_major}*10000 + ${fpc_vers_minor}*100 + ${fpc_vers_patch}")
   131     math(EXPR fpc_ver "${fpc_vers_major}*10000 + ${fpc_vers_minor}*100 + ${fpc_vers_patch}")
   131 
   132 
   132 	if(fpc_ver LESS "020200")
   133     if(fpc_ver LESS "020200")
   133 		message(FATAL_ERROR "Minimum required version of FreePascal is 2.2.0")
   134         message(FATAL_ERROR "Minimum required version of FreePascal is 2.2.0")
   134 	elseif(APPLE AND x86_64_build AND fpc_ver LESS "020400")
   135     elseif(APPLE AND x86_64_build AND fpc_ver LESS "020400")
   135 		message(FATAL_ERROR "Minimum required version of FreePascal is 2.4.0 for building 64 bit applications!")
   136         message(FATAL_ERROR "Minimum required version of FreePascal is 2.4.0 for building 64 bit applications!")
   136 	endif()
   137     endif()
   137 else()
   138 else()
   138 	message(FATAL_ERROR "No Pascal compiler found!")
   139     message(FATAL_ERROR "No Pascal compiler found!")
   139 endif()
   140 endif()
   140 
   141 
   141 set(pascal_compiler ${fpc_executable})
   142 set(pascal_compiler ${fpc_executable})
   142 set(pascal_compiler_flags ${noexecstack_flags} ${pascal_compiler_flags_cmn} ${hwengine_project})
   143 set(pascal_compiler_flags ${noexecstack_flags} ${pascal_compiler_flags_cmn} ${hwengine_project})
   143 
   144 
   144 
   145 
   145 #DEPENDECIES AND EXECUTABLES SECTION
   146 #DEPENDECIES AND EXECUTABLES SECTION
   146 IF(NOT APPLE OR BUILD_ENGINE_LIBRARY)
   147 IF(NOT APPLE OR BUILD_ENGINE_LIBRARY)
   147 	#here is the command for standard executables or for shared library
   148     #here is the command for standard executables or for shared library
   148 	add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}"
   149     add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}"
   149 		COMMAND "${pascal_compiler}"
   150         COMMAND "${pascal_compiler}"
   150 		ARGS ${pascal_compiler_flags}
   151         ARGS ${pascal_compiler_flags}
   151 		MAIN_DEPENDENCY ${hwengine_project}
   152         MAIN_DEPENDENCY ${hwengine_project}
   152 		DEPENDS ${engine_sources}
   153         DEPENDS ${engine_sources}
   153 		)
   154         )
   154 ELSE()
   155 ELSE()
   155 	#let's build sdlmain, which is absent from the framework
   156     #let's build sdlmain, which is absent from the framework
   156 	find_package(SDL REQUIRED)
   157     find_package(SDL REQUIRED)
   157 
   158 
   158 	set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
   159     set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
   159 	include_directories(${SDL_INCLUDE_DIR})
   160     include_directories(${SDL_INCLUDE_DIR})
   160 
   161 
   161 	add_library (SDLmain STATIC SDLMain.m)
   162     add_library (SDLmain STATIC SDLMain.m)
   162 
   163 
   163 
   164 
   164 	#these are the dependencies for building a universal binary on Mac OS X
   165     #these are the dependencies for building a universal binary on Mac OS X
   165 	foreach (build_arch ${powerpc_build} ${i386_build} ${x86_64_build})
   166     foreach (build_arch ${powerpc_build} ${i386_build} ${x86_64_build})
   166 		set(lipo_args_list "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}" ${lipo_args_list})
   167         set(lipo_args_list "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}" ${lipo_args_list})
   167 		add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}"
   168         add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}"
   168 			COMMAND "${pascal_compiler}"
   169             COMMAND "${pascal_compiler}"
   169 			ARGS ${pascal_compiler_flags} -ohwengine.${build_arch} -P${build_arch}
   170             ARGS ${pascal_compiler_flags} -ohwengine.${build_arch} -P${build_arch}
   170 			MAIN_DEPENDENCY ${hwengine_project}
   171             MAIN_DEPENDENCY ${hwengine_project}
   171 			DEPENDS ${engine_sources} SDLmain lua
   172             DEPENDS ${engine_sources} SDLmain lua
   172 			)
   173             )
   173 		add_custom_target(hwengine.${build_arch} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}")
   174         add_custom_target(hwengine.${build_arch} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}")
   174 	endforeach()
   175     endforeach()
   175 
   176 
   176 	add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine"
   177     add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine"
   177 		COMMAND "lipo"
   178         COMMAND "lipo"
   178 		ARGS ${lipo_args_list} -create -output ${EXECUTABLE_OUTPUT_PATH}/hwengine
   179         ARGS ${lipo_args_list} -create -output ${EXECUTABLE_OUTPUT_PATH}/hwengine
   179 		DEPENDS ${lipo_args_list}
   180         DEPENDS ${lipo_args_list}
   180 		)
   181         )
   181 ENDIF()
   182 ENDIF()
   182 
   183 
   183 
   184 
   184 add_custom_target(hwengine ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}")
   185 add_custom_target(hwengine ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}")
   185 
   186