cmake_minimum_required(VERSION 2.6)
cmake_policy(VERSION 2.6.4)

project(freeorion)

message("-- Configuring freeorion")

if (WIN32)
   find_package(OpenGL)
   if (OPENGL_FOUND)
       if (NOT OPENGL_GLU_FOUND)
           message(FATAL_ERROR "OpenGL GLU library not found.")
       endif ()
       include_directories(${OPENGL_INCLUDE_DIR})
   else ()
       message(FATAL_ERROR "OpenGL library not found.")
   endif ()
endif ()

find_package(OpenAL)
if (OPENAL_FOUND)
    include_directories(${OPENAL_INCLUDE_DIR})
else ()
    message(FATAL_ERROR "OpenAL library not found.")
endif ()

find_package(ALUT)
if (ALUT_FOUND)
    include_directories(${ALUT_INCLUDE_DIR})
else ()
    message(FATAL_ERROR "ALUT OpenAL utility library not found.")
endif ()

find_package(OGRE)
if (OGRE_FOUND)
    include_directories(${OGRE_INCLUDE_DIRS})
else ()
    message(FATAL_ERROR "Ogre library not found.")
endif ()

find_package(Ogg)
if (OGG_FOUND)
    include_directories(${OGG_INCLUDE_DIR})
else ()
    message(FATAL_ERROR "Ogg library not found.")
endif ()

find_package(Vorbis)
if (VORBIS_FOUND)
    include_directories(${VORBIS_INCLUDE_DIR})
else ()
    message(FATAL_ERROR "Vorbis library not found.")
endif ()

find_package(Bullet)
if (BULLET_FOUND)
    include_directories(${BULLET_INCLUDE_DIR})
    link_directories(${BULLET_LIB_DIR})
else ()
    message(FATAL_ERROR "Bullet library not found.")
endif ()

include_directories(${CMAKE_SOURCE_DIR}/PagedGeometry/include)

add_definitions(-DFREEORION_BUILD_HUMAN -DGL_GLEXT_PROTOTYPES)

if (CMAKE_COMPILER_IS_GNUCXX)
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
endif ()

set(freeorion_SOURCES
    ../../client/ClientApp.cpp
    ../../client/ClientFSMEvents.cpp
    ../../client/human/HumanClientFSM.cpp
    ../../client/human/HumanClientApp.cpp
    ../../client/human/chmain.cpp
    ../../combat/CombatSystem.cpp
    ../../network/ClientNetworking.cpp
    ../../UI/About.cpp
    ../../UI/BuildDesignatorWnd.cpp
    ../../UI/ChatWnd.cpp
    ../../UI/PlayerListWnd.cpp
    ../../UI/ClientUI.cpp
    ../../UI/CollisionMeshConverter.cpp
    ../../UI/CombatCamera.cpp
    ../../UI/CombatWnd.cpp
    ../../UI/CombatSetupWnd.cpp
    ../../UI/CUIControls.cpp
    ../../UI/CUIDrawUtil.cpp
    ../../UI/CUIStyle.cpp
    ../../UI/CUIWnd.cpp
    ../../UI/EncyclopediaDetailPanel.cpp
    ../../UI/EntityRenderer.cpp
    ../../UI/FieldIcon.cpp
    ../../UI/FleetButton.cpp
    ../../UI/FleetWnd.cpp
    ../../UI/GalaxySetupWnd.cpp
    ../../UI/InGameMenu.cpp
    ../../UI/InfoPanels.cpp
    ../../UI/IntroScreen.cpp
    ../../UI/LinkText.cpp
    ../../UI/MapWnd.cpp
    ../../UI/ModeratorActionsWnd.cpp
    ../../UI/GLClientAndServerBuffer.cpp
    ../../UI/MultiplayerLobbyWnd.cpp
    ../../UI/ObjectListWnd.cpp
    ../../UI/OptionsWnd.cpp
    ../../UI/DesignWnd.cpp
    ../../UI/ProductionWnd.cpp
    ../../UI/QueueListBox.cpp
    ../../UI/ResearchWnd.cpp
    ../../UI/ServerConnectWnd.cpp
    ../../UI/SidePanel.cpp
    ../../UI/SitRepPanel.cpp
    ../../UI/Sound.cpp
    ../../UI/SystemIcon.cpp
    ../../UI/TechTreeWnd.cpp
    ../../UI/TechTreeLayout.cpp
    ../../UI/TurnProgressWnd.cpp
    ../../UI/ShaderProgram.cpp
)

set(freeorion_LINK_LIBS
    freeorioncommon
    freeorionparse
    pagedgeometry
    GiGi
    GiGiOgre
    GiGiOgrePlugin_OIS
    ${OPENAL_LIBRARY}
    ${ALUT_LIBRARY}
    ${OGRE_LIBRARIES}
    ${OGG_LIBRARY}
    ${VORBIS_LIBRARIES}
    ${BULLET_LIBRARIES}
    ${ZLIB_LIBRARY}
    ${CMAKE_THREAD_LIBS_INIT}
)

if (WIN32)
    link_directories(${BOOST_LIBRARYDIR})
    list(APPEND
        freeorion_LINK_LIBS
        ${OPENGL_gl_LIBRARY}
        ${OPENGL_glu_LIBRARY}
        jpeg.lib libpng.lib glew32.lib
    )
    list(APPEND freeorion_SOURCES ${CMAKE_BINARY_DIR}/win32_resources.rc)
else ()
    list(APPEND freeorion_LINK_LIBS ${Boost_LIBRARIES})
endif ()

add_executable(freeorion
    ${freeorion_SOURCES}
)

target_link_libraries(freeorion
    ${freeorion_LINK_LIBS}
)

install(
    TARGETS freeorion
    RUNTIME DESTINATION .
    COMPONENT COMPONENT_FREEORION
)

