diff options
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/CMakeCheckCompilerFlagCommonPatterns.cmake | 1 | ||||
-rw-r--r-- | Modules/ExternalProject.cmake | 66 | ||||
-rw-r--r-- | Modules/FindBLAS.cmake | 26 | ||||
-rw-r--r-- | Modules/FindEnvModules.cmake | 333 | ||||
-rw-r--r-- | Modules/FindGLEW.cmake | 302 |
5 files changed, 657 insertions, 71 deletions
diff --git a/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake b/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake index e60ffe0..5b9ed34 100644 --- a/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake +++ b/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake @@ -30,5 +30,6 @@ macro (CHECK_COMPILER_FLAG_COMMON_PATTERNS _VAR) FAIL_REGEX "Incorrect command line option:" # Borland FAIL_REGEX "Warning: illegal option" # SunStudio 12 FAIL_REGEX "[Ww]arning: Invalid suboption" # Fujitsu + FAIL_REGEX "An invalid option .* appears on the command line" # Cray ) endmacro () diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake index 22e0523..4344bdb 100644 --- a/Modules/ExternalProject.cmake +++ b/Modules/ExternalProject.cmake @@ -251,6 +251,9 @@ External Project Definition The lack of such deterministic behavior makes the main project lose traceability and repeatability. + If ``GIT_SHALLOW`` is enabled then ``GIT_TAG`` works only with + branch names and tags. A commit hash is not allowed. + ``GIT_REMOTE_NAME <name>`` The optional name of the remote. If this option is not specified, it defaults to ``origin``. @@ -1053,11 +1056,6 @@ define_property(DIRECTORY PROPERTY "EP_UPDATE_DISCONNECTED" INHERITED ) function(_ep_write_gitclone_script script_filename source_dir git_EXECUTABLE git_repository git_tag git_remote_name git_submodules git_shallow git_progress git_config src_name work_dir gitclone_infofile gitclone_stampfile tls_verify) - if(NOT GIT_VERSION_STRING VERSION_LESS 1.7.10) - set(git_clone_shallow_options "--depth 1 --no-single-branch") - else() - set(git_clone_shallow_options "--depth 1") - endif() if(NOT GIT_VERSION_STRING VERSION_LESS 1.8.5) # Use `git checkout <tree-ish> --` to avoid ambiguity with a local path. set(git_checkout_explicit-- "--") @@ -1067,12 +1065,30 @@ function(_ep_write_gitclone_script script_filename source_dir git_EXECUTABLE git # because that will not search for remote branch names, a common use case. set(git_checkout_explicit-- "") endif() - file(WRITE ${script_filename} -"if(\"${git_tag}\" STREQUAL \"\") - message(FATAL_ERROR \"Tag for git checkout should not be empty.\") -endif() + if("${git_tag}" STREQUAL "") + message(FATAL_ERROR "Tag for git checkout should not be empty.") + endif() -set(run 0) + set(git_clone_options) + if(git_shallow) + if(NOT GIT_VERSION_STRING VERSION_LESS 1.7.10) + list(APPEND git_clone_options "--depth 1 --no-single-branch") + else() + list(APPEND git_clone_options "--depth 1") + endif() + endif() + if(git_progress) + list(APPEND git_clone_options --progress) + endif() + foreach(config IN LISTS git_config) + list(APPEND git_clone_options --config ${config}) + endforeach() + if(NOT ${git_remote_name} STREQUAL "origin") + list(APPEND git_clone_options --origin \"${git_remote_name}\") + endif() + string (REPLACE ";" " " git_clone_options "${git_clone_options}") + file(WRITE ${script_filename} +"set(run 0) if(\"${gitclone_infofile}\" IS_NEWER_THAN \"${gitclone_stampfile}\") set(run 1) @@ -1100,29 +1116,12 @@ if(NOT \"x${tls_verify}\" STREQUAL \"x\" AND NOT tls_verify) -c http.sslVerify=false) endif() -set(git_clone_options) - -set(git_shallow \"${git_shallow}\") -if(git_shallow) - list(APPEND git_clone_options ${git_clone_shallow_options}) -endif() - -set(git_progress \"${git_progress}\") -if(git_progress) - list(APPEND git_clone_options --progress) -endif() - -set(git_config \"${git_config}\") -foreach(config IN LISTS git_config) - list(APPEND git_clone_options --config \${config}) -endforeach() - # try the clone 3 times in case there is an odd git clone issue set(error_code 1) set(number_of_tries 0) while(error_code AND number_of_tries LESS 3) execute_process( - COMMAND \"${git_EXECUTABLE}\" \${git_options} clone \${git_clone_options} --origin \"${git_remote_name}\" \"${git_repository}\" \"${src_name}\" + COMMAND \"${git_EXECUTABLE}\" \${git_options} clone ${git_clone_options} \"${git_repository}\" \"${src_name}\" WORKING_DIRECTORY \"${work_dir}\" RESULT_VARIABLE error_code ) @@ -1146,15 +1145,6 @@ if(error_code) endif() execute_process( - COMMAND \"${git_EXECUTABLE}\" \${git_options} submodule init ${git_submodules} - WORKING_DIRECTORY \"${work_dir}/${src_name}\" - RESULT_VARIABLE error_code - ) -if(error_code) - message(FATAL_ERROR \"Failed to init submodules in: '${work_dir}/${src_name}'\") -endif() - -execute_process( COMMAND \"${git_EXECUTABLE}\" \${git_options} submodule update --recursive --init ${git_submodules} WORKING_DIRECTORY \"${work_dir}/${src_name}\" RESULT_VARIABLE error_code @@ -2460,7 +2450,7 @@ function(_ep_add_download_command name) # set(repository ${git_repository}) set(module) - set(tag) + set(tag ${git_remote_name}) configure_file( "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in" "${stamp_dir}/${name}-gitinfo.txt" diff --git a/Modules/FindBLAS.cmake b/Modules/FindBLAS.cmake index 0aa4f50..bfa449f 100644 --- a/Modules/FindBLAS.cmake +++ b/Modules/FindBLAS.cmake @@ -83,6 +83,13 @@ This module defines the following variables: set(BLA_VENDOR Intel10_64lp) find_package(BLAS) + +Hints +^^^^^ + +Set ``MKLROOT`` environment variable to a directory that contains an MKL +installation. + #]=======================================================================] include(${CMAKE_CURRENT_LIST_DIR}/CheckFunctionExists.cmake) @@ -394,6 +401,24 @@ if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All") endif () endif () + if (DEFINED ENV{MKLROOT}) + set(_BLAS_MKLROOT_LIB_DIR "$ENV{MKLROOT}") + endif () + if (_BLAS_MKLROOT_LIB_DIR) + if( SIZEOF_INTEGER EQUAL 8 ) + set( _BLAS_MKL_PATH_PREFIX "intel64" ) + else() + set( _BLAS_MKL_PATH_PREFIX "ia32" ) + endif() + if (WIN32) + string(APPEND _BLAS_MKLROOT_LIB_DIR "/lib/${_BLAS_MKL_PATH_PREFIX}_win") + elseif (APPLE) + string(APPEND _BLAS_MKLROOT_LIB_DIR "/lib/${_BLAS_MKL_PATH_PREFIX}_mac") + else () + string(APPEND _BLAS_MKLROOT_LIB_DIR "/lib/${_BLAS_MKL_PATH_PREFIX}_lin") + endif () + endif () + foreach (IT ${BLAS_SEARCH_LIBS}) string(REPLACE " " ";" SEARCH_LIBS ${IT}) if (NOT ${_LIBRARIES}) @@ -404,6 +429,7 @@ if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All") "" "${SEARCH_LIBS}" "${CMAKE_THREAD_LIBS_INIT};${BLAS_mkl_LM};${BLAS_mkl_LDL}" + "${_BLAS_MKLROOT_LIB_DIR}" ) endif () endforeach () diff --git a/Modules/FindEnvModules.cmake b/Modules/FindEnvModules.cmake new file mode 100644 index 0000000..5d3452d --- /dev/null +++ b/Modules/FindEnvModules.cmake @@ -0,0 +1,333 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindEnvModules +-------------- + +Locate an environment module implementation and make commands available to +CMake scripts to use them. This is compatible with both Lua-based Lmod +and TCL-based EnvironmentModules. + +This module is intended for the use case of setting up the compiler and library +environment within a :ref:`CTest Script <CTest Script>` (``ctest -S``). It can +also be used in a :ref:`CMake Script <Script Processing Mode>` (``cmake -P``). + +.. note:: + + The loaded environment will not survive past the end of the calling process. + Do not use this module in project code (``CMakeLists.txt`` files) to load + a compiler environment; it will not be available during the build. Instead + load the environment manually before running CMake or using the generated + build system. + +Example Usage +^^^^^^^^^^^^^ + +.. code-block:: cmake + + set(CTEST_BUILD_NAME "CrayLinux-CrayPE-Cray-dynamic") + set(CTEST_BUILD_CONFIGURATION Release) + set(CTEST_BUILD_FLAGS "-k -j8") + set(CTEST_CMAKE_GENERATOR "Unix Makefiles") + + ... + + find_package(EnvModules REQUIRED) + + env_module(purge) + env_module(load modules) + env_module(load craype) + env_module(load PrgEnv-cray) + env_module(load craype-knl) + env_module(load cray-mpich) + env_module(load cray-libsci) + + set(ENV{CRAYPE_LINK_TYPE} dynamic) + + ... + +Result Variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: + +``EnvModules_FOUND`` + Found the a compatible environment modules framework + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variable will be set: + +``EnvModules_COMMAND`` + The low level module command to use. Currently supported are + implementations are the Lua based Lmod and TCL based EnvironmentModules. + +Environment Variables +^^^^^^^^^^^^^^^^^^^^^ + +``ENV{MODULESHOME}`` + Usually set by the module environment implementation, used as a hint to + locate the module command to execute. + +Provided Functions +^^^^^^^^^^^^^^^^^^ + +This defines the following cmake functions for interacting with environment +modules: + +.. command:: env_module + + Execute an aribitrary module command: + + .. code-block:: cmake + + env_module(cmd arg1 ... argN) + env_module( + COMMAND cmd arg1 ... argN + [OUTPUT_VARIABLE <out-var>] + [RESULT_VARIABLE <ret-var>] + ) + + The options are: + + ``cmd arg1 ... argN`` + The module sub-command and arguments to execute as if they were + passed directly to the module command in your shell environment. + + ``OUTPUT_VARIABLE <out-var>`` + The standard output from executing the module command. + + ``RESULT_VARIABLE <ret-var>`` + The return code from executing the module command. + +.. command:: env_module_swap + + Swap one module for another: + + .. code-block:: cmake + + env_module_swap(out_mod in_mod + [OUTPUT_VARIABLE <out-var>] + [RESULT_VARIABLE <ret-var>] + ) + + This is functionally equivalent to the ``module swap out_mod in_mod`` shell + command. The options are: + + ``OUTPUT_VARIABLE <out-var>`` + The standard output from executing the module command. + + ``RESULT_VARIABLE <ret-var>`` + The return code from executing the module command. + +.. command:: env_module_list + + Retrieve the list of currently loaded modules: + + .. code-block:: cmake + + env_module_list(<out-var>) + + This is functionally equivalent to the ``module list`` shell command. + The result is stored in ``<out-var>`` as a properly formatted CMake + :ref:`semicolon-separated list <CMake Language Lists>` variable. + +.. command:: env_module_avail + + Retrieve the list of available modules: + + .. code-block:: cmake + + env_module_avail([<mod-prefix>] <out-var>) + + This is functionally equivalent to the ``module avail <mod-prefix>`` shell + command. The result is stored in ``<out-var>`` as a properly formatted + CMake :ref:`semicolon-separated list <CMake Language Lists>` variable. + +#]=======================================================================] + +function(env_module) + if(NOT EnvModules_COMMAND) + message(FATAL_ERROR "Failed to process module command. EnvModules_COMMAND not found") + return() + endif() + + set(options) + set(oneValueArgs OUTPUT_VARIABLE RESULT_VARIABLE) + set(multiValueArgs COMMAND) + cmake_parse_arguments(MOD_ARGS + "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGV} + ) + if(NOT MOD_ARGS_COMMAND) + # If no explicit command argument was given, then treat the calling syntax + # as: module(cmd args...) + set(exec_cmd ${ARGV}) + else() + set(exec_cmd ${MOD_ARGS_COMMAND}) + endif() + + if(MOD_ARGS_OUTPUT_VARIABLE) + set(err_var_args ERROR_VARIABLE err_var) + endif() + + execute_process( + COMMAND mktemp -t module.cmake.XXXXXXXXXXXX + OUTPUT_VARIABLE tempfile_name + ) + string(STRIP "${tempfile_name}" tempfile_name) + + # If the $MODULESHOME/init/cmake file exists then assume that the CMake + # "shell" functionality exits + if(EXISTS "$ENV{MODULESHOME}/init/cmake") + execute_process( + COMMAND ${EnvModules_COMMAND} cmake ${exec_cmd} + OUTPUT_FILE ${tempfile_name} + ${err_var_args} + RESULT_VARIABLE ret_var + ) + + else() # fallback to the sh shell and manually convert to CMake + execute_process( + COMMAND ${EnvModules_COMMAND} sh ${exec_cmd} + OUTPUT_VARIABLE out_var + ${err_var_args} + RESULT_VARIABLE ret_var + ) + endif() + + # If we executed successfully then process and cleanup the temp file + if(ret_var EQUAL 0) + # No CMake shell so we need to process the sh output into CMake code + if(NOT EXISTS "$ENV{MODULESHOME}/init/cmake") + file(WRITE ${tempfile_name} "") + string(REPLACE "\n" ";" out_var "${out_var}") + foreach(sh_cmd IN LISTS out_var) + if(sh_cmd MATCHES "^ *unset *([^ ]*)") + set(cmake_cmd "unset(ENV{${CMAKE_MATCH_1}})") + elseif(sh_cmd MATCHES "^ *export *([^ ]*)") + set(cmake_cmd "set(ENV{${CMAKE_MATCH_1}} \"\${${CMAKE_MATCH_1}}\")") + elseif(sh_cmd MATCHES " *([^ =]*) *= *(.*)") + set(var_name "${CMAKE_MATCH_1}") + set(var_value "${CMAKE_MATCH_2}") + if(var_value MATCHES "^\"(.*[^\\])\"") + # If it's in quotes, take the value as is + set(var_value "${CMAKE_MATCH_1}") + else() + # Otherwise, strip trailing spaces + string(REGEX REPLACE "([^\\])? +$" "\\1" var_value "${var_value}") + endif() + string(REPLACE "\\ " " " var_value "${var_value}") + set(cmake_cmd "set(${var_name} \"${var_value}\")") + else() + continue() + endif() + file(APPEND ${tempfile_name} "${cmake_cmd}\n") + endforeach() + endif() + + # Process the change in environment variables + include(${tempfile_name}) + file(REMOVE ${tempfile_name}) + endif() + + # Push the output back out to the calling scope + if(MOD_ARGS_OUTPUT_VARIABLE) + set(${MOD_ARGS_OUTPUT_VARIABLE} "${err_var}" PARENT_SCOPE) + endif() + if(MOD_ARGS_RESULT_VARIABLE) + set(${MOD_ARGS_RESULT_VARIABLE} ${ret_var} PARENT_SCOPE) + endif() +endfunction(env_module) + +#------------------------------------------------------------------------------ +function(env_module_swap out_mod in_mod) + set(options) + set(oneValueArgs OUTPUT_VARIABLE RESULT_VARIABLE) + set(multiValueArgs) + + cmake_parse_arguments(MOD_ARGS + "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGV} + ) + + env_module(COMMAND -t swap ${out_mod} ${in_mod} + OUTPUT_VARIABLE tmp_out + RETURN_VARIABLE tmp_ret + ) + + if(MOD_ARGS_OUTPUT_VARIABLE) + set(${MOD_ARGS_OUTPUT_VARIABLE} "${err_var}" PARENT_SCOPE) + endif() + if(MOD_ARGS_RESULT_VARIABLE) + set(${MOD_ARGS_RESULT_VARIABLE} ${tmp_ret} PARENT_SCOPE) + endif() +endfunction() + +#------------------------------------------------------------------------------ +function(env_module_list out_var) + cmake_policy(SET CMP0007 NEW) + env_module(COMMAND -t list OUTPUT_VARIABLE tmp_out) + + # Convert output into a CMake list + string(REPLACE "\n" ";" ${out_var} "${tmp_out}") + + # Remove title headers and empty entries + list(REMOVE_ITEM ${out_var} "No modules loaded") + if(${out_var}) + list(FILTER ${out_var} EXCLUDE REGEX "^(.*:)?$") + endif() + list(FILTER ${out_var} EXCLUDE REGEX "^(.*:)?$") + + set(${out_var} ${${out_var}} PARENT_SCOPE) +endfunction() + +#------------------------------------------------------------------------------ +function(env_module_avail) + cmake_policy(SET CMP0007 NEW) + + if(ARGC EQUAL 1) + set(mod_prefix) + set(out_var ${ARGV0}) + elseif(ARGC EQUAL 2) + set(mod_prefix ${ARGV0}) + set(out_var ${ARGV1}) + else() + message(FATAL_ERROR "Usage: env_module_avail([mod_prefix] out_var)") + endif() + env_module(COMMAND -t avail ${mod_prefix} OUTPUT_VARIABLE tmp_out) + + # Convert output into a CMake list + string(REPLACE "\n" ";" tmp_out "${tmp_out}") + + set(${out_var}) + foreach(MOD IN LISTS tmp_out) + # Remove directory entries and empty values + if(MOD MATCHES "^(.*:)?$") + continue() + endif() + + # Convert default modules + if(MOD MATCHES "^(.*)/$" ) # "foo/" + list(APPEND ${out_var} ${CMAKE_MATCH_1}) + elseif(MOD MATCHES "^((.*)/.*)\\(default\\)$") # "foo/1.2.3(default)" + list(APPEND ${out_var} ${CMAKE_MATCH_2}) + list(APPEND ${out_var} ${CMAKE_MATCH_1}) + else() + list(APPEND ${out_var} ${MOD}) + endif() + endforeach() + + set(${out_var} ${${out_var}} PARENT_SCOPE) +endfunction() + +#------------------------------------------------------------------------------ +# Make sure we know where the underlying module command is +find_program(EnvModules_COMMAND + NAMES lmod modulecmd + HINTS ENV MODULESHOME + PATH_SUFFIXES libexec +) + +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +find_package_handle_standard_args(EnvModules DEFAULT_MSG EnvModules_COMMAND) diff --git a/Modules/FindGLEW.cmake b/Modules/FindGLEW.cmake index ad8a810..34ee873 100644 --- a/Modules/FindGLEW.cmake +++ b/Modules/FindGLEW.cmake @@ -7,64 +7,300 @@ FindGLEW Find the OpenGL Extension Wrangler Library (GLEW) -IMPORTED Targets +Input Variables +^^^^^^^^^^^^^^^ + +The following variables may be set to influence this module’s behavior: + +``GLEW_USE_STATIC_LIBS`` + to find and create :prop_tgt:`IMPORTED` target for static linkage. + +``GLEW_VERBOSE`` + to output a detailed log of this module. + +Imported Targets ^^^^^^^^^^^^^^^^ -This module defines the :prop_tgt:`IMPORTED` target ``GLEW::GLEW``, -if GLEW has been found. +This module defines the following :ref:`Imported Targets <Imported Targets>`: + + +``GLEW::glew`` + The GLEW shared library. +``GLEW::glew_s`` + The GLEW static library, if ``GLEW_USE_STATIC_LIBS`` is set to ``TRUE``. +``GLEW::GLEW`` + Duplicates either ``GLEW::glew`` or ``GLEW::glew_s`` based on availability. Result Variables ^^^^^^^^^^^^^^^^ This module defines the following variables: -:: +``GLEW_INCLUDE_DIRS`` + include directories for GLEW +``GLEW_LIBRARIES`` + libraries to link against GLEW +``GLEW_SHARED_LIBRARIES`` + libraries to link against shared GLEW +``GLEW_STATIC_LIBRARIES`` + libraries to link against static GLEW +``GLEW_FOUND`` + true if GLEW has been found and can be used +``GLEW_VERSION`` + GLEW version +``GLEW_VERSION_MAJOR`` + GLEW major version +``GLEW_VERSION_MINOR`` + GLEW minor version +``GLEW_VERSION_MICRO`` + GLEW micro version - GLEW_INCLUDE_DIRS - include directories for GLEW - GLEW_LIBRARIES - libraries to link against GLEW - GLEW_FOUND - true if GLEW has been found and can be used #]=======================================================================] +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) + +find_package(GLEW CONFIG QUIET) + +if(GLEW_FOUND) + find_package_handle_standard_args(GLEW DEFAULT_MSG GLEW_CONFIG) + return() +endif() + +if(GLEW_VERBOSE) + message(STATUS "FindGLEW: did not find GLEW CMake config file. Searching for libraries.") +endif() + + +function(__glew_set_find_library_suffix shared_or_static) + if(UNIX AND "${shared_or_static}" MATCHES "SHARED") + set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" PARENT_SCOPE) + elseif(UNIX AND "${shared_or_static}" MATCHES "STATIC") + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" PARENT_SCOPE) + elseif(APPLE AND "${shared_or_static}" MATCHES "SHARED") + set(CMAKE_FIND_LIBRARY_SUFFIXES ".dylib;.so" PARENT_SCOPE) + elseif(APPLE AND "${shared_or_static}" MATCHES "STATIC") + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" PARENT_SCOPE) + elseif(WIN32 AND "${shared_or_static}" MATCHES "SHARED") + set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" PARENT_SCOPE) + elseif(WIN32 AND "${shared_or_static}" MATCHES "STATIC") + set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.dll.a" PARENT_SCOPE) + endif() + + if(GLEW_VERBOSE) + message(STATUS "FindGLEW: CMAKE_FIND_LIBRARY_SUFFIXES for ${shared_or_static}: ${CMAKE_FIND_LIBRARY_SUFFIXES}") + endif() +endfunction() + + +if(GLEW_VERBOSE) + if(DEFINED GLEW_USE_STATIC_LIBS) + message(STATUS "FindGLEW: GLEW_USE_STATIC_LIBS: ${GLEW_USE_STATIC_LIBS}.") + else() + message(STATUS "FindGLEW: GLEW_USE_STATIC_LIBS is undefined. Treated as FALSE.") + endif() +endif() + find_path(GLEW_INCLUDE_DIR GL/glew.h) +mark_as_advanced(GLEW_INCLUDE_DIR) -if(NOT GLEW_LIBRARY) - find_library(GLEW_LIBRARY_RELEASE NAMES GLEW glew32 glew glew32s PATH_SUFFIXES lib64 libx32) - find_library(GLEW_LIBRARY_DEBUG NAMES GLEWd glew32d glewd PATH_SUFFIXES lib64) +set(GLEW_INCLUDE_DIRS ${GLEW_INCLUDE_DIR}) - include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) - select_library_configurations(GLEW) -endif () +if(GLEW_VERBOSE) + message(STATUS "FindGLEW: GLEW_INCLUDE_DIR: ${GLEW_INCLUDE_DIR}") + message(STATUS "FindGLEW: GLEW_INCLUDE_DIRS: ${GLEW_INCLUDE_DIRS}") +endif() + +if("${CMAKE_GENERATOR_PLATFORM}" MATCHES "x64" OR "${CMAKE_GENERATOR}" MATCHES "Win64") + set(_arch "x64") +else() + set(_arch "Win32") +endif() + + +__glew_set_find_library_suffix(SHARED) + +find_library(GLEW_SHARED_LIBRARY_RELEASE + NAMES GLEW glew glew32 + PATH_SUFFIXES lib lib64 libx32 lib/Release/${_arch} + PATHS ENV GLEW_ROOT) + +find_library(GLEW_SHARED_LIBRARY_DEBUG + NAMES GLEWd glewd glew32d + PATH_SUFFIXES lib lib64 + PATHS ENV GLEW_ROOT) + + +__glew_set_find_library_suffix(STATIC) + +find_library(GLEW_STATIC_LIBRARY_RELEASE + NAMES GLEW glew glew32s + PATH_SUFFIXES lib lib64 libx32 lib/Release/${_arch} + PATHS ENV GLEW_ROOT) + +find_library(GLEW_STATIC_LIBRARY_DEBUG + NAMES GLEWds glewds glew32ds + PATH_SUFFIXES lib lib64 + PATHS ENV GLEW_ROOT) + +include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) + +select_library_configurations(GLEW_SHARED) +select_library_configurations(GLEW_STATIC) + +if(NOT GLEW_USE_STATIC_LIBS) + set(GLEW_LIBRARIES ${GLEW_SHARED_LIBRARY}) +else() + set(GLEW_LIBRARIES ${GLEW_STATIC_LIBRARY}) +endif() + + +if(GLEW_VERBOSE) + message(STATUS "FindGLEW: GLEW_SHARED_LIBRARY_RELEASE: ${GLEW_SHARED_LIBRARY_RELEASE}") + message(STATUS "FindGLEW: GLEW_STATIC_LIBRARY_RELEASE: ${GLEW_STATIC_LIBRARY_RELEASE}") + message(STATUS "FindGLEW: GLEW_SHARED_LIBRARY_DEBUG: ${GLEW_SHARED_LIBRARY_DEBUG}") + message(STATUS "FindGLEW: GLEW_STATIC_LIBRARY_DEBUG: ${GLEW_STATIC_LIBRARY_DEBUG}") + message(STATUS "FindGLEW: GLEW_SHARED_LIBRARY: ${GLEW_SHARED_LIBRARY}") + message(STATUS "FindGLEW: GLEW_STATIC_LIBRARY: ${GLEW_STATIC_LIBRARY}") + message(STATUS "FindGLEW: GLEW_LIBRARIES: ${GLEW_LIBRARIES}") +endif() + + +# Read version from GL/glew.h file +if(EXISTS "${GLEW_INCLUDE_DIR}/GL/glew.h") + file(STRINGS "${GLEW_INCLUDE_DIR}/GL/glew.h" _contents REGEX "^VERSION_.+ [0-9]+") + if(_contents) + string(REGEX REPLACE ".*VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" GLEW_VERSION_MAJOR "${_contents}") + string(REGEX REPLACE ".*VERSION_MINOR[ \t]+([0-9]+).*" "\\1" GLEW_VERSION_MINOR "${_contents}") + string(REGEX REPLACE ".*VERSION_MICRO[ \t]+([0-9]+).*" "\\1" GLEW_VERSION_MICRO "${_contents}") + set(GLEW_VERSION "${GLEW_VERSION_MAJOR}.${GLEW_VERSION_MINOR}.${GLEW_VERSION_MICRO}") + endif() +endif() + +if(GLEW_VERBOSE) + message(STATUS "FindGLEW: GLEW_VERSION_MAJOR: ${GLEW_VERSION_MAJOR}") + message(STATUS "FindGLEW: GLEW_VERSION_MINOR: ${GLEW_VERSION_MINOR}") + message(STATUS "FindGLEW: GLEW_VERSION_MICRO: ${GLEW_VERSION_MICRO}") + message(STATUS "FindGLEW: GLEW_VERSION: ${GLEW_VERSION}") +endif() -include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) find_package_handle_standard_args(GLEW - REQUIRED_VARS GLEW_INCLUDE_DIR GLEW_LIBRARY) + REQUIRED_VARS GLEW_INCLUDE_DIRS GLEW_LIBRARIES + VERSION_VAR GLEW_VERSION) -if(GLEW_FOUND) - set(GLEW_INCLUDE_DIRS ${GLEW_INCLUDE_DIR}) +if(NOT GLEW_FOUND) + if(GLEW_VERBOSE) + message(STATUS "FindGLEW: could not found GLEW library.") + endif() + return() +endif() + + +if(NOT TARGET GLEW::glew AND NOT GLEW_USE_STATIC_LIBS) + if(GLEW_VERBOSE) + message(STATUS "FindGLEW: Creating GLEW::glew imported target.") + endif() + + add_library(GLEW::glew UNKNOWN IMPORTED) + + set_target_properties(GLEW::glew + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${GLEW_INCLUDE_DIRS}") + + if(GLEW_SHARED_LIBRARY_RELEASE) + set_property(TARGET GLEW::glew + APPEND + PROPERTY IMPORTED_CONFIGURATIONS RELEASE) + + set_target_properties(GLEW::glew + PROPERTIES IMPORTED_LOCATION_RELEASE "${GLEW_SHARED_LIBRARY_RELEASE}") + endif() + + if(GLEW_SHARED_LIBRARY_DEBUG) + set_property(TARGET GLEW::glew + APPEND + PROPERTY IMPORTED_CONFIGURATIONS DEBUG) + + set_target_properties(GLEW::glew + PROPERTIES IMPORTED_LOCATION_DEBUG "${GLEW_SHARED_LIBRARY_DEBUG}") + endif() - if(NOT GLEW_LIBRARIES) - set(GLEW_LIBRARIES ${GLEW_LIBRARY}) +elseif(NOT TARGET GLEW::glew_s AND GLEW_USE_STATIC_LIBS) + if(GLEW_VERBOSE) + message(STATUS "FindGLEW: Creating GLEW::glew_s imported target.") endif() - if (NOT TARGET GLEW::GLEW) - add_library(GLEW::GLEW UNKNOWN IMPORTED) - set_target_properties(GLEW::GLEW PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${GLEW_INCLUDE_DIRS}") + add_library(GLEW::glew_s UNKNOWN IMPORTED) - if(GLEW_LIBRARY_RELEASE) - set_property(TARGET GLEW::GLEW APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) - set_target_properties(GLEW::GLEW PROPERTIES IMPORTED_LOCATION_RELEASE "${GLEW_LIBRARY_RELEASE}") + set_target_properties(GLEW::glew_s + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${GLEW_INCLUDE_DIRS}") + + if(GLEW_STATIC_LIBRARY_RELEASE) + set_property(TARGET GLEW::glew_s + APPEND + PROPERTY IMPORTED_CONFIGURATIONS RELEASE) + + set_target_properties(GLEW::glew_s + PROPERTIES IMPORTED_LOCATION_RELEASE "${GLEW_STATIC_LIBRARY_RELEASE}") + endif() + + if(GLEW_STATIC_LIBRARY_DEBUG) + set_property(TARGET GLEW::glew_s + APPEND + PROPERTY IMPORTED_CONFIGURATIONS DEBUG) + + set_target_properties(GLEW::glew_s + PROPERTIES IMPORTED_LOCATION_DEBUG "${GLEW_STATIC_LIBRARY_DEBUG}") + endif() +endif() + +if(NOT TARGET GLEW::GLEW) + if(GLEW_VERBOSE) + message(STATUS "FindGLEW: Creating GLEW::GLEW imported target.") + endif() + + add_library(GLEW::GLEW UNKNOWN IMPORTED) + + set_target_properties(GLEW::GLEW + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${GLEW_INCLUDE_DIRS}") + + if(TARGET GLEW::glew) + if(GLEW_SHARED_LIBRARY_RELEASE) + set_property(TARGET GLEW::GLEW + APPEND + PROPERTY IMPORTED_CONFIGURATIONS RELEASE) + + set_target_properties(GLEW::GLEW + PROPERTIES IMPORTED_LOCATION_RELEASE "${GLEW_SHARED_LIBRARY_RELEASE}") + endif() + + if(GLEW_SHARED_LIBRARY_DEBUG) + set_property(TARGET GLEW::GLEW + APPEND + PROPERTY IMPORTED_CONFIGURATIONS DEBUG) + + set_target_properties(GLEW::GLEW + PROPERTIES IMPORTED_LOCATION_DEBUG "${GLEW_SHARED_LIBRARY_DEBUG}") endif() - if(GLEW_LIBRARY_DEBUG) - set_property(TARGET GLEW::GLEW APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) - set_target_properties(GLEW::GLEW PROPERTIES IMPORTED_LOCATION_DEBUG "${GLEW_LIBRARY_DEBUG}") + elseif(TARGET GLEW::glew_s) + if(GLEW_STATIC_LIBRARY_RELEASE) + set_property(TARGET GLEW::GLEW + APPEND + PROPERTY IMPORTED_CONFIGURATIONS RELEASE) + + set_target_properties(GLEW::GLEW + PROPERTIES IMPORTED_LOCATION_RELEASE "${GLEW_STATIC_LIBRARY_RELEASE}") endif() - if(NOT GLEW_LIBRARY_RELEASE AND NOT GLEW_LIBRARY_DEBUG) - set_property(TARGET GLEW::GLEW APPEND PROPERTY IMPORTED_LOCATION "${GLEW_LIBRARY}") + if(GLEW_STATIC_LIBRARY_DEBUG AND GLEW_USE_STATIC_LIBS) + set_property(TARGET GLEW::GLEW + APPEND + PROPERTY IMPORTED_CONFIGURATIONS DEBUG) + + set_target_properties(GLEW::GLEW + PROPERTIES IMPORTED_LOCATION_DEBUG "${GLEW_STATIC_LIBRARY_DEBUG}") endif() + + elseif(GLEW_VERBOSE) + message(WARNING "FindGLEW: no `GLEW::glew` or `GLEW::glew_s` target was created. Something went wrong in FindGLEW target creation.") endif() endif() - -mark_as_advanced(GLEW_INCLUDE_DIR) |