cmake: allow calling find_package(GLEW) multiple times

This commit is contained in:
Tamas Kenez 2015-11-10 11:53:16 +01:00 committed by Nigel Stewart
parent c8c0c1e480
commit 66c5229ec2
2 changed files with 18 additions and 3 deletions

View File

@ -40,7 +40,21 @@ endif()
foreach(_glew_target glew glewmx) foreach(_glew_target glew glewmx)
set(_glew_src_target "GLEW::${_glew_target}${_glew_target_postfix}") set(_glew_src_target "GLEW::${_glew_target}${_glew_target_postfix}")
string(TOUPPER "GLEW::${_glew_target}" _glew_dest_target) string(TOUPPER "GLEW::${_glew_target}" _glew_dest_target)
add_library(${_glew_dest_target} ${_glew_target_type} IMPORTED) if(TARGET ${_glew_dest_target})
# message(STATUS "add_library(${_glew_dest_target} ${_glew_target_type} IMPORTED)") get_target_property(_glew_previous_src_target ${_glew_dest_target}
copy_imported_target_properties(${_glew_src_target} ${_glew_dest_target}) _GLEW_SRC_TARGET)
if(NOT _glew_previous_src_target STREQUAL _glew_src_target)
message(FATAL_ERROR "find_package(GLEW) was called the second time with "
"different GLEW_USE_STATIC_LIBS setting. Previously, "
"`glew-config.cmake` created ${_glew_dest_target} as a copy of "
"${_glew_previous_src_target}. Now it attempted to copy it from "
"${_glew_src_target}. ")
endif()
else()
add_library(${_glew_dest_target} ${_glew_target_type} IMPORTED)
# message(STATUS "add_library(${_glew_dest_target} ${_glew_target_type} IMPORTED)")
copy_imported_target_properties(${_glew_src_target} ${_glew_dest_target})
set_target_properties(${_glew_dest_target} PROPERTIES
_GLEW_SRC_TARGET ${_glew_src_target})
endif()
endforeach() endforeach()

View File

@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 2.8.12)
project(glew-cmake-test) project(glew-cmake-test)
find_package(GLEW REQUIRED CONFIG) find_package(GLEW REQUIRED CONFIG)
find_package(GLEW REQUIRED CONFIG) # call twice to test multiple call
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
add_executable(cmake-test main.c) add_executable(cmake-test main.c)