Home | History | Annotate | Download | only in vulkan-validation-layers
      1 # The name of our project is "VULKAN". CMakeLists files in this project can
      2 # refer to the root source directory of the project as ${VULKAN_SOURCE_DIR} and
      3 # to the root binary directory of the project as ${VULKAN_BINARY_DIR}.
      4 cmake_minimum_required(VERSION 2.8.11)
      5 project (VULKAN)
      6 # set (CMAKE_VERBOSE_MAKEFILE 1)
      7 
      8 # The MAJOR number of the version we're building, used in naming
      9 # vulkan-<major>.dll (and other files).
     10 set(MAJOR "1")
     11 
     12 find_package(PythonInterp 3 REQUIRED)
     13 
     14 if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
     15     add_definitions(-DVK_USE_PLATFORM_WIN32_KHR -DWIN32_LEAN_AND_MEAN)
     16     set(DisplayServer Win32)
     17 elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
     18     add_definitions(-DVK_USE_PLATFORM_ANDROID_KHR)
     19     set(DisplayServer Android)
     20 elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
     21     #   TODO: Basic support is present for Xlib but is untested.
     22     #         Mir support is stubbed in but unimplemented and untested.
     23     option(BUILD_WSI_XCB_SUPPORT "Build XCB WSI support" ON)
     24     option(BUILD_WSI_XLIB_SUPPORT "Build Xlib WSI support" ON)
     25     option(BUILD_WSI_WAYLAND_SUPPORT "Build Wayland WSI support" OFF)
     26     option(BUILD_WSI_MIR_SUPPORT "Build Mir WSI support" OFF)
     27 
     28     if (BUILD_WSI_XCB_SUPPORT)
     29         add_definitions(-DVK_USE_PLATFORM_XCB_KHR)
     30         set(DisplayServer Xcb)
     31     endif()
     32 
     33     if (BUILD_WSI_XLIB_SUPPORT)
     34         add_definitions(-DVK_USE_PLATFORM_XLIB_KHR)
     35         set(DisplayServer Xlib)
     36     endif()
     37 
     38     if (BUILD_WSI_WAYLAND_SUPPORT)
     39         add_definitions(-DVK_USE_PLATFORM_WAYLAND_KHR)
     40         set(DisplayServer Wayland)
     41     endif()
     42 
     43     if (BUILD_WSI_MIR_SUPPORT)
     44         add_definitions(-DVK_USE_PLATFORM_MIR_KHR)
     45         set(DisplayServer Mir)
     46     endif()
     47 else()
     48     message(FATAL_ERROR "Unsupported Platform!")
     49 endif()
     50 
     51 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
     52 
     53 # Header file for CMake settings
     54 include_directories("${PROJECT_SOURCE_DIR}/include")
     55 
     56 if(NOT WIN32)
     57     include(FindPkgConfig)
     58 endif()
     59 
     60 set (CMAKE_INSTALL_PREFIX "")
     61 
     62 if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
     63     set(COMMON_COMPILE_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers")
     64     set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -fno-strict-aliasing -fno-builtin-memcmp")
     65     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 ${COMMON_COMPILE_FLAGS}")
     66     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_COMPILE_FLAGS} -std=c++11")
     67     if (UNIX)
     68         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
     69         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
     70     endif()
     71 endif()
     72 
     73 if(NOT WIN32)
     74     find_package(XCB REQUIRED)
     75     set (BUILDTGT_DIR build)
     76     set (BINDATA_DIR Bin)
     77     set (LIBSOURCE_DIR Lib)
     78 else()
     79     # For Windows, since 32-bit and 64-bit items can co-exist, we build each in its own build directory.
     80     # 32-bit target data goes in build32, and 64-bit target data goes into build.  So, include/link the
     81     # appropriate data at build time.
     82     if (CMAKE_CL_64)
     83         set (BUILDTGT_DIR build)
     84         set (BINDATA_DIR Bin)
     85         set (LIBSOURCE_DIR Lib)
     86     else()
     87         set (BUILDTGT_DIR build32)
     88         set (BINDATA_DIR Bin32)
     89         set (LIBSOURCE_DIR Lib32)
     90     endif()
     91 endif()
     92 
     93 option(BUILD_LOADER "Build loader" ON)
     94 option(BUILD_TESTS "Build tests" ON)
     95 option(BUILD_LAYERS "Build layers" ON)
     96 option(BUILD_DEMOS "Build demos" ON)
     97 option(BUILD_VKJSON "Build vkjson" ON)
     98 
     99 find_program(GLSLANG_VALIDATOR NAMES glslangValidator
    100              HINTS "${CMAKE_SOURCE_DIR}/../glslang/${BUILDTGT_DIR}/install/bin"
    101                    "${PROJECT_SOURCE_DIR}/../${BINDATA_DIR}" )
    102 
    103 find_path(GLSLANG_SPIRV_INCLUDE_DIR SPIRV/spirv.hpp HINTS "${CMAKE_SOURCE_DIR}/../glslang" DOC "Path to SPIRV/spirv.hpp")
    104 find_path(SPIRV_TOOLS_INCLUDE_DIR spirv-tools/libspirv.h HINTS "${CMAKE_SOURCE_DIR}/../spirv-tools/include"
    105                                                                "${CMAKE_SOURCE_DIR}/../source/spirv-tools/include"
    106                                                                "${CMAKE_SOURCE_DIR}/../spirv-tools/external/include"
    107                                                                "${CMAKE_SOURCE_DIR}/../source/spirv-tools/external/include"
    108                                                          DOC "Path to spirv-tools/libspirv.h")
    109 
    110 if (WIN32)
    111     set (GLSLANG_SEARCH_PATH "${CMAKE_SOURCE_DIR}/../glslang/${BUILDTGT_DIR}/glslang/Release"
    112                              "${CMAKE_SOURCE_DIR}/../glslang/${BUILDTGT_DIR}/glslang/OSDependent/Windows/Release"
    113                              "${CMAKE_SOURCE_DIR}/../glslang/${BUILDTGT_DIR}/OGLCompilersDLL/Release"
    114                              "${CMAKE_SOURCE_DIR}/../glslang/${BUILDTGT_DIR}/SPIRV/Release" )
    115     set (SPIRV_TOOLS_SEARCH_PATH "${CMAKE_SOURCE_DIR}/../spirv-tools/${BUILDTGT_DIR}/Release")
    116 else()
    117     set (GLSLANG_SEARCH_PATH "${CMAKE_SOURCE_DIR}/../glslang/build/install/lib" "${CMAKE_SOURCE_DIR}/../x86_64/lib/glslang" )
    118     set (SPIRV_TOOLS_SEARCH_PATH "${CMAKE_SOURCE_DIR}/../spirv-tools/build" "${CMAKE_SOURCE_DIR}/../x86_64/lib/spirv-tools" )
    119 endif()
    120 
    121 find_library(GLSLANG_LIB NAMES glslang
    122              HINTS ${GLSLANG_SEARCH_PATH} )
    123 
    124 find_library(OGLCompiler_LIB NAMES OGLCompiler
    125              HINTS ${GLSLANG_SEARCH_PATH} )
    126 
    127 find_library(OSDependent_LIB NAMES OSDependent
    128              HINTS ${GLSLANG_SEARCH_PATH} )
    129 
    130 find_library(SPIRV_LIB NAMES SPIRV
    131              HINTS ${GLSLANG_SEARCH_PATH} )
    132 
    133 find_library(SPIRV_TOOLS_LIB NAMES SPIRV-Tools
    134              HINTS ${SPIRV_TOOLS_SEARCH_PATH} )
    135 
    136 # On Windows, we must pair Debug and Release appropriately
    137 if (WIN32)
    138     set (GLSLANG_DEBUG_SEARCH_PATH "${CMAKE_SOURCE_DIR}/../glslang/${BUILDTGT_DIR}/glslang/Debug"
    139                                    "${CMAKE_SOURCE_DIR}/../glslang/${BUILDTGT_DIR}/glslang/OSDependent/Windows/Debug"
    140                                    "${CMAKE_SOURCE_DIR}/../glslang/${BUILDTGT_DIR}/OGLCompilersDLL/Debug"
    141                                    "${CMAKE_SOURCE_DIR}/../glslang/${BUILDTGT_DIR}/SPIRV/Debug")
    142     set (SPIRV_TOOLS_DEBUG_SEARCH_PATH "${CMAKE_SOURCE_DIR}/../spirv-tools/${BUILDTGT_DIR}/Debug")
    143 
    144     add_library(glslang     STATIC IMPORTED)
    145     add_library(OGLCompiler STATIC IMPORTED)
    146     add_library(OSDependent STATIC IMPORTED)
    147     add_library(SPIRV       STATIC IMPORTED)
    148     add_library(Loader      STATIC IMPORTED)
    149     add_library(SPIRV-Tools STATIC IMPORTED)
    150 
    151     find_library(GLSLANG_DLIB NAMES glslang
    152                  HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
    153     find_library(OGLCompiler_DLIB NAMES OGLCompiler
    154                  HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
    155     find_library(OSDependent_DLIB NAMES OSDependent
    156                  HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
    157     find_library(SPIRV_DLIB NAMES SPIRV
    158                  HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
    159     find_library(SPIRV_TOOLS_DLIB NAMES SPIRV-Tools
    160                  HINTS ${SPIRV_TOOLS_DEBUG_SEARCH_PATH} )
    161 
    162     set_target_properties(glslang PROPERTIES
    163                          IMPORTED_LOCATION       "${GLSLANG_LIB}"
    164                          IMPORTED_LOCATION_DEBUG "${GLSLANG_DLIB}")
    165     set_target_properties(OGLCompiler PROPERTIES
    166                          IMPORTED_LOCATION       "${OGLCompiler_LIB}"
    167                          IMPORTED_LOCATION_DEBUG "${OGLCompiler_DLIB}")
    168     set_target_properties(OSDependent PROPERTIES
    169                          IMPORTED_LOCATION       "${OSDependent_LIB}"
    170                          IMPORTED_LOCATION_DEBUG "${OSDependent_DLIB}")
    171     set_target_properties(SPIRV PROPERTIES
    172                          IMPORTED_LOCATION       "${SPIRV_LIB}"
    173                          IMPORTED_LOCATION_DEBUG "${SPIRV_DLIB}")
    174     set_target_properties(SPIRV-Tools PROPERTIES
    175                          IMPORTED_LOCATION       "${SPIRV_TOOLS_LIB}"
    176                          IMPORTED_LOCATION_DEBUG "${SPIRV_TOOLS_DLIB}")
    177 
    178     set (GLSLANG_LIBRARIES glslang OGLCompiler OSDependent SPIRV)
    179     set (SPIRV_TOOLS_LIBRARIES SPIRV-Tools)
    180 else ()
    181     set (GLSLANG_LIBRARIES ${GLSLANG_LIB} ${OGLCompiler_LIB} ${OSDependent_LIB} ${SPIRV_LIB})
    182     set (SPIRV_TOOLS_LIBRARIES ${SPIRV_TOOLS_LIB})
    183 endif()
    184 
    185 set (PYTHON_CMD ${PYTHON_EXECUTABLE})
    186 
    187 if(NOT WIN32)
    188     include(GNUInstallDirs)
    189     add_definitions(-DSYSCONFDIR="${CMAKE_INSTALL_SYSCONFDIR}")
    190     add_definitions(-DDATADIR="${CMAKE_INSTALL_DATADIR}")
    191     if (CMAKE_INSTALL_PREFIX STREQUAL "/usr")
    192     elseif (CMAKE_INSTALL_PREFIX STREQUAL "")
    193     else()
    194         add_definitions(-DLOCALPREFIX="${CMAKE_INSTALL_PREFIX}")
    195     endif()
    196 endif()
    197 
    198 # loader: Generic VULKAN ICD loader
    199 # tests: VULKAN tests
    200 if(BUILD_LOADER)
    201     add_subdirectory(loader)
    202 endif()
    203 
    204 if(BUILD_TESTS)
    205     add_subdirectory(tests)
    206 endif()
    207 
    208 if(BUILD_LAYERS)
    209     add_subdirectory(layers)
    210 endif()
    211 
    212 if(BUILD_DEMOS)
    213     add_subdirectory(demos)
    214 endif()
    215 
    216 if(BUILD_VKJSON)
    217     add_subdirectory(libs/vkjson)
    218 endif()
    219