hedgewars/CMakeLists.txt
author nemo
Sat, 23 May 2009 18:26:16 +0000
changeset 2096 356468481e74
parent 2016 73b0bcc4396d
child 2191 20c62f787a4d
permissions -rw-r--r--
set Minefield to 150%, reduce fort distance by 512px

configure_file(${hedgewars_SOURCE_DIR}/hedgewars/proto.inc.in 
	${CMAKE_CURRENT_BINARY_DIR}/proto.inc)

set(fpc_tryexe fpc)
set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwengine.dpr)

set(engine_sources
	${hwengine_project}
	SDLh.pas
	uAI.pas
	uAIActions.pas
	uAIAmmoTests.pas
	uAIMisc.pas
	uAmmos.pas
	uChat.pas
	uCollisions.pas
	uConsole.pas
	uConsts.pas
	uFloat.pas
	uGame.pas
	uGears.pas
	uIO.pas
	uKeys.pas
	uLand.pas
	uLandGraphics.pas
	uLandObjects.pas
	uLandTemplates.pas
	uLandTexture.pas
	uLocale.pas
	uMisc.pas
	uRandom.pas
	uSHA.pas
	uSound.pas
	uStats.pas
	uStore.pas
	uTeams.pas
	uTriggers.pas
	uVisualGears.pas
	uWorld.pas
	CCHandlers.inc
	GSHandlers.inc
	HHHandlers.inc
	SinTable.inc
	options.inc
	${CMAKE_CURRENT_BINARY_DIR}/proto.inc
	tunsetborder.inc
	)

find_program(fpc_executable ${fpc_tryexe})

if (fpc_executable)
	 exec_program(${fpc_executable} ARGS "-h" OUTPUT_VARIABLE fpc_output)
endif (fpc_executable)

set (noexecstack_flags "-k-z" "-knoexecstack")
file(WRITE ${EXECUTABLE_OUTPUT_PATH}/checkstack.pas "begin end.")

exec_program(${fpc_executable} ${EXECUTABLE_OUTPUT_PATH}
		ARGS ${noexecstack_flags} checkstack.pas
		OUTPUT_VARIABLE noout
		RETURN_VALUE testnoexecstack)

if (${testnoexecstack})
set (noexecstack_flags "")
endif (${testnoexecstack})

IF(APPLE)

	FIND_PACKAGE(SDL)

	if (SDL_FOUND)
		#removing previous version of library
		exec_program(rm
			ARGS -f ${EXECUTABLE_OUTPUT_PATH}/libSDLmain.a ${EXECUTABLE_OUTPUT_PATH}/SDLMain.o
			OUTPUT_VARIABLE noout
			RETURN_VALUE testnoexecstack
			)

		#get what architectures to build
		if(universal_build MATCHES "1")
			set (arch_to_build "-arch i386 -arch ppc7400")
		else(universal_build MATCHES "1")
			set (arch_to_build "")
		endif(universal_build MATCHES "1")

		#build, archive and make lib
		exec_program(${CMAKE_C_COMPILER}
			ARGS ${arch_to_build} -o ${EXECUTABLE_OUTPUT_PATH}/SDLMain.o -c ${hedgewars_SOURCE_DIR}/hedgewars/SDLMain.m -I ${SDL_INCLUDE_DIR} -O2
			OUTPUT_VARIABLE noout
			)
		exec_program(${CMAKE_AR}
			ARGS -rvu ${EXECUTABLE_OUTPUT_PATH}/libSDLmain.a ${EXECUTABLE_OUTPUT_PATH}/SDLMain.o
			OUTPUT_VARIABLE noout
			)
		exec_program(${CMAKE_RANLIB}
			ARGS ${EXECUTABLE_OUTPUT_PATH}/libSDLmain.a
			OUTPUT_VARIABLE noout
			)
	else (SDL_FOUND)
		message(FATAL_ERROR "No SDL framework found!")
	endif (SDL_FOUND)

ENDIF(APPLE)


string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" fpc_version "${fpc_output}")
if (fpc_version)
	string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" fpc_vers_major "${fpc_version}")
	string(REGEX REPLACE "[0-9]+\\.([0-9])+\\.[0-9]+" "\\1" fpc_vers_minor "${fpc_version}")
	string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" fpc_vers_patch "${fpc_version}")
	math(EXPR fpc_ver "${fpc_vers_major}*10000 + ${fpc_vers_minor}*100 + ${fpc_vers_patch}")
	if (fpc_ver LESS "020200")
		message("Minimum required version of FreePascal is 2.2.0")
	else (fpc_ver LESS "020200")
		set(pascal_compiler ${fpc_executable})
		set(pascal_compiler_flags ${noexecstack_flags} "-B" "-FE../bin" "-Fl../bin" "-Cs2000000" "-vwi" "-O2" ${hwengine_project})
	endif (fpc_ver LESS "020200")
endif (fpc_version)

if (NOT pascal_compiler)
	message(FATAL_ERROR "No Pascal compiler found!")
endif (NOT pascal_compiler)


IF(NOT APPLE OR NOT universal_build MATCHES "1")
#here is the standard command for any system
add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}"
		COMMAND "${pascal_compiler}"
		ARGS ${pascal_compiler_flags}
		MAIN_DEPENDENCY ${hwengine_project}
		DEPENDS ${engine_sources}
		)

ELSE(NOT APPLE OR NOT universal_build MATCHES "1")

#these are the two dependencies for building a universal binary on Mac OS X
add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}.386"
		COMMAND "ppc386" 
		ARGS ${pascal_compiler_flags} -ohwengine.386
		MAIN_DEPENDENCY ${hwengine_project}
		DEPENDS ${engine_sources}
		)
add_custom_target(hwengine.386 ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}.386")

add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}.ppc"
		COMMAND "ppcppc"
		ARGS ${pascal_compiler_flags} -ohwengine.ppc
		MAIN_DEPENDENCY ${hwengine_project}
		DEPENDS ${engine_sources}
		)
add_custom_target(hwengine.ppc ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}.ppc")

#this is the command that bundles the two executables into one
add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}"
		COMMAND "lipo"
		ARGS ${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}.386 ${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}.ppc -create -output ${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}
		DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}.386" "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}.ppc" 
		)
ENDIF(NOT APPLE OR NOT universal_build MATCHES "1")


add_custom_target(hwengine ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}")


if(APPLE)
	set (target_dir ".")
else(APPLE)
	set (target_dir "bin")
endif(APPLE)

install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION ${target_dir})