FIND_PACKAGE(OpenGL REQUIRED)

if(UNIX)
    set(GLEW_LIBRARY_STATIC libGLEW.a)
    set(GLEW_LIBRARY_STATIC_D libGLEW.a)
elseif(MSVC)
    set(GLEW_LIBRARY_STATIC libglew32.lib)
    set(GLEW_LIBRARY_STATIC_D libglew32.lib)
elseif(MINGW)
    set(GLEW_LIBRARY_STATIC libglew32.a)
    set(GLEW_LIBRARY_STATIC_D libglew32.a)
endif()
set(glew_LIBRARY_STATIC ${ThirdParty_Install_Dir}/lib/${GLEW_LIBRARY_STATIC})
set(glew_LIBRARY_STATIC_D ${ThirdParty_Install_Dir}/lib/${GLEW_LIBRARY_STATIC_D})

ExternalProject_Add(
    glew_BUILD
    DOWNLOAD_COMMAND ""
    SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/glew-2.1.0
    UPDATE_COMMAND ""
    INSTALL_DIR ${ThirdParty_Install_Dir}
    CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_STAGING_PREFIX:PATH=${ThirdParty_Install_Dir} -DBUILD_UTILS:BOOL=OFF -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
    CMAKE_GENERATOR "${CMAKE_GENERATOR}"
    CMAKE_GENERATOR_TOOLSET ${CMAKE_GENERATOR_TOOLSET}
    BUILD_BYPRODUCTS ${glew_LIBRARY_STATIC}
)
add_library(glew_IMP STATIC IMPORTED GLOBAL)
add_dependencies(glew_IMP glew_BUILD)
set_target_properties(glew_IMP PROPERTIES
    IMPORTED_LINK_INTERFACE_LIBRARIES "${OPENGL_LIBRARIES}"
    IMPORTED_LOCATION ${glew_LIBRARY_STATIC}
    IMPORTED_LOCATION_DEBUG ${glew_LIBRARY_STATIC}
    IMPORTED_LOCATION_RELEASE ${glew_LIBRARY_STATIC}
	INTERFACE_COMPILE_DEFINITIONS "GLEW_STATIC"
)


