CMakeLists.txt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # increase to 3.1 once all major distributions
  2. # include a version of CMake >= 3.1
  3. cmake_minimum_required(VERSION 2.8.12)
  4. if (POLICY CMP0048)
  5. cmake_policy(SET CMP0048 NEW)
  6. endif()
  7. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  8. # Adhere to GNU filesystem layout conventions
  9. include(GNUInstallDirs)
  10. option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
  11. set(LIB_TYPE STATIC)
  12. if(BUILD_SHARED_LIBS)
  13. set(LIB_TYPE SHARED)
  14. endif()
  15. option(SKIP_GLSLANG_INSTALL "Skip installation" ${SKIP_GLSLANG_INSTALL})
  16. if(NOT ${SKIP_GLSLANG_INSTALL})
  17. set(ENABLE_GLSLANG_INSTALL ON)
  18. endif()
  19. option(ENABLE_SPVREMAPPER "Enables building of SPVRemapper" ON)
  20. option(ENABLE_AMD_EXTENSIONS "Enables support of AMD-specific extensions" ON)
  21. option(ENABLE_GLSLANG_BINARIES "Builds glslangValidator and spirv-remap" ON)
  22. option(ENABLE_NV_EXTENSIONS "Enables support of Nvidia-specific extensions" ON)
  23. option(ENABLE_HLSL "Enables HLSL input support" ON)
  24. option(ENABLE_OPT "Enables spirv-opt capability if present" ON)
  25. if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
  26. set(CMAKE_INSTALL_PREFIX "install" CACHE STRING "..." FORCE)
  27. endif()
  28. option(USE_CCACHE "Use ccache" OFF)
  29. if(USE_CCACHE)
  30. find_program(CCACHE_FOUND ccache)
  31. if(CCACHE_FOUND)
  32. set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
  33. endif(CCACHE_FOUND)
  34. endif()
  35. project(glslang)
  36. # make testing optional
  37. include(CTest)
  38. if(ENABLE_AMD_EXTENSIONS)
  39. add_definitions(-DAMD_EXTENSIONS)
  40. endif(ENABLE_AMD_EXTENSIONS)
  41. if(ENABLE_NV_EXTENSIONS)
  42. add_definitions(-DNV_EXTENSIONS)
  43. endif(ENABLE_NV_EXTENSIONS)
  44. if(ENABLE_HLSL)
  45. add_definitions(-DENABLE_HLSL)
  46. endif(ENABLE_HLSL)
  47. if(WIN32)
  48. set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Adds a postfix for debug-built libraries.")
  49. if(MSVC)
  50. include(ChooseMSVCCRT.cmake)
  51. endif(MSVC)
  52. add_definitions(-DGLSLANG_OSINCLUDE_WIN32)
  53. elseif(UNIX)
  54. add_definitions(-DGLSLANG_OSINCLUDE_UNIX)
  55. else(WIN32)
  56. message("unknown platform")
  57. endif(WIN32)
  58. if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
  59. add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs
  60. -Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions)
  61. add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
  62. elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
  63. add_compile_options(-Wall -Wuninitialized -Wunused -Wunused-local-typedefs
  64. -Wunused-parameter -Wunused-value -Wunused-variable)
  65. add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
  66. endif()
  67. # Request C++11
  68. if(${CMAKE_VERSION} VERSION_LESS 3.1)
  69. # CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD
  70. # remove this block once CMake >=3.1 has fixated in the ecosystem
  71. add_compile_options(-std=c++11)
  72. else()
  73. set(CMAKE_CXX_STANDARD 11)
  74. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  75. set(CMAKE_CXX_EXTENSIONS OFF)
  76. endif()
  77. function(glslang_set_link_args TARGET)
  78. # For MinGW compiles, statically link against the GCC and C++ runtimes.
  79. # This avoids the need to ship those runtimes as DLLs.
  80. if(WIN32 AND ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
  81. set_target_properties(${TARGET} PROPERTIES
  82. LINK_FLAGS "-static -static-libgcc -static-libstdc++")
  83. endif()
  84. endfunction(glslang_set_link_args)
  85. # We depend on these for later projects, so they should come first.
  86. add_subdirectory(External)
  87. if(NOT TARGET SPIRV-Tools-opt)
  88. set(ENABLE_OPT OFF)
  89. endif()
  90. if(ENABLE_OPT)
  91. message(STATUS "optimizer enabled")
  92. add_definitions(-DENABLE_OPT=1)
  93. else()
  94. if(ENABLE_HLSL)
  95. message(STATUS "spirv-tools not linked - illegal SPIRV may be generated for HLSL")
  96. endif()
  97. add_definitions(-DENABLE_OPT=0)
  98. endif()
  99. add_subdirectory(glslang)
  100. add_subdirectory(OGLCompilersDLL)
  101. if(ENABLE_GLSLANG_BINARIES)
  102. add_subdirectory(StandAlone)
  103. endif()
  104. add_subdirectory(SPIRV)
  105. if(ENABLE_HLSL)
  106. add_subdirectory(hlsl)
  107. endif(ENABLE_HLSL)
  108. add_subdirectory(gtests)