Source

pygamekit / CMakeLists.txt

# ---------------------------------------------------------
cmake_minimum_required(VERSION 2.6)

set(TargetName pygamekit)

# if (APPLE)
# 	include_directories(${OGRELITE_SOURCE_DIR}/OgreMain/include/OSX)
# 	SET(EXETYPE MACOSX_BUNDLE)
# 	SET_SOURCE_FILES_PROPERTIES( MainMenu.nib  PROPERTIES MACOSX_PACKAGE_LOCATION Resources )
# 	SET_SOURCE_FILES_PROPERTIES(${CONTENT} PROPERTIES MACOSX_PACKAGE_LOCATION Resources )
# 	SET (NibFile MainMenu.nib)
# endif()
# 
# set(CPP_MAIN_HDR
# 	gkApplication.h
# 	gkCollisionCameraConstraint.h
# 	gkGamePlayer.h
# 	gkGameLevel.h
# 	# gkGameNPC.h
# )
# 
# if(WIN32)
# 
# 	source_group(Main\\Source FILES ${CPP_MAIN_SRC})
# 	source_group(Main\\Header FILES ${CPP_MAIN_HDR})
# 
# 	source_group(Controllers\\Source FILES ${CPP_CONT_SRC})
# 	source_group(Controllers\\Header FILES ${CPP_CONT_HDR})
# 
# 	source_group(Datafiles FILES ${CONTENT})
# endif()


include_directories(
	${OGREKIT_INCLUDE}
)

link_libraries(
	${OGREKIT_LIB}
)


# if (APPLE)
# 
# 	add_executable(
# 		${TargetName} 
# 		MACOSX_BUNDLE
# 		MainMenu.nib
# 		${SRC} 
# 	)
# 
# else ()
# 
# 	add_executable(${TargetName} ${SRC})
# 	
# 	
# 	IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
# 		ADD_CUSTOM_COMMAND(
# 			TARGET ${TargetName} 
# 			POST_BUILD
# 			COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/Maps.blend ${CMAKE_CURRENT_BINARY_DIR}/Maps.blend
# 			COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/Momo.blend ${CMAKE_CURRENT_BINARY_DIR}/Momo.blend
# 			COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/Rat.blend ${CMAKE_CURRENT_BINARY_DIR}/Rat.blend
# 		)
# 	ENDIF ()
# 
# endif()

######################################################################################
# Python extension builder
######################################################################################

set(PYGAMEKIT_SRC
    actuator.pxi
    animation.pxd
    animation.pxi
    blendfile.pxi
    camera.pxd
    camera.pxi
    collision.pxd
    collision.pxi
    controller.pxi
    engine.pxi
    entity.pxd
    entity.pxi
    sensor.pxi
    gamekit.pyx
    gameobject.pxd
    gameobject.pxi
    gkmath.pxd
    input.pxd
    input.pxi
    mathutils.pxd
    mathutils.pyx
    prerequisites.pxd
    pywrap.pxd
    pywrap.pxi
    scene.pxi
    sound.pxd
    sound.pxi
    variable.pxd
    standalone.py
)

#include(FindPythonInterp)
#include(FindPythonLibs)

# set(Py_DEBUG CACHE BOOL 0)

if (OGREKIT_BUILD_ANDROID)
    set(PYTHON_INCLUDE_PATH ${PYTHON_ANDROID_LIB}/include/python2.6)
    set(PYTHON_LIBRARIES -L${PYTHON_ANDROID_LIB}/lib -lpython2.6)
else()
    include(FindPythonLibs)
    if(PYTHON_LIBRARIES)
        if(CMAKE_BUILD_TYPE MATCHES "Deb")
#             if(PYTHON_FORCE_DEBUG_LIBRARIES)
#                 set(PYTHON_DEBUG_LIBRARIES ${PYTHON_FORCE_DEBUG_LIBRARIES})
#             endif()
#             if(PYTHON_DEBUG_LIBRARIES)
#                 message("Python debug libraries found at ${PYTHON_DEBUG_LIBRARIES}")
#                 #todo: add "#cmakedefine Py_DEBUG 1" to OgreKitSettings.in
#                 set(Py_DEBUG 1)
#                 set(PYTHON_LIBRARIES ${PYTHON_DEBUG_LIBRARIES})
#                 if(PYOGREKIT_AS_MODULES)
#                     set(PY_SUFFIX _d)
#                 endif()
#             endif()
        endif()
    else()
        set(PYTHON_INCLUDE_PATH $ENV{HOME}/.wine/drive_c/Python27/include)
        set(PYTHON_LIBRARIES -L$ENV{HOME}/.wine/drive_c/Python27/libs -lpython27)
    endif()
endif()

find_program(CYTHON_EXECUTABLE cython)
if (CYTHON_EXECUTABLE MATCHES "NOTFOUND")
    set (CYTHON_EXECUTABLE cython)
endif()

# Cython integratin into gdb
if (CMAKE_BUILD_TYPE MATCHES "Deb")
    set(CYTHON_DEBUG --gdb --line-directives)
endif()

set(CYTHON_OPTIONS --cplus --fast-fail -X embedsignature=True)

add_custom_command(
  DEPENDS ${PYGAMEKIT_SRC}
  OUTPUT gamekit.cpp mathutils.cpp standalone.py.h
  COMMAND ${CYTHON_EXECUTABLE} ${CYTHON_DEBUG} ${CYTHON_OPTIONS} -o gamekit.cpp
         "${CMAKE_CURRENT_SOURCE_DIR}/gamekit.pyx"
  COMMAND ${CYTHON_EXECUTABLE} ${CYTHON_DEBUG} ${CYTHON_OPTIONS} -o mathutils.cpp
         "${CMAKE_CURRENT_SOURCE_DIR}/mathutils.pyx"
  COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/standalone.py" .
  COMMAND xxd -i standalone.py standalone.py.h
)
list(APPEND ADDITIONAL_MAKE_CLEAN_FILES gamekit.cpp mathutils.cpp standalone.py.h)

set(PYGAMEKIT_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})

#add_custom_target(gamekit.cpp DEPENDS gamekit.pyx)
#add_dependencies(gamekit.cpp gamekit.pyx)

# Compile the extension
if (PYGAMEKIT_AS_MODULES OR OGREKIT_BUILD_ANDROID)
    add_library(cython_gamekit MODULE gamekit.cpp ${PYGAMEKIT_SRC})
    # Build mathutils as a separate module instead
    add_library(cython_mathutils MODULE mathutils.cpp ${PYGAMEKIT_SRC})
    set_target_properties(cython_mathutils PROPERTIES
    PREFIX ""
    OUTPUT_NAME "mathutils${PY_SUFFIX}"
    LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    COMPILE_FLAGS "-fno-permissive" )
    target_link_libraries(cython_mathutils ${OGREKIT_LIB} ${PYTHON_LIBRARIES})
else()
    add_executable(cython_gamekit gamekit.cpp mathutils.cpp ${PYGAMEKIT_SRC} standalone.cpp)
endif()

set_target_properties(cython_gamekit PROPERTIES
  PREFIX ""
  OUTPUT_NAME "gamekit${PY_SUFFIX}"
  LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  COMPILE_FLAGS "-fno-permissive" )
target_link_libraries(cython_gamekit ${OGREKIT_LIB} ${PYTHON_LIBRARIES})
if (OGREKIT_BUILD_ANDROID)
  target_link_libraries(cython_gamekit log)
endif()
include_directories(
    ${PYTHON_INCLUDE_PATH}
    ${OGREKIT_INCLUDE}
    ${CMAKE_CURRENT_BINARY_DIR}
    .
)