hedgewars/CMakeLists.txt
branchexperimental3D
changeset 4812 f924be23ffb4
parent 4457 ffb766e85150
child 4928 6ebbca960503
equal deleted inserted replaced
4347:0ddb100fea61 4812:f924be23ffb4
     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     uCaptions.pas
    47 	uCollisions.pas
    47     uChat.pas
    48 	uConsole.pas
    48     uCollisions.pas
    49 	uConsts.pas
    49     uCommands.pas
    50 	uFloat.pas
    50     uCommandHandlers.pas
    51 	uGame.pas
    51     uConsole.pas
    52 	uGears.pas
    52     uConsts.pas
    53 	uIO.pas
    53     uDebug.pas
    54 	uKeys.pas
    54     uFloat.pas
    55 	uLand.pas
    55     uGame.pas
    56 	uLandGraphics.pas
    56     uGears.pas
    57 	uLandObjects.pas
    57     uGearsRender.pas
    58 	uLandTemplates.pas
    58     uIO.pas
    59 	uLandTexture.pas
    59     uKeys.pas
    60 	uLocale.pas
    60     uLand.pas
    61 	uMisc.pas
    61     uLandGraphics.pas
    62 	uMobile.pas
    62     uLandObjects.pas
    63 	uRandom.pas
    63     uLandPainted.pas
    64 	uScript.pas
    64     uLandTemplates.pas
    65 	adler32.pas
    65     uLandTexture.pas
    66 	uSound.pas
    66     uLocale.pas
    67 	uStats.pas
    67     uMisc.pas
    68 	uStore.pas
    68     uMobile.pas
    69 	uTeams.pas
    69     uRandom.pas
    70 	uVisualGears.pas
    70     uRender.pas
    71 	uWorld.pas
    71     uRenderUtils.pas
    72 	CCHandlers.inc
    72     uScript.pas
    73 	GSHandlers.inc
    73     uSinTable.pas
    74 	VGSHandlers.inc
    74     uSound.pas
    75 	GearDrawing.inc
    75     uStats.pas
    76 	HHHandlers.inc
    76     uStore.pas
    77 	SinTable.inc
    77     uTeams.pas
    78 	ArgParsers.inc
    78     uTextures.pas
    79 	options.inc
    79     uTypes.pas
    80 	${CMAKE_CURRENT_BINARY_DIR}/config.inc
    80     uUtils.pas
    81 	)
    81     uVisualGears.pas
       
    82     uWorld.pas
       
    83     GSHandlers.inc
       
    84     VGSHandlers.inc
       
    85     HHHandlers.inc
       
    86     ArgParsers.inc
       
    87     options.inc
       
    88     adler32.pas
       
    89     ${CMAKE_CURRENT_BINARY_DIR}/config.inc
       
    90     )
    82 
    91 
    83 if(BUILD_ENGINE_LIBRARY)
    92 if(BUILD_ENGINE_LIBRARY)
    84 	message(STATUS "Engine will be built as library (experimental)")
    93     message(STATUS "Engine will be built as library (experimental)")
    85 	set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwLibrary.pas)
    94     set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwLibrary.pas)
    86 	set(engine_sources ${hwengine_project} PascalExports.pas ${engine_sources})
    95     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})
    96     set(pascal_compiler_flags_cmn "-dHWLIBRARY" "-k-no_order_inits" "-fPIC" ${pascal_compiler_flags_cmn})
    88 endif(BUILD_ENGINE_LIBRARY)
    97 endif(BUILD_ENGINE_LIBRARY)
    89 
    98 
    90 
    99 
    91 find_program(fpc_executable ${fpc_tryexe})
   100 find_program(fpc_executable ${fpc_tryexe})
    92 
   101 
    93 if(fpc_executable)
   102 if(fpc_executable)
    94 	 exec_program(${fpc_executable} ARGS "-iV" OUTPUT_VARIABLE fpc_output)
   103     exec_program(${fpc_executable} ARGS "-iV" OUTPUT_VARIABLE fpc_output)
    95 endif(fpc_executable)
   104 endif(fpc_executable)
    96 
   105 
    97 set(noexecstack_flags "-k-z" "-knoexecstack")
   106 set(noexecstack_flags "-k-z" "-knoexecstack")
    98 file(WRITE ${EXECUTABLE_OUTPUT_PATH}/checkstack.pas "begin end.")
   107 file(WRITE ${EXECUTABLE_OUTPUT_PATH}/checkstack.pas "begin end.")
    99 
   108 
   100 exec_program(${fpc_executable} ${EXECUTABLE_OUTPUT_PATH}
   109 exec_program(${fpc_executable} ${EXECUTABLE_OUTPUT_PATH}
   101 	ARGS ${noexecstack_flags} checkstack.pas
   110     ARGS ${noexecstack_flags} checkstack.pas
   102 	OUTPUT_VARIABLE noout
   111     OUTPUT_VARIABLE noout
   103 	RETURN_VALUE testnoexecstack
   112     RETURN_VALUE testnoexecstack
   104 	)
   113     )
   105 
   114 
   106 if(${testnoexecstack})
   115 if(${testnoexecstack})
   107 	set (noexecstack_flags "")
   116     set (noexecstack_flags "")
   108 endif(${testnoexecstack})
   117 endif(${testnoexecstack})
   109 
   118 
   110 
   119 
   111 if(APPLE)
   120 if(APPLE)
   112 	string(REGEX MATCH "[pP][pP][cC]+" powerpc_build "${CMAKE_OSX_ARCHITECTURES}")
   121     string(REGEX MATCH "[pP][pP][cC]+" powerpc_build "${CMAKE_OSX_ARCHITECTURES}")
   113 	string(REGEX MATCH "[iI]386+" i386_build "${CMAKE_OSX_ARCHITECTURES}")
   122     string(REGEX MATCH "[iI]386+" i386_build "${CMAKE_OSX_ARCHITECTURES}")
   114 	string(REGEX MATCH "[xX]86_64+" x86_64_build "${CMAKE_OSX_ARCHITECTURES}")
   123     string(REGEX MATCH "[xX]86_64+" x86_64_build "${CMAKE_OSX_ARCHITECTURES}")
   115 
   124 
   116 	if(powerpc_build)
   125     if(powerpc_build)
   117 		set(powerpc_build "powerpc")
   126         set(powerpc_build "powerpc")
   118 	endif()
   127     endif()
   119 endif(APPLE)
   128 endif(APPLE)
   120 
   129 
   121 
   130 
   122 #PASCAL DETECTION SECTION
   131 #PASCAL DETECTION SECTION
   123 string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" fpc_version "${fpc_output}")
   132 string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" fpc_version "${fpc_output}")
   124 
   133 
   125 if(fpc_version)
   134 if(fpc_version)
   126 	string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" fpc_vers_major "${fpc_version}")
   135     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}")
   136     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}")
   137     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}")
   138     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}")
   139     math(EXPR fpc_ver "${fpc_vers_major}*10000 + ${fpc_vers_minor}*100 + ${fpc_vers_patch}")
   131 
   140 
   132 	if(fpc_ver LESS "020200")
   141     if(fpc_ver LESS "020200")
   133 		message(FATAL_ERROR "Minimum required version of FreePascal is 2.2.0")
   142         message(FATAL_ERROR "Minimum required version of FreePascal is 2.2.0")
   134 	elseif(APPLE AND x86_64_build AND fpc_ver LESS "020400")
   143     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!")
   144         message(FATAL_ERROR "Minimum required version of FreePascal is 2.4.0 for building 64 bit applications!")
   136 	endif()
   145     endif()
   137 else()
   146 else()
   138 	message(FATAL_ERROR "No Pascal compiler found!")
   147     message(FATAL_ERROR "No Pascal compiler found!")
   139 endif()
   148 endif()
   140 
   149 
   141 set(pascal_compiler ${fpc_executable})
   150 set(pascal_compiler ${fpc_executable})
   142 set(pascal_compiler_flags ${noexecstack_flags} ${pascal_compiler_flags_cmn} ${hwengine_project})
   151 set(pascal_compiler_flags ${noexecstack_flags} ${pascal_compiler_flags_cmn} ${hwengine_project})
   143 
   152 
   144 
   153 
   145 #DEPENDECIES AND EXECUTABLES SECTION
   154 #DEPENDECIES AND EXECUTABLES SECTION
   146 IF(NOT APPLE OR BUILD_ENGINE_LIBRARY)
   155 IF(NOT APPLE OR BUILD_ENGINE_LIBRARY)
   147 	#here is the command for standard executables or for shared library
   156     #here is the command for standard executables or for shared library
   148 	add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}"
   157     add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}"
   149 		COMMAND "${pascal_compiler}"
   158         COMMAND "${pascal_compiler}"
   150 		ARGS ${pascal_compiler_flags}
   159         ARGS ${pascal_compiler_flags}
   151 		MAIN_DEPENDENCY ${hwengine_project}
   160         MAIN_DEPENDENCY ${hwengine_project}
   152 		DEPENDS ${engine_sources}
   161         DEPENDS ${engine_sources}
   153 		)
   162         )
   154 ELSE()
   163 ELSE()
   155 	#let's build sdlmain, which is absent from the framework
   164     #let's build sdlmain, which is absent from the framework
   156 	find_package(SDL REQUIRED)
   165     find_package(SDL REQUIRED)
   157 
   166 
   158 	set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
   167     set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
   159 	include_directories(${SDL_INCLUDE_DIR})
   168     include_directories(${SDL_INCLUDE_DIR})
   160 
   169 
   161 	add_library (SDLmain STATIC SDLMain.m)
   170     add_library (SDLmain STATIC SDLMain.m)
   162 
   171 
   163 
   172 
   164 	#these are the dependencies for building a universal binary on Mac OS X
   173     #these are the dependencies for building a universal binary on Mac OS X
   165 	foreach (build_arch ${powerpc_build} ${i386_build} ${x86_64_build})
   174     foreach (build_arch ${powerpc_build} ${i386_build} ${x86_64_build})
   166 		set(lipo_args_list "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}" ${lipo_args_list})
   175         set(lipo_args_list "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}" ${lipo_args_list})
   167 		add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}"
   176         add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}"
   168 			COMMAND "${pascal_compiler}"
   177             COMMAND "${pascal_compiler}"
   169 			ARGS ${pascal_compiler_flags} -ohwengine.${build_arch} -P${build_arch}
   178             ARGS ${pascal_compiler_flags} -ohwengine.${build_arch} -P${build_arch}
   170 			MAIN_DEPENDENCY ${hwengine_project}
   179             MAIN_DEPENDENCY ${hwengine_project}
   171 			DEPENDS ${engine_sources} SDLmain lua
   180             DEPENDS ${engine_sources} SDLmain lua
   172 			)
   181             )
   173 		add_custom_target(hwengine.${build_arch} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}")
   182         add_custom_target(hwengine.${build_arch} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}")
   174 	endforeach()
   183     endforeach()
   175 
   184 
   176 	add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine"
   185     add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine"
   177 		COMMAND "lipo"
   186         COMMAND "lipo"
   178 		ARGS ${lipo_args_list} -create -output ${EXECUTABLE_OUTPUT_PATH}/hwengine
   187         ARGS ${lipo_args_list} -create -output ${EXECUTABLE_OUTPUT_PATH}/hwengine
   179 		DEPENDS ${lipo_args_list}
   188         DEPENDS ${lipo_args_list}
   180 		)
   189         )
   181 ENDIF()
   190 ENDIF()
   182 
   191 
   183 
   192 
   184 add_custom_target(hwengine ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}")
   193 add_custom_target(hwengine ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}")
   185 
   194