CMakeLists.txt 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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_OPT "Enables spirv-opt capability if present" ON)
  50. option(ENABLE_PCH "Enables Precompiled header" ON)
  51. option(ENABLE_CTEST "Enables testing" ON)
  52. if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
  53. set(CMAKE_INSTALL_PREFIX "install" CACHE STRING "..." FORCE)
  54. endif()
  55. option(USE_CCACHE "Use ccache" OFF)
  56. if(USE_CCACHE)
  57. find_program(CCACHE_FOUND ccache)
  58. if(CCACHE_FOUND)
  59. set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
  60. endif(CCACHE_FOUND)
  61. endif()
  62. # Precompiled header macro. Parameters are source file list and filename for pch cpp file.
  63. macro(glslang_pch SRCS PCHCPP)
  64. if(MSVC AND CMAKE_GENERATOR MATCHES "^Visual Studio" AND NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND ENABLE_PCH)
  65. set(PCH_NAME "$(IntDir)\\pch.pch")
  66. # make source files use/depend on PCH_NAME
  67. set_source_files_properties(${${SRCS}} PROPERTIES COMPILE_FLAGS "/Yupch.h /FIpch.h /Fp${PCH_NAME} /Zm300" OBJECT_DEPENDS "${PCH_NAME}")
  68. # make PCHCPP file compile and generate PCH_NAME
  69. set_source_files_properties(${PCHCPP} PROPERTIES COMPILE_FLAGS "/Ycpch.h /Fp${PCH_NAME} /Zm300" OBJECT_OUTPUTS "${PCH_NAME}")
  70. list(APPEND ${SRCS} "${PCHCPP}")
  71. endif()
  72. endmacro(glslang_pch)
  73. project(glslang)
  74. if(ENABLE_CTEST)
  75. include(CTest)
  76. endif()
  77. if(ENABLE_HLSL)
  78. add_definitions(-DENABLE_HLSL)
  79. endif(ENABLE_HLSL)
  80. if(ENABLE_GLSLANG_WEBMIN)
  81. add_definitions(-DGLSLANG_WEB)
  82. if(ENABLE_GLSLANG_WEBMIN_DEVEL)
  83. add_definitions(-DGLSLANG_WEB_DEVEL)
  84. endif(ENABLE_GLSLANG_WEBMIN_DEVEL)
  85. endif(ENABLE_GLSLANG_WEBMIN)
  86. if(WIN32)
  87. set(CMAKE_DEBUG_POSTFIX "d")
  88. if(MSVC)
  89. include(ChooseMSVCCRT.cmake)
  90. endif(MSVC)
  91. add_definitions(-DGLSLANG_OSINCLUDE_WIN32)
  92. elseif(UNIX)
  93. add_definitions(-DGLSLANG_OSINCLUDE_UNIX)
  94. else(WIN32)
  95. message("unknown platform")
  96. endif(WIN32)
  97. if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
  98. add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs
  99. -Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions)
  100. add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
  101. if(NOT ENABLE_RTTI)
  102. add_compile_options(-fno-rtti)
  103. endif()
  104. if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9.0.0")
  105. add_compile_options(-Werror=deprecated-copy)
  106. endif()
  107. elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND NOT MSVC)
  108. add_compile_options(-Wall -Wuninitialized -Wunused -Wunused-local-typedefs
  109. -Wunused-parameter -Wunused-value -Wunused-variable)
  110. add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
  111. if(NOT ENABLE_RTTI)
  112. add_compile_options(-fno-rtti)
  113. endif()
  114. elseif(MSVC)
  115. if(NOT ENABLE_RTTI)
  116. add_compile_options(/GR-) # Disable RTTI
  117. endif()
  118. endif()
  119. if(ENABLE_GLSLANG_JS)
  120. if(MSVC)
  121. add_compile_options(/Os /GR-)
  122. else()
  123. add_compile_options(-Os -fno-exceptions)
  124. if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND NOT MSVC)
  125. add_compile_options(-Wno-unused-parameter)
  126. add_compile_options(-Wno-unused-variable -Wno-unused-const-variable)
  127. endif()
  128. endif()
  129. endif(ENABLE_GLSLANG_JS)
  130. # Request C++11
  131. if(${CMAKE_VERSION} VERSION_LESS 3.1)
  132. # CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD
  133. # remove this block once CMake >=3.1 has fixated in the ecosystem
  134. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  135. else()
  136. set(CMAKE_CXX_STANDARD 11)
  137. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  138. set(CMAKE_CXX_EXTENSIONS OFF)
  139. endif()
  140. function(glslang_set_link_args TARGET)
  141. # For MinGW compiles, statically link against the GCC and C++ runtimes.
  142. # This avoids the need to ship those runtimes as DLLs.
  143. if(WIN32 AND ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
  144. set_target_properties(${TARGET} PROPERTIES
  145. LINK_FLAGS "-static -static-libgcc -static-libstdc++")
  146. endif()
  147. endfunction(glslang_set_link_args)
  148. # CMake needs to find the right version of python, right from the beginning,
  149. # otherwise, it will find the wrong version and fail later
  150. if(BUILD_EXTERNAL AND IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/External)
  151. find_package(PythonInterp 3 REQUIRED)
  152. # We depend on these for later projects, so they should come first.
  153. add_subdirectory(External)
  154. endif()
  155. if(NOT TARGET SPIRV-Tools-opt)
  156. set(ENABLE_OPT OFF)
  157. endif()
  158. if(ENABLE_OPT)
  159. message(STATUS "optimizer enabled")
  160. add_definitions(-DENABLE_OPT=1)
  161. else()
  162. if(ENABLE_HLSL)
  163. message(STATUS "spirv-tools not linked - illegal SPIRV may be generated for HLSL")
  164. endif()
  165. add_definitions(-DENABLE_OPT=0)
  166. endif()
  167. add_subdirectory(glslang)
  168. add_subdirectory(OGLCompilersDLL)
  169. if(ENABLE_GLSLANG_BINARIES)
  170. add_subdirectory(StandAlone)
  171. endif()
  172. add_subdirectory(SPIRV)
  173. if(ENABLE_HLSL)
  174. add_subdirectory(hlsl)
  175. endif(ENABLE_HLSL)
  176. if(ENABLE_CTEST)
  177. add_subdirectory(gtests)
  178. endif()
  179. if(BUILD_TESTING)
  180. # glslang-testsuite runs a bash script on Windows.
  181. # Make sure to use '-o igncr' flag to ignore carriage returns (\r).
  182. set(IGNORE_CR_FLAG "")
  183. if(WIN32)
  184. set(IGNORE_CR_FLAG -o igncr)
  185. endif()
  186. if (CMAKE_CONFIGURATION_TYPES)
  187. set(RESULTS_PATH ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>/localResults)
  188. set(VALIDATOR_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/$<CONFIGURATION>/glslangValidator)
  189. set(REMAP_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/$<CONFIGURATION>/spirv-remap)
  190. else(CMAKE_CONFIGURATION_TYPES)
  191. set(RESULTS_PATH ${CMAKE_CURRENT_BINARY_DIR}/localResults)
  192. set(VALIDATOR_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/glslangValidator)
  193. set(REMAP_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/spirv-remap)
  194. endif(CMAKE_CONFIGURATION_TYPES)
  195. add_test(NAME glslang-testsuite
  196. COMMAND bash ${IGNORE_CR_FLAG} runtests ${RESULTS_PATH} ${VALIDATOR_PATH} ${REMAP_PATH}
  197. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Test/)
  198. endif(BUILD_TESTING)