Home | History | Annotate | Download | only in icd
      1 cmake_minimum_required (VERSION 2.8.11)
      2 if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
      3     add_definitions(-DVK_USE_PLATFORM_WIN32_KHR -DVK_USE_PLATFORM_WIN32_KHX -DWIN32_LEAN_AND_MEAN)
      4     set(DisplayServer Win32)
      5 elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
      6     add_definitions(-DVK_USE_PLATFORM_ANDROID_KHR -DVK_USE_PLATFORM_ANDROID_KHX)
      7 elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
      8     if (BUILD_WSI_XCB_SUPPORT)
      9         add_definitions(-DVK_USE_PLATFORM_XCB_KHR -DVK_USE_PLATFORM_XCB_KHX)
     10     endif()
     11 
     12     if (BUILD_WSI_XLIB_SUPPORT)
     13        add_definitions(-DVK_USE_PLATFORM_XLIB_KHR -DVK_USE_PLATFORM_XLIB_KHX -DVK_USE_PLATFORM_XLIB_XRANDR_EXT)
     14     endif()
     15 
     16     if (BUILD_WSI_WAYLAND_SUPPORT)
     17        add_definitions(-DVK_USE_PLATFORM_WAYLAND_KHR -DVK_USE_PLATFORM_WAYLAND_KHX)
     18     endif()
     19 
     20     if (BUILD_WSI_MIR_SUPPORT)
     21         add_definitions(-DVK_USE_PLATFORM_MIR_KHR -DVK_USE_PLATFORM_MIR_KHX)
     22         include_directories(${MIR_INCLUDE_DIR})
     23     endif()
     24 else()
     25     message(FATAL_ERROR "Unsupported Platform!")
     26 endif()
     27 
     28 set(ICD_JSON_FILES VkICD_mock_icd)
     29 
     30 if (WIN32)
     31     if (NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
     32         if (CMAKE_GENERATOR MATCHES "^Visual Studio.*")
     33             foreach (config_file ${ICD_JSON_FILES})
     34                 FILE(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/windows/${config_file}.json src_json)
     35                 FILE(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>/${config_file}.json dst_json)
     36                 add_custom_target(${config_file}-json ALL
     37                     COMMAND copy ${src_json} ${dst_json}
     38                     VERBATIM
     39                     )
     40                 set_target_properties(${config_file}-json PROPERTIES FOLDER ${LVL_TARGET_FOLDER})
     41             endforeach(config_file)
     42         else()
     43             foreach (config_file ${ICD_JSON_FILES})
     44                 FILE(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/windows/${config_file}.json src_json)
     45                 FILE(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${config_file}.json dst_json)
     46                 add_custom_target(${config_file}-json ALL
     47                     COMMAND copy ${src_json} ${dst_json}
     48                     VERBATIM
     49                     )
     50             endforeach(config_file)
     51         endif()
     52     endif()
     53 else()
     54     # extra setup for out-of-tree builds
     55     if (NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
     56         foreach (config_file ${ICD_JSON_FILES})
     57             add_custom_target(${config_file}-json ALL
     58                 COMMAND ln -sf ${CMAKE_CURRENT_SOURCE_DIR}/linux/${config_file}.json
     59                 VERBATIM
     60                 )
     61         endforeach(config_file)
     62     endif()
     63 endif()
     64 # For ICD with a direct dependency on a project with the same name, use it.
     65 if (NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
     66     foreach (config_file ${ICD_JSON_FILES})
     67         add_dependencies(${config_file}-json ${config_file})
     68     endforeach(config_file)
     69 endif()
     70 
     71 add_custom_target(generate_icd_files DEPENDS
     72     mock_icd.h
     73     mock_icd.cpp
     74     )
     75 set_target_properties(generate_icd_files PROPERTIES FOLDER ${LVL_TARGET_FOLDER})
     76 
     77 if (WIN32)
     78     macro(add_vk_icd target)
     79     FILE(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/VkICD_${target}.def DEF_FILE)
     80     add_custom_target(copy-${target}-def-file ALL
     81         COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DEF_FILE} VkICD_${target}.def
     82         VERBATIM
     83     )
     84     set_target_properties(copy-${target}-def-file PROPERTIES FOLDER ${LVL_TARGET_FOLDER})
     85     add_library(VkICD_${target} SHARED ${ARGN} VkICD_${target}.def)
     86     add_dependencies(VkICD_${target} generate_icd_files)
     87     #target_link_Libraries(VkICD_${target} VkICD_utils)
     88     #add_dependencies(VkICD_${target} generate_helper_files VkICD_utils)
     89     endmacro()
     90 else()
     91     macro(add_vk_icd target)
     92     add_library(VkICD_${target} SHARED ${ARGN})
     93     #target_link_Libraries(VkICD_${target} VkICD_utils)
     94     add_dependencies(VkICD_${target} generate_icd_files)
     95     set_target_properties(VkICD_${target} PROPERTIES LINK_FLAGS "-Wl,-export-dynamic,-Bsymbolic,--exclude-libs,ALL")
     96     if(INSTALL_ICD_FILES)
     97         install(TARGETS VkICD_${target} DESTINATION ${CMAKE_INSTALL_LIBDIR})
     98     endif()
     99     endmacro()
    100 endif()
    101 
    102 include_directories(
    103     ${CMAKE_CURRENT_SOURCE_DIR}
    104     ${CMAKE_CURRENT_SOURCE_DIR}/../loader
    105     ${CMAKE_CURRENT_SOURCE_DIR}/../include/vulkan
    106     ${CMAKE_CURRENT_BINARY_DIR}
    107     ${PROJECT_BINARY_DIR}
    108     ${CMAKE_BINARY_DIR}
    109 )
    110 
    111 if (WIN32)
    112     set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -D_CRT_SECURE_NO_WARNINGS")
    113     set (CMAKE_C_FLAGS_RELEASE   "${CMAKE_C_FLAGS_RELEASE} -D_CRT_SECURE_NO_WARNINGS")
    114     set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -D_CRT_SECURE_NO_WARNINGS")
    115     set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D_CRT_SECURE_NO_WARNINGS")
    116     set (CMAKE_CXX_FLAGS_DEBUG   "${CMAKE_CXX_FLAGS_DEBUG} -D_CRT_SECURE_NO_WARNINGS /bigobj")
    117     set (CMAKE_C_FLAGS_DEBUG     "${CMAKE_C_FLAGS_DEBUG} -D_CRT_SECURE_NO_WARNINGS /bigobj")
    118     # Turn off transitional "changed behavior" warning message for Visual Studio versions prior to 2015.
    119     # The changed behavior is that constructor initializers are now fixed to clear the struct members.
    120     add_compile_options("$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,19>>:/wd4351>")
    121 else()
    122     set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpointer-arith -Wno-unused-function -Wno-sign-compare")
    123     set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpointer-arith -Wno-unused-function -Wno-sign-compare")
    124 endif()
    125 
    126 run_vk_xml_generate(mock_icd_generator.py mock_icd.h)
    127 run_vk_xml_generate(mock_icd_generator.py mock_icd.cpp)
    128 
    129 add_vk_icd(mock_icd mock_icd.cpp mock_icd.h)
    130 
    131