CMakeLists.txt 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. # Enable compile commands database
  9. set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
  10. # Adhere to GNU filesystem layout conventions
  11. include(GNUInstallDirs)
  12. # Needed for CMAKE_DEPENDENT_OPTION macro
  13. include(CMakeDependentOption)
  14. option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
  15. option(BUILD_EXTERNAL "Build external dependencies in /External" ON)
  16. set(LIB_TYPE STATIC)
  17. if(BUILD_SHARED_LIBS)
  18. set(LIB_TYPE SHARED)
  19. endif()
  20. option(SKIP_GLSLANG_INSTALL "Skip installation" ${SKIP_GLSLANG_INSTALL})
  21. if(NOT ${SKIP_GLSLANG_INSTALL})
  22. set(ENABLE_GLSLANG_INSTALL ON)
  23. endif()
  24. option(ENABLE_SPVREMAPPER "Enables building of SPVRemapper" ON)
  25. option(ENABLE_GLSLANG_BINARIES "Builds glslangValidator and spirv-remap" ON)
  26. option(ENABLE_GLSLANG_JS
  27. "If using Emscripten, build glslang.js. Otherwise, builds a sample executable for binary-size testing." OFF)
  28. CMAKE_DEPENDENT_OPTION(ENABLE_GLSLANG_WEBMIN
  29. "Reduces glslang to minimum needed for web use"
  30. OFF "ENABLE_GLSLANG_JS"
  31. OFF)
  32. CMAKE_DEPENDENT_OPTION(ENABLE_GLSLANG_WEBMIN_DEVEL
  33. "For ENABLE_GLSLANG_WEBMIN builds, enables compilation error messages"
  34. OFF "ENABLE_GLSLANG_WEBMIN"
  35. OFF)
  36. CMAKE_DEPENDENT_OPTION(ENABLE_EMSCRIPTEN_SINGLE_FILE
  37. "If using Emscripten, enables SINGLE_FILE build"
  38. OFF "ENABLE_GLSLANG_JS AND EMSCRIPTEN"
  39. OFF)
  40. CMAKE_DEPENDENT_OPTION(ENABLE_EMSCRIPTEN_ENVIRONMENT_NODE
  41. "If using Emscripten, builds to run on Node instead of Web"
  42. OFF "ENABLE_GLSLANG_JS AND EMSCRIPTEN"
  43. OFF)
  44. CMAKE_DEPENDENT_OPTION(ENABLE_HLSL
  45. "Enables HLSL input support"
  46. ON "NOT ENABLE_GLSLANG_WEBMIN"
  47. OFF)
  48. option(ENABLE_RTTI "Enables RTTI" OFF)
  49. option(ENABLE_EXCEPTIONS "Enables Exceptions" OFF)
  50. option(ENABLE_OPT "Enables spirv-opt capability if present" ON)
  51. option(ENABLE_PCH "Enables Precompiled header" ON)
  52. option(ENABLE_CTEST "Enables testing" ON)
  53. if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
  54. set(CMAKE_INSTALL_PREFIX "install" CACHE STRING "..." FORCE)
  55. endif()
  56. option(USE_CCACHE "Use ccache" OFF)
  57. if(USE_CCACHE)
  58. find_program(CCACHE_FOUND ccache)
  59. if(CCACHE_FOUND)
  60. set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
  61. endif(CCACHE_FOUND)
  62. endif()
  63. # Precompiled header macro. Parameters are source file list and filename for pch cpp file.
  64. macro(glslang_pch SRCS PCHCPP)
  65. if(MSVC AND CMAKE_GENERATOR MATCHES "^Visual Studio" AND NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND ENABLE_PCH)
  66. set(PCH_NAME "$(IntDir)\\pch.pch")
  67. # make source files use/depend on PCH_NAME
  68. set_source_files_properties(${${SRCS}} PROPERTIES COMPILE_FLAGS "/Yupch.h /FIpch.h /Fp${PCH_NAME} /Zm300" OBJECT_DEPENDS "${PCH_NAME}")
  69. # make PCHCPP file compile and generate PCH_NAME
  70. set_source_files_properties(${PCHCPP} PROPERTIES COMPILE_FLAGS "/Ycpch.h /Fp${PCH_NAME} /Zm300" OBJECT_OUTPUTS "${PCH_NAME}")
  71. list(APPEND ${SRCS} "${PCHCPP}")
  72. endif()
  73. endmacro(glslang_pch)
  74. project(glslang)
  75. if(ENABLE_CTEST)
  76. include(CTest)
  77. endif()
  78. if(ENABLE_HLSL)
  79. add_definitions(-DENABLE_HLSL)
  80. endif(ENABLE_HLSL)
  81. if(ENABLE_GLSLANG_WEBMIN)
  82. add_definitions(-DGLSLANG_WEB)
  83. if(ENABLE_GLSLANG_WEBMIN_DEVEL)
  84. add_definitions(-DGLSLANG_WEB_DEVEL)
  85. endif(ENABLE_GLSLANG_WEBMIN_DEVEL)
  86. endif(ENABLE_GLSLANG_WEBMIN)
  87. if(WIN32)
  88. set(CMAKE_DEBUG_POSTFIX "d")
  89. if(MSVC)
  90. include(ChooseMSVCCRT.cmake)
  91. endif(MSVC)
  92. add_definitions(-DGLSLANG_OSINCLUDE_WIN32)
  93. elseif(UNIX)
  94. add_definitions(-DGLSLANG_OSINCLUDE_UNIX)
  95. else(WIN32)
  96. message("unknown platform")
  97. endif(WIN32)
  98. if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
  99. add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs
  100. -Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions)
  101. add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
  102. if(NOT ENABLE_RTTI)
  103. add_compile_options(-fno-rtti)
  104. endif()
  105. if(NOT ENABLE_EXCEPTIONS)
  106. add_compile_options(-fno-exceptions)
  107. endif()
  108. if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9.0.0")
  109. add_compile_options(-Werror=deprecated-copy)
  110. endif()
  111. elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND NOT MSVC)
  112. add_compile_options(-Wall -Wuninitialized -Wunused -Wunused-local-typedefs
  113. -Wunused-parameter -Wunused-value -Wunused-variable)
  114. add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
  115. if(NOT ENABLE_RTTI)
  116. add_compile_options(-fno-rtti)
  117. endif()
  118. if(NOT ENABLE_EXCEPTIONS)
  119. add_compile_options(-fno-exceptions)
  120. endif()
  121. elseif(MSVC)
  122. if(NOT ENABLE_RTTI)
  123. string(FIND "${CMAKE_CXX_FLAGS}" "/GR" MSVC_HAS_GR)
  124. if(MSVC_HAS_GR)
  125. string(REGEX REPLACE /GR /GR- CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
  126. else()
  127. add_compile_options(/GR-) # Disable RTTI
  128. endif()
  129. endif()
  130. if(ENABLE_EXCEPTIONS)
  131. add_compile_options(/EHsc) # Enable Exceptions
  132. endif()
  133. endif()
  134. if(ENABLE_GLSLANG_JS)
  135. if(MSVC)
  136. add_compile_options(/Os /GR-)
  137. else()
  138. add_compile_options(-Os -fno-rtti -fno-exceptions)
  139. if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND NOT MSVC)
  140. add_compile_options(-Wno-unused-parameter)
  141. add_compile_options(-Wno-unused-variable -Wno-unused-const-variable)
  142. endif()
  143. endif()
  144. endif(ENABLE_GLSLANG_JS)
  145. # Request C++11
  146. if(${CMAKE_VERSION} VERSION_LESS 3.1)
  147. # CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD
  148. # remove this block once CMake >=3.1 has fixated in the ecosystem
  149. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  150. else()
  151. set(CMAKE_CXX_STANDARD 11)
  152. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  153. set(CMAKE_CXX_EXTENSIONS OFF)
  154. endif()
  155. function(glslang_set_link_args TARGET)
  156. # For MinGW compiles, statically link against the GCC and C++ runtimes.
  157. # This avoids the need to ship those runtimes as DLLs.
  158. if(WIN32 AND ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
  159. set_target_properties(${TARGET} PROPERTIES
  160. LINK_FLAGS "-static -static-libgcc -static-libstdc++")
  161. endif()
  162. endfunction(glslang_set_link_args)
  163. # CMake needs to find the right version of python, right from the beginning,
  164. # otherwise, it will find the wrong version and fail later
  165. if(BUILD_EXTERNAL AND IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/External)
  166. find_package(PythonInterp 3 REQUIRED)
  167. # We depend on these for later projects, so they should come first.
  168. add_subdirectory(External)
  169. endif()
  170. if(NOT TARGET SPIRV-Tools-opt)
  171. set(ENABLE_OPT OFF)
  172. endif()
  173. if(ENABLE_OPT)
  174. message(STATUS "optimizer enabled")
  175. add_definitions(-DENABLE_OPT=1)
  176. else()
  177. if(ENABLE_HLSL)
  178. message(STATUS "spirv-tools not linked - illegal SPIRV may be generated for HLSL")
  179. endif()
  180. add_definitions(-DENABLE_OPT=0)
  181. endif()
  182. add_subdirectory(glslang)
  183. add_subdirectory(OGLCompilersDLL)
  184. if(ENABLE_GLSLANG_BINARIES)
  185. add_subdirectory(StandAlone)
  186. endif()
  187. add_subdirectory(SPIRV)
  188. if(ENABLE_HLSL)
  189. add_subdirectory(hlsl)
  190. endif(ENABLE_HLSL)
  191. if(ENABLE_CTEST)
  192. add_subdirectory(gtests)
  193. endif()
  194. if(ENABLE_CTEST AND BUILD_TESTING)
  195. # glslang-testsuite runs a bash script on Windows.
  196. # Make sure to use '-o igncr' flag to ignore carriage returns (\r).
  197. set(IGNORE_CR_FLAG "")
  198. if(WIN32)
  199. set(IGNORE_CR_FLAG -o igncr)
  200. endif()
  201. if (CMAKE_CONFIGURATION_TYPES)
  202. set(RESULTS_PATH ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>/localResults)
  203. set(VALIDATOR_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/$<CONFIGURATION>/glslangValidator)
  204. set(REMAP_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/$<CONFIGURATION>/spirv-remap)
  205. else(CMAKE_CONFIGURATION_TYPES)
  206. set(RESULTS_PATH ${CMAKE_CURRENT_BINARY_DIR}/localResults)
  207. set(VALIDATOR_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/glslangValidator)
  208. set(REMAP_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/spirv-remap)
  209. endif(CMAKE_CONFIGURATION_TYPES)
  210. add_test(NAME glslang-testsuite
  211. COMMAND bash ${IGNORE_CR_FLAG} runtests ${RESULTS_PATH} ${VALIDATOR_PATH} ${REMAP_PATH}
  212. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Test/)
  213. endif()