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