summaryrefslogtreecommitdiff
path: root/cmake_modules
diff options
context:
space:
mode:
authorEdward O'Callaghan <funfunctor@folklore1984.net>2017-02-07 22:02:38 +1100
committerEdward O'Callaghan <funfunctor@folklore1984.net>2017-02-07 22:02:38 +1100
commit58044a07dfe9ae1fb21d2dfa4aa779693d68fda4 (patch)
tree56553a9f996ec34b0d320c0f90288c288fe533e6 /cmake_modules
parent3b59e8ff0e0a58cf1a068d624eebd5b0594374b0 (diff)
cmake_modules/: Add missing finder modules
Signed-off-by: Edward O'Callaghan <funfunctor@folklore1984.net>
Diffstat (limited to 'cmake_modules')
-rw-r--r--cmake_modules/FindGLFW.cmake132
-rw-r--r--cmake_modules/FindVulkan.cmake75
2 files changed, 207 insertions, 0 deletions
diff --git a/cmake_modules/FindGLFW.cmake b/cmake_modules/FindGLFW.cmake
new file mode 100644
index 0000000..32f7771
--- /dev/null
+++ b/cmake_modules/FindGLFW.cmake
@@ -0,0 +1,132 @@
+# Locate GLFW library (3.x)
+#
+# This module defines:
+#
+# GLFW_FOUND, if false, do not try to link to GLFW
+# GLFW_LIBRARY, the name of the library to link against
+# GLFW_LIBRARIES, the full list of libs to link against
+# GLFW_INCLUDE_DIR, where to find glfw3.h
+#=============================================================================
+
+FIND_PATH(GLFW_INCLUDE_DIR glfw3.h
+ HINTS
+ $ENV{GLFWDIR}
+ PATH_SUFFIXES include/GL include
+ PATHS
+ ~/Library/Frameworks
+ /Library/Frameworks
+ /usr/local/include/GLFW
+ /usr/include/GLFW
+ /sw # Fink
+ /opt/local # DarwinPorts
+ /opt/csw # Blastwave
+ /opt
+)
+
+#MESSAGE("GLFW_INCLUDE_DIR is ${GLFW_INCLUDE_DIR}")
+
+FIND_LIBRARY(GLFW_LIBRARY
+ NAMES glfw glfw3 GLFW
+ HINTS
+ $ENV{GLFWDIR}
+ PATH_SUFFIXES lib64 lib
+ PATHS
+ /sw
+ /usr
+ /usr/local
+ /opt/local
+ /opt/csw
+ /opt
+)
+
+SET(GLFW_FOUND FALSE)
+
+IF(NOT GLFW_LIBRARY OR FORCE_DOWNLOAD_GLFW)
+ # If not found, try to build with local sources.
+ # It uses CMake's "ExternalProject_Add" target.
+ MESSAGE(STATUS "Preparing external GLFW project")
+ INCLUDE(ExternalProject)
+ ExternalProject_Add(project_glfw
+ URL http://sourceforge.net/projects/glfw/files/glfw/3.0.4/glfw-3.0.4.zip
+ URL_MD5 3949775a24ae921c8de8b948236f3c9a
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -DGLFW_BUILD_DOCS:BOOL=OFF -DGLFW_BUILD_EXAMPLES:BOOL=OFF -DGLFW_BUILD_TESTS:BOOL=OFF
+ LOG_DOWNLOAD 1
+ LOG_UPDATE 1
+ LOG_CONFIGURE 1
+ LOG_BUILD 1
+ LOG_TEST 1
+ LOG_INSTALL 1
+ )
+ MESSAGE(STATUS "External GLFW project done")
+
+ ExternalProject_Get_Property(project_glfw install_dir)
+ SET(GLFW_INCLUDE_DIR
+ ${install_dir}/src/project_glfw/include
+ )
+
+ IF(WIN32)
+ SET(GLFW_LIBRARY
+ ${install_dir}/lib/glfw3.lib
+ )
+ ELSE(WIN32)
+ SET(GLFW_LIBRARY
+ ${install_dir}/lib/libglfw3.a
+ )
+ ENDIF(WIN32)
+
+ENDIF(NOT GLFW_LIBRARY OR FORCE_DOWNLOAD_GLFW)
+
+#MESSAGE("GLFW_LIBRARY is ${GLFW_LIBRARY}")
+
+IF(GLFW_LIBRARY)
+
+ SET(GLFW_LIBRARIES ${GLFW_LIBRARY} CACHE STRING "All the libs required to link GLFW")
+
+ # GLFW may require threads on your system.
+ # The Apple build may not need an explicit flag because one of the
+ # frameworks may already provide it.
+ # But for non-OSX systems, I will use the CMake Threads package.
+ # In fact, there seems to be a problem if I used the Threads package
+ # and try using this line, so I'm just skipping it entirely for OS X.
+ IF(NOT APPLE)
+ FIND_PACKAGE(Threads)
+ SET(GLFW_LIBRARIES ${GLFW_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
+ ENDIF(NOT APPLE)
+
+ # For OS X, GLFW uses Cocoa as a backend so it must link to Cocoa.
+ IF(APPLE OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+ FIND_LIBRARY(COCOA_LIBRARY Cocoa)
+ FIND_LIBRARY(OPENGL_LIBRARY OpenGL)
+ FIND_LIBRARY(IOKIT_LIBRARY IOKit)
+ FIND_LIBRARY(COREVIDEO_LIBRARY CoreVideo)
+ SET(GLFW_LIBRARIES ${GLFW_LIBRARIES} ${COCOA_LIBRARY} ${OPENGL_LIBRARY} ${IOKIT_LIBRARY} ${COREVIDEO_LIBRARY})
+ ENDIF(APPLE OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+
+ # For MinGW library.
+ IF(MINGW)
+ # MinGW needs an additional library, mwindows
+ # It's total link flags should look like -lmingw32 -lGLFW -lmwindows
+ # (Actually on second look, I think it only needs one of the m* libraries.)
+ SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
+ SET(GLFW_LIBRARIES ${MINGW32_LIBRARY} ${GLFW_LIBRARIES})
+ ENDIF(MINGW)
+
+ # For Unix, GLFW should be linked to X11-releated libraries.
+ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+ FIND_LIBRARY(X11_LIBRARY X11)
+ FIND_LIBRARY(Xrandr_LIBRARY Xrandr)
+ FIND_LIBRARY(Xxf86vm_LIBRARY Xxf86vm)
+ FIND_LIBRARY(Xi_LIBRARY Xi)
+ SET(GLFW_LIBRARIES ${GLFW_LIBRARIES} ${X11_LIBRARY} ${Xrandr_LIBRARY} ${Xxf86vm_LIBRARY} ${Xi_LIBRARY})
+ ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+
+ # Set the final string here so the GUI reflects the final state.
+ SET(GLFW_LIBRARY ${GLFW_LIBRARY} CACHE STRING "Where the GLFW Library can be found")
+
+ SET(GLFW_FOUND TRUE)
+
+ #MESSAGE("GLFW_LIBRARIES is ${GLFW_LIBRARIES}")
+
+ENDIF(GLFW_LIBRARY)
+
+MESSAGE("-- Found GLFW: ${GLFW_FOUND}")
diff --git a/cmake_modules/FindVulkan.cmake b/cmake_modules/FindVulkan.cmake
new file mode 100644
index 0000000..820e0eb
--- /dev/null
+++ b/cmake_modules/FindVulkan.cmake
@@ -0,0 +1,75 @@
+# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
+#.rst:
+# FindVulkan
+# ----------
+#
+# Try to find Vulkan
+#
+# IMPORTED Targets
+# ^^^^^^^^^^^^^^^^
+#
+# This module defines :prop_tgt:`IMPORTED` target ``Vulkan::Vulkan``, if
+# Vulkan has been found.
+#
+# Result Variables
+# ^^^^^^^^^^^^^^^^
+#
+# This module defines the following variables::
+#
+# Vulkan_FOUND - True if Vulkan was found
+# Vulkan_INCLUDE_DIRS - include directories for Vulkan
+# Vulkan_LIBRARIES - link against this library to use Vulkan
+#
+# The module will also define two cache variables::
+#
+# Vulkan_INCLUDE_DIR - the Vulkan include directory
+# Vulkan_LIBRARY - the path to the Vulkan library
+#
+
+if(WIN32)
+ find_path(Vulkan_INCLUDE_DIR
+ NAMES vulkan/vulkan.h
+ PATHS
+ "$ENV{VULKAN_SDK}/Include"
+ )
+
+ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ find_library(Vulkan_LIBRARY
+ NAMES vulkan-1
+ PATHS
+ "$ENV{VULKAN_SDK}/Bin")
+ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
+ find_library(Vulkan_LIBRARY
+ NAMES vulkan-1
+ PATHS
+ "$ENV{VULKAN_SDK}/Bin32")
+ endif()
+else()
+ find_path(Vulkan_INCLUDE_DIR
+ NAMES vulkan/vulkan.h
+ PATHS
+ "$ENV{VULKAN_SDK}/include")
+ find_library(Vulkan_LIBRARY
+ NAMES vulkan
+ PATHS
+ "$ENV{VULKAN_SDK}/lib")
+endif()
+
+set(Vulkan_LIBRARIES ${Vulkan_LIBRARY})
+set(Vulkan_INCLUDE_DIRS ${Vulkan_INCLUDE_DIR})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Vulkan
+ DEFAULT_MSG
+ Vulkan_LIBRARY Vulkan_INCLUDE_DIR)
+
+mark_as_advanced(Vulkan_INCLUDE_DIR Vulkan_LIBRARY)
+
+if(Vulkan_FOUND AND NOT TARGET Vulkan::Vulkan)
+ add_library(Vulkan::Vulkan UNKNOWN IMPORTED)
+ set_target_properties(Vulkan::Vulkan PROPERTIES
+ IMPORTED_LOCATION "${Vulkan_LIBRARIES}"
+ INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
+endif()