
# use the local Findbrick.cmake for now ..
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/extra")


# include SDL .. (necessary for win32)
find_package(SDL REQUIRED)

# and Lua ..
find_package(Lua51 REQUIRED)

# and of course Brick.
find_package(brick REQUIRED)

# and set up the include-directories
include_directories (${BRICK_INCLUDE_DIR} ${LUA_INCLUDE_DIR} ${SDL_INCLUDE_DIR})


# build a list of sources
set (SRCS lua-mod.c lua-mod-audio.c lua-mod-clock.c lua-mod-collision.c
          lua-mod-font.c lua-mod-frame.c lua-mod-graphics.c lua-mod-inspect.c
          lua-mod-io.c lua-mod-layer.c lua-mod-list.c lua-mod-map.c
          lua-mod-motion.c lua-mod-render.c lua-mod-sound.c lua-mod-song.c
          lua-mod-sprite.c lua-mod-string.c lua-mod-tile.c)



# If building the module ..
if (LUA_MOD)

  # note: can't build an extension on os x ..
  if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
    message (FATAL_ERROR "Can't be built as an extension on OS X")
  endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

  # add the source files
  add_library (lua-mod SHARED ${SRCS})

  # set some specific options for the module
  set_target_properties (lua-mod PROPERTIES PREFIX "")
  set_target_properties (lua-mod PROPERTIES OUTPUT_NAME "br")

  # and include the stubs library.
  target_link_libraries (lua-mod ${BRICK_LIBRARIES} ${LUA_LIBRARIES} ${SDL_LIBRARY})

  # last, deposit the library into the right place
  set_target_properties (lua-mod PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../src-out)

endif (LUA_MOD)



# If building the executable ..
if (LUA_EXE)

  # add the source files
  add_executable (lua-exe main.c ${SRCS})
  install_targets (/bin lua-exe)

  # set some options for the executable
  set_target_properties (lua-exe PROPERTIES OUTPUT_NAME "brick-lua")

  # and include the lua library.
  target_link_libraries (lua-exe ${SDL_LIBRARY} ${SDLMAIN_LIBRARY} ${LUA_LIBRARIES} ${BRICK_LIBRARIES})

  # Enable darwin-specific build modifications ..
  if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
    FIND_LIBRARY(COCOA_LIBRARY Cocoa)
    target_link_libraries (lua-exe ${COCOA_LIBRARY})
  endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

  # last, deposit the executable into the right place
  set_target_properties (lua-exe PROPERTIES RUNTIME_OUTPUT_DIRECTORY ../src-out)

endif (LUA_EXE)
