CMakeLists.txt 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. # Needed for CMAKE_DEPENDENT_OPTION macro
  11. include(CMakeDependentOption)
  12. option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
  13. set(LIB_TYPE STATIC)
  14. if(BUILD_SHARED_LIBS)
  15. set(LIB_TYPE SHARED)
  16. endif()
  17. option(SKIP_GLSLANG_INSTALL "Skip installation" ${SKIP_GLSLANG_INSTALL})
  18. if(NOT ${SKIP_GLSLANG_INSTALL})
  19. set(ENABLE_GLSLANG_INSTALL ON)
  20. endif()
  21. option(ENABLE_SPVREMAPPER "Enables building of SPVRemapper" ON)
  22. option(ENABLE_GLSLANG_BINARIES "Builds glslangValidator and spirv-remap" ON)
  23. option(ENABLE_GLSLANG_WEB "Reduces glslang to minumum needed for web use" OFF)
  24. option(ENABLE_EMSCRIPTEN_SINGLE_FILE "If using emscripten, enables SINGLE_FILE build" OFF)
  25. option(ENABLE_EMSCRIPTEN_ENVIRONMENT_NODE "If using emscripten, builds to run on Node instead of Web" OFF)
  26. CMAKE_DEPENDENT_OPTION(ENABLE_HLSL "Enables HLSL input support" ON "NOT ENABLE_GLSLANG_WEB" OFF)
  27. option(ENABLE_OPT "Enables spirv-opt capability if present" ON)
  28. if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
  29. set(CMAKE_INSTALL_PREFIX "install" CACHE STRING "..." FORCE)
  30. endif()
  31. option(USE_CCACHE "Use ccache" OFF)
  32. if(USE_CCACHE)
  33. find_program(CCACHE_FOUND ccache)
  34. if(CCACHE_FOUND)
  35. set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
  36. endif(CCACHE_FOUND)
  37. endif()
  38. # Precompiled header macro. Parameters are source file list and filename for pch cpp file.
  39. macro(glslang_pch SRCS PCHCPP)
  40. if(MSVC AND CMAKE_GENERATOR MATCHES "^Visual Studio")
  41. set(PCH_NAME "$(IntDir)\\pch.pch")
  42. # make source files use/depend on PCH_NAME
  43. set_source_files_properties(${${SRCS}} PROPERTIES COMPILE_FLAGS "/Yupch.h /FIpch.h /Fp${PCH_NAME} /Zm300" OBJECT_DEPENDS "${PCH_NAME}")
  44. # make PCHCPP file compile and generate PCH_NAME
  45. set_source_files_properties(${PCHCPP} PROPERTIES COMPILE_FLAGS "/Ycpch.h /Fp${PCH_NAME} /Zm300" OBJECT_OUTPUTS "${PCH_NAME}")
  46. list(APPEND ${SRCS} "${PCHCPP}")
  47. endif()
  48. endmacro(glslang_pch)
  49. project(glslang)
  50. # make testing optional
  51. include(CTest)
  52. if(ENABLE_HLSL)
  53. add_definitions(-DENABLE_HLSL)
  54. endif(ENABLE_HLSL)
  55. if(ENABLE_GLSLANG_WEB)
  56. add_definitions(-DGLSLANG_WEB)
  57. endif(ENABLE_GLSLANG_WEB)
  58. if(WIN32)
  59. set(CMAKE_DEBUG_POSTFIX "d")
  60. if(MSVC)
  61. include(ChooseMSVCCRT.cmake)
  62. endif(MSVC)
  63. add_definitions(-DGLSLANG_OSINCLUDE_WIN32)
  64. elseif(UNIX)
  65. add_definitions(-DGLSLANG_OSINCLUDE_UNIX)
  66. else(WIN32)
  67. message("unknown platform")
  68. endif(WIN32)
  69. if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
  70. add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs
  71. -Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions)
  72. add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
  73. add_compile_options(-fno-rtti)
  74. elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
  75. add_compile_options(-Wall -Wuninitialized -Wunused -Wunused-local-typedefs
  76. -Wunused-parameter -Wunused-value -Wunused-variable)
  77. add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
  78. add_compile_options(-fno-rtti)
  79. elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC")
  80. add_compile_options(/GR-) # Disable RTTI
  81. endif()
  82. if(ENABLE_GLSLANG_WEB)
  83. if(EMSCRIPTEN)
  84. add_compile_options(-Os -fno-exceptions)
  85. add_compile_options("SHELL: -s WASM=1")
  86. add_compile_options("SHELL: -s WASM_OBJECT_FILES=0")
  87. add_link_options(-Os)
  88. add_link_options("SHELL: -s FILESYSTEM=0")
  89. add_link_options("SHELL: --llvm-lto 1")
  90. add_link_options("SHELL: --closure 1")
  91. add_link_options("SHELL: -s ALLOW_MEMORY_GROWTH=1")
  92. add_link_options("SHELL: -s MODULARIZE=1")
  93. if(ENABLE_EMSCRIPTEN_SINGLE_FILE)
  94. add_link_options("SHELL: -s SINGLE_FILE=1")
  95. endif(ENABLE_EMSCRIPTEN_SINGLE_FILE)
  96. if(ENABLE_EMSCRIPTEN_ENVIRONMENT_NODE)
  97. add_link_options("SHELL: -s ENVIRONMENT=node")
  98. add_link_options("SHELL: -s BINARYEN_ASYNC_COMPILATION=0")
  99. else()
  100. add_link_options("SHELL: -s ENVIRONMENT=web,worker")
  101. add_link_options("SHELL: -s EXPORT_ES6=1")
  102. endif()
  103. else()
  104. if(MSVC)
  105. add_compile_options(/Os /GR-)
  106. else()
  107. add_compile_options(-Os -fno-exceptions)
  108. add_link_options(-Os)
  109. endif()
  110. endif(EMSCRIPTEN)
  111. endif(ENABLE_GLSLANG_WEB)
  112. # Request C++11
  113. if(${CMAKE_VERSION} VERSION_LESS 3.1)
  114. # CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD
  115. # remove this block once CMake >=3.1 has fixated in the ecosystem
  116. add_compile_options(-std=c++11)
  117. else()
  118. set(CMAKE_CXX_STANDARD 11)
  119. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  120. set(CMAKE_CXX_EXTENSIONS OFF)
  121. endif()
  122. function(glslang_set_link_args TARGET)
  123. # For MinGW compiles, statically link against the GCC and C++ runtimes.
  124. # This avoids the need to ship those runtimes as DLLs.
  125. if(WIN32 AND ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
  126. set_target_properties(${TARGET} PROPERTIES
  127. LINK_FLAGS "-static -static-libgcc -static-libstdc++")
  128. endif()
  129. endfunction(glslang_set_link_args)
  130. # CMake needs to find the right version of python, right from the beginning,
  131. # otherwise, it will find the wrong version and fail later
  132. if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/External)
  133. find_package(PythonInterp 3 REQUIRED)
  134. endif()
  135. # We depend on these for later projects, so they should come first.
  136. add_subdirectory(External)
  137. if(NOT TARGET SPIRV-Tools-opt)
  138. set(ENABLE_OPT OFF)
  139. endif()
  140. if(ENABLE_OPT)
  141. message(STATUS "optimizer enabled")
  142. add_definitions(-DENABLE_OPT=1)
  143. else()
  144. if(ENABLE_HLSL)
  145. message(STATUS "spirv-tools not linked - illegal SPIRV may be generated for HLSL")
  146. endif()
  147. add_definitions(-DENABLE_OPT=0)
  148. endif()
  149. add_subdirectory(glslang)
  150. add_subdirectory(OGLCompilersDLL)
  151. if(ENABLE_GLSLANG_BINARIES)
  152. add_subdirectory(StandAlone)
  153. endif()
  154. add_subdirectory(SPIRV)
  155. if(ENABLE_HLSL)
  156. add_subdirectory(hlsl)
  157. endif(ENABLE_HLSL)
  158. add_subdirectory(gtests)