FIND_PACKAGE(OpenGL REQUIRED)
if(MSVC)
    libname(glew libGLEW)
else()
    libname(glew GLEW)
endif()
ExternalProject_Add(
    glew_BUILD
    DOWNLOAD_COMMAND ""
    SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/glew-1.13.0
    UPDATE_COMMAND ""
    CMAKE_ARGS -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_SHARED_LIBS:BOOL=OFF -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_STAGING_PREFIX:PATH=${ThirdParty_Install_Dir}
    CMAKE_GENERATOR "${CMAKE_GENERATOR}"
    CMAKE_GENERATOR_TOOLSET ${CMAKE_GENERATOR_TOOLSET}
    INSTALL_DIR ${ThirdParty_Install_Dir}
    BUILD_BYPRODUCTS ${glew_LIBRARY_STATIC}
)
ADD_LIBRARY(glew_IMP STATIC IMPORTED GLOBAL) # this is shared but cmake is wonky on windows and tries to link to glew.lib instead of the set glewdll.lib

add_dependencies(glew_IMP glew_BUILD)
SET_TARGET_PROPERTIES(glew_IMP PROPERTIES
    IMPORTED_LOCATION ${glew_LIBRARY_STATIC}
    IMPORTED_LOCATION_DEBUG ${glew_LIBRARY_STATIC_D}
    IMPORTED_LOCATION_RELEASE ${glew_LIBRARY_STATIC}
    IMPORTED_LINK_INTERFACE_LIBRARIES "${OPENGL_LIBRARIES}"
    INTERFACE_COMPILE_DEFINITIONS GLEW_STATIC

)
