
# FIXME: For OS X, need flag for Framework or dylib
IF(DYNAMIC_OPENSCENEGRAPH)
    ADD_DEFINITIONS(-DOSG_LIBRARY)
ELSE()
    ADD_DEFINITIONS(-DOSG_LIBRARY_STATIC)
ENDIF()

SET(LIB_NAME osg)


#
# Enable workaround for OpenGL driver crash with occlusion query
#
OPTION(OSG_FORCE_QUERY_RESULT_AVAILABLE_BEFORE_RETRIEVAL "Set to ON to build OcclussionQueryNode with a workaround for multi-threaded OpenGL driver occlussion query crash. " OFF)
IF(OSG_FORCE_QUERY_RESULT_AVAILABLE_BEFORE_RETRIEVAL)
    ADD_DEFINITIONS(-DFORCE_QUERY_RESULT_AVAILABLE_BEFORE_RETRIEVAL)
ENDIF()


SET(HEADER_PATH ${OpenSceneGraph_SOURCE_DIR}/include/${LIB_NAME})
SET(LIB_PUBLIC_HEADERS
    ${HEADER_PATH}/AlphaFunc
    ${HEADER_PATH}/AnimationPath
    ${HEADER_PATH}/ApplicationUsage
    ${HEADER_PATH}/ArgumentParser
    ${HEADER_PATH}/Array
    ${HEADER_PATH}/ArrayDispatchers
    ${HEADER_PATH}/AudioStream
    ${HEADER_PATH}/AutoTransform
    ${HEADER_PATH}/Billboard
    ${HEADER_PATH}/BlendColor
    ${HEADER_PATH}/BlendEquation
    ${HEADER_PATH}/BlendFunc
    ${HEADER_PATH}/BoundingBox
    ${HEADER_PATH}/BoundingSphere
    ${HEADER_PATH}/BoundsChecking
    ${HEADER_PATH}/buffered_value
    ${HEADER_PATH}/BufferObject
    ${HEADER_PATH}/Camera
    ${HEADER_PATH}/CameraNode
    ${HEADER_PATH}/CameraView
    ${HEADER_PATH}/ClampColor
    ${HEADER_PATH}/ClearNode
    ${HEADER_PATH}/ClipNode
    ${HEADER_PATH}/ClipPlane
    ${HEADER_PATH}/ClusterCullingCallback
    ${HEADER_PATH}/CollectOccludersVisitor
    ${HEADER_PATH}/ColorMask
    ${HEADER_PATH}/ColorMatrix
    ${HEADER_PATH}/ComputeBoundsVisitor
    ${HEADER_PATH}/ConvexPlanarOccluder
    ${HEADER_PATH}/ConvexPlanarPolygon
    ${HEADER_PATH}/CoordinateSystemNode
    ${HEADER_PATH}/CopyOp
    ${HEADER_PATH}/CullFace
    ${HEADER_PATH}/CullingSet
    ${HEADER_PATH}/CullSettings
    ${HEADER_PATH}/CullStack
    ${HEADER_PATH}/DeleteHandler
    ${HEADER_PATH}/Depth
    ${HEADER_PATH}/DisplaySettings
    ${HEADER_PATH}/Drawable
    ${HEADER_PATH}/DrawPixels
    ${HEADER_PATH}/Endian
    ${HEADER_PATH}/Export
    ${HEADER_PATH}/fast_back_stack
    ${HEADER_PATH}/Fog
    ${HEADER_PATH}/FragmentProgram
    ${HEADER_PATH}/FrameBufferObject
    ${HEADER_PATH}/FrameStamp
    ${HEADER_PATH}/FrontFace
    ${HEADER_PATH}/Geode
    ${HEADER_PATH}/Geometry
    ${HEADER_PATH}/GL
    ${HEADER_PATH}/GL2Extensions
    ${HEADER_PATH}/GLExtensions
    ${HEADER_PATH}/GLBeginEndAdapter
    ${HEADER_PATH}/GLObjects
    ${HEADER_PATH}/GLU
    ${HEADER_PATH}/GraphicsContext
    ${HEADER_PATH}/GraphicsThread
    ${HEADER_PATH}/Group
    ${HEADER_PATH}/Hint
    ${HEADER_PATH}/Image
    ${HEADER_PATH}/ImageSequence
    ${HEADER_PATH}/ImageStream
    ${HEADER_PATH}/ImageUtils
    ${HEADER_PATH}/io_utils
    ${HEADER_PATH}/KdTree
    ${HEADER_PATH}/Light
    ${HEADER_PATH}/LightModel
    ${HEADER_PATH}/LightSource
    ${HEADER_PATH}/LineSegment
    ${HEADER_PATH}/LineStipple
    ${HEADER_PATH}/LineWidth
    ${HEADER_PATH}/LOD
    ${HEADER_PATH}/LogicOp
    ${HEADER_PATH}/Material
    ${HEADER_PATH}/Math
    ${HEADER_PATH}/Matrix
    ${HEADER_PATH}/Matrixd
    ${HEADER_PATH}/Matrixf
    ${HEADER_PATH}/MatrixTransform
    ${HEADER_PATH}/MixinVector
    ${HEADER_PATH}/Multisample
    ${HEADER_PATH}/Node
    ${HEADER_PATH}/NodeCallback
    ${HEADER_PATH}/NodeTrackerCallback
    ${HEADER_PATH}/NodeVisitor
    ${HEADER_PATH}/Notify
    ${HEADER_PATH}/Object
    ${HEADER_PATH}/observer_ptr
    ${HEADER_PATH}/OccluderNode
    ${HEADER_PATH}/OcclusionQueryNode
    ${HEADER_PATH}/OperationThread
    ${HEADER_PATH}/PagedLOD
    ${HEADER_PATH}/Plane
    ${HEADER_PATH}/Point
    ${HEADER_PATH}/PointSprite
    ${HEADER_PATH}/PolygonMode
    ${HEADER_PATH}/PolygonOffset
    ${HEADER_PATH}/PolygonStipple
    ${HEADER_PATH}/Polytope
    ${HEADER_PATH}/PositionAttitudeTransform
    ${HEADER_PATH}/PrimitiveSet
    ${HEADER_PATH}/Program
    ${HEADER_PATH}/Projection
    ${HEADER_PATH}/ProxyNode
    ${HEADER_PATH}/Quat
    ${HEADER_PATH}/Referenced
    ${HEADER_PATH}/ref_ptr
    ${HEADER_PATH}/RenderInfo
    ${HEADER_PATH}/Scissor
    ${HEADER_PATH}/Sequence
    ${HEADER_PATH}/ShadeModel
    ${HEADER_PATH}/Shader
    ${HEADER_PATH}/ShadowVolumeOccluder
    ${HEADER_PATH}/Shape
    ${HEADER_PATH}/ShapeDrawable
    ${HEADER_PATH}/State
    ${HEADER_PATH}/StateAttribute
    ${HEADER_PATH}/StateAttributeCallback
    ${HEADER_PATH}/StateSet
    ${HEADER_PATH}/Stats
    ${HEADER_PATH}/Stencil
    ${HEADER_PATH}/StencilTwoSided
    ${HEADER_PATH}/Switch
    ${HEADER_PATH}/TemplatePrimitiveFunctor
    ${HEADER_PATH}/TexEnv
    ${HEADER_PATH}/TexEnvCombine
    ${HEADER_PATH}/TexEnvFilter
    ${HEADER_PATH}/TexGen
    ${HEADER_PATH}/TexGenNode
    ${HEADER_PATH}/TexMat
    ${HEADER_PATH}/Texture
    ${HEADER_PATH}/Texture1D
    ${HEADER_PATH}/Texture2D
    ${HEADER_PATH}/Texture2DArray
    ${HEADER_PATH}/Texture3D
    ${HEADER_PATH}/TextureCubeMap
    ${HEADER_PATH}/TextureRectangle
    ${HEADER_PATH}/Timer
    ${HEADER_PATH}/TransferFunction
    ${HEADER_PATH}/Transform
    ${HEADER_PATH}/TriangleFunctor
    ${HEADER_PATH}/TriangleIndexFunctor
    ${HEADER_PATH}/Uniform
    ${HEADER_PATH}/Vec2
    ${HEADER_PATH}/Vec2b
    ${HEADER_PATH}/Vec2d
    ${HEADER_PATH}/Vec2f
    ${HEADER_PATH}/Vec2s
    ${HEADER_PATH}/Vec3
    ${HEADER_PATH}/Vec3b
    ${HEADER_PATH}/Vec3d
    ${HEADER_PATH}/Vec3f
    ${HEADER_PATH}/Vec3s
    ${HEADER_PATH}/Vec4
    ${HEADER_PATH}/Vec4b
    ${HEADER_PATH}/Vec4d
    ${HEADER_PATH}/Vec4f
    ${HEADER_PATH}/Vec4s
    ${HEADER_PATH}/Vec4ub
    ${HEADER_PATH}/Version
    ${HEADER_PATH}/VertexProgram
    ${HEADER_PATH}/View
    ${HEADER_PATH}/Viewport
    ${OPENSCENEGRAPH_CONFIG_HEADER}
)

ADD_LIBRARY(${LIB_NAME}
    ${OPENSCENEGRAPH_USER_DEFINED_DYNAMIC_OR_STATIC}
    ${LIB_PUBLIC_HEADERS}
    AlphaFunc.cpp
    AnimationPath.cpp
    ApplicationUsage.cpp
    ArgumentParser.cpp
    Array.cpp
    ArrayDispatchers.cpp
    AudioStream.cpp
    AutoTransform.cpp
    Billboard.cpp
    BlendColor.cpp
    BlendEquation.cpp
    BlendFunc.cpp
    BufferObject.cpp
    Camera.cpp
    CameraView.cpp
    ClampColor.cpp
    ClearNode.cpp
    ClipNode.cpp
    ClipPlane.cpp
    ClusterCullingCallback.cpp
    CollectOccludersVisitor.cpp
    ColorMask.cpp
    ColorMatrix.cpp
    ComputeBoundsVisitor.cpp
    ConvexPlanarOccluder.cpp
    ConvexPlanarPolygon.cpp
    CoordinateSystemNode.cpp
    CopyOp.cpp
    CullFace.cpp
    CullingSet.cpp
    CullSettings.cpp
    CullStack.cpp
    DeleteHandler.cpp
    Depth.cpp
    DisplaySettings.cpp
    Drawable.cpp
    DrawPixels.cpp
    dxtctool.cpp
    dxtctool.h
    Fog.cpp
    FragmentProgram.cpp
    FrameBufferObject.cpp
    FrameStamp.cpp
    FrontFace.cpp
    Geode.cpp
    Geometry.cpp
    GL2Extensions.cpp
    GLExtensions.cpp
    GLBeginEndAdapter.cpp
    GLObjects.cpp
    GraphicsContext.cpp
    GraphicsThread.cpp
    Group.cpp
    Hint.cpp
    Image.cpp
    ImageSequence.cpp
    ImageStream.cpp
    ImageUtils.cpp
    KdTree.cpp
    Light.cpp
    LightModel.cpp
    LightSource.cpp
    LineSegment.cpp
    LineStipple.cpp
    LineWidth.cpp
    LOD.cpp
    LogicOp.cpp
    Material.cpp
    Math.cpp
    Matrixd.cpp
    MatrixDecomposition.cpp
    Matrixf.cpp
    # We don't build this one
    #    Matrix_implementation.cpp
    MatrixTransform.cpp
    Multisample.cpp
    NodeCallback.cpp
    Node.cpp
    NodeTrackerCallback.cpp
    NodeVisitor.cpp
    Notify.cpp
    Object.cpp
    OccluderNode.cpp
    OcclusionQueryNode.cpp
    OperationThread.cpp
    PagedLOD.cpp
    Point.cpp
    PointSprite.cpp
    PolygonMode.cpp
    PolygonOffset.cpp
    PolygonStipple.cpp
    PositionAttitudeTransform.cpp
    PrimitiveSet.cpp
    Program.cpp
    Projection.cpp
    ProxyNode.cpp
    Quat.cpp
    Referenced.cpp
    Scissor.cpp
    Sequence.cpp
    ShadeModel.cpp
    Shader.cpp
    ShadowVolumeOccluder.cpp
    Shape.cpp
    ShapeDrawable.cpp
    StateAttribute.cpp
    State.cpp
    StateSet.cpp
    Stats.cpp
    Stencil.cpp
    StencilTwoSided.cpp
    Switch.cpp
    TexEnvCombine.cpp
    TexEnv.cpp
    TexEnvFilter.cpp
    TexGen.cpp
    TexGenNode.cpp
    TexMat.cpp
    Texture1D.cpp
    Texture2DArray.cpp
    Texture2D.cpp
    Texture3D.cpp
    Texture.cpp
    TextureCubeMap.cpp
    TextureRectangle.cpp
    Timer.cpp
    TransferFunction.cpp
    Transform.cpp
    Uniform.cpp
    Version.cpp
    VertexProgram.cpp
    View.cpp
    Viewport.cpp
    ${OPENSCENEGRAPH_VERSIONINFO_RC}
)

LINK_INTERNAL(${LIB_NAME}     
    OpenThreads
)
LINK_EXTERNAL(${LIB_NAME} ${CMAKE_THREAD_LIBS_INIT}    ${MATH_LIBRARY} ${RT_LIBRARY} )
LINK_CORELIB_DEFAULT(${LIB_NAME} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIBRARY} ${RT_LIBRARY} )

INCLUDE(ModuleInstall OPTIONAL)
