# increase to 3.1 once all major distributions
# include a version of CMake >= 3.1
-cmake_minimum_required(VERSION 2.8.12)
+cmake_minimum_required(VERSION 3.14.0)
if (POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif()
+if(POLICY CMP0054)
+ cmake_policy(SET CMP0054 NEW)
+endif()
+
+project(glslang LANGUAGES CXX)
+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Enable compile commands database
# Adhere to GNU filesystem layout conventions
include(GNUInstallDirs)
+include(CMakePackageConfigHelpers)
# Needed for CMAKE_DEPENDENT_OPTION macro
include(CMakeDependentOption)
set(LIB_TYPE SHARED)
endif()
+if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
+ # This logic inside SPIRV-Tools, which can upset build target dependencies
+ # if changed after targets are already defined. To prevent these issues,
+ # ensure CMAKE_BUILD_TYPE is assigned early and at the glslang root scope.
+ message(STATUS "No build type selected, default to Debug")
+ set(CMAKE_BUILD_TYPE "Debug")
+endif()
+
option(SKIP_GLSLANG_INSTALL "Skip installation" ${SKIP_GLSLANG_INSTALL})
if(NOT ${SKIP_GLSLANG_INSTALL})
set(ENABLE_GLSLANG_INSTALL ON)
option(ENABLE_RTTI "Enables RTTI" OFF)
option(ENABLE_EXCEPTIONS "Enables Exceptions" OFF)
option(ENABLE_OPT "Enables spirv-opt capability if present" ON)
-option(ENABLE_PCH "Enables Precompiled header" ON)
+
+if(MINGW OR (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU"))
+ # Workaround for CMake behavior on Mac OS with gcc, cmake generates -Xarch_* arguments
+ # which gcc rejects
+ option(ENABLE_PCH "Enables Precompiled header" OFF)
+else()
+ option(ENABLE_PCH "Enables Precompiled header" ON)
+endif()
option(ENABLE_CTEST "Enables testing" ON)
-if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
+if(ENABLE_GLSLANG_INSTALL AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
set(CMAKE_INSTALL_PREFIX "install" CACHE STRING "..." FORCE)
endif()
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
- endif(CCACHE_FOUND)
+ endif()
endif()
-# Precompiled header macro. Parameters are source file list and filename for pch cpp file.
-macro(glslang_pch SRCS PCHCPP)
- if(MSVC AND CMAKE_GENERATOR MATCHES "^Visual Studio" AND NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND ENABLE_PCH)
- set(PCH_NAME "$(IntDir)\\pch.pch")
- # make source files use/depend on PCH_NAME
- set_source_files_properties(${${SRCS}} PROPERTIES COMPILE_FLAGS "/Yupch.h /FIpch.h /Fp${PCH_NAME} /Zm300" OBJECT_DEPENDS "${PCH_NAME}")
- # make PCHCPP file compile and generate PCH_NAME
- set_source_files_properties(${PCHCPP} PROPERTIES COMPILE_FLAGS "/Ycpch.h /Fp${PCH_NAME} /Zm300" OBJECT_OUTPUTS "${PCH_NAME}")
- list(APPEND ${SRCS} "${PCHCPP}")
- endif()
-endmacro(glslang_pch)
-
-project(glslang)
-
if(ENABLE_CTEST)
include(CTest)
endif()
if(ENABLE_HLSL)
add_definitions(-DENABLE_HLSL)
-endif(ENABLE_HLSL)
+endif()
if(ENABLE_GLSLANG_WEBMIN)
add_definitions(-DGLSLANG_WEB)
if(ENABLE_GLSLANG_WEBMIN_DEVEL)
add_definitions(-DGLSLANG_WEB_DEVEL)
- endif(ENABLE_GLSLANG_WEBMIN_DEVEL)
-endif(ENABLE_GLSLANG_WEBMIN)
+ endif()
+endif()
if(WIN32)
set(CMAKE_DEBUG_POSTFIX "d")
- if(MSVC)
+ option(OVERRIDE_MSVCCRT "Overrides runtime of MSVC " ON)
+ if(MSVC AND OVERRIDE_MSVCCRT)
include(ChooseMSVCCRT.cmake)
- endif(MSVC)
+ endif()
add_definitions(-DGLSLANG_OSINCLUDE_WIN32)
elseif(UNIX)
add_definitions(-DGLSLANG_OSINCLUDE_UNIX)
-else(WIN32)
+else()
message("unknown platform")
-endif(WIN32)
+endif()
if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs
add_compile_options(-Werror=deprecated-copy)
endif()
- if(NOT CMAKE_VERSION VERSION_LESS "3.13")
+ if(NOT CMAKE_VERSION VERSION_LESS "3.13" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
# Error if there's symbols that are not found at link time.
# add_link_options() was added in CMake 3.13 - if using an earlier
# version don't set this - it should be caught by presubmits anyway.
# Error if there's symbols that are not found at link time.
# add_link_options() was added in CMake 3.13 - if using an earlier
# version don't set this - it should be caught by presubmits anyway.
- add_link_options("-Wl,-undefined,error")
+ if (WIN32)
+ add_link_options("-Wl,--no-undefined")
+ else()
+ add_link_options("-Wl,-undefined,error")
+ endif()
endif()
elseif(MSVC)
if(NOT ENABLE_RTTI)
string(FIND "${CMAKE_CXX_FLAGS}" "/GR" MSVC_HAS_GR)
if(MSVC_HAS_GR)
- string(REGEX REPLACE /GR /GR- CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
+ string(REGEX REPLACE "/GR" "/GR-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
add_compile_options(/GR-) # Disable RTTI
endif()
endif()
if(ENABLE_EXCEPTIONS)
add_compile_options(/EHsc) # Enable Exceptions
+ else()
+ string(REGEX REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # Try to remove default /EHsc cxx_flag
+ add_compile_options(/D_HAS_EXCEPTIONS=0)
endif()
endif()
add_compile_options(-Wno-unused-variable -Wno-unused-const-variable)
endif()
endif()
-endif(ENABLE_GLSLANG_JS)
+endif()
# Request C++11
if(${CMAKE_VERSION} VERSION_LESS 3.1)
endif()
endfunction(glslang_set_link_args)
-# CMake needs to find the right version of python, right from the beginning,
-# otherwise, it will find the wrong version and fail later
-if(BUILD_EXTERNAL AND IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/External)
- find_package(PythonInterp 3 REQUIRED)
-
- # We depend on these for later projects, so they should come first.
- add_subdirectory(External)
+if(NOT COMMAND find_host_package)
+ macro(find_host_package)
+ find_package(${ARGN})
+ endmacro()
endif()
+# Root directory for build-time generated include files
+set(GLSLANG_GENERATED_INCLUDEDIR "${CMAKE_BINARY_DIR}/include")
+
+################################################################################
+# Build version information generation
+################################################################################
+include(parse_version.cmake)
+set(GLSLANG_CHANGES_FILE "${CMAKE_CURRENT_SOURCE_DIR}/CHANGES.md")
+set(GLSLANG_BUILD_INFO_H_TMPL "${CMAKE_CURRENT_SOURCE_DIR}/build_info.h.tmpl")
+set(GLSLANG_BUILD_INFO_H "${GLSLANG_GENERATED_INCLUDEDIR}/glslang/build_info.h")
+
+parse_version(${GLSLANG_CHANGES_FILE} GLSLANG)
+
+function(configurate_version)
+ set(major ${GLSLANG_VERSION_MAJOR})
+ set(minor ${GLSLANG_VERSION_MINOR})
+ set(patch ${GLSLANG_VERSION_PATCH})
+ set(flavor ${GLSLANG_VERSION_FLAVOR})
+ configure_file(${GLSLANG_BUILD_INFO_H_TMPL} ${GLSLANG_BUILD_INFO_H} @ONLY)
+endfunction()
+
+configurate_version()
+
+# glslang_add_build_info_dependency() adds the glslang-build-info dependency and
+# generated include directories to target.
+function(glslang_add_build_info_dependency target)
+ target_include_directories(${target} PUBLIC $<BUILD_INTERFACE:${GLSLANG_GENERATED_INCLUDEDIR}>)
+endfunction()
+
# glslang_only_export_explicit_symbols() makes the symbol visibility hidden by
# default for <target> when building shared libraries, and sets the
# GLSLANG_IS_SHARED_LIBRARY define, and GLSLANG_EXPORTING to 1 when specifically
endif()
endfunction()
+# glslang_pch() adds precompiled header rules to <target> for the pre-compiled
+# header file <pch>. As target_precompile_headers() was added in CMake 3.16,
+# this is a no-op if called on earlier versions of CMake.
+if(NOT CMAKE_VERSION VERSION_LESS "3.16" AND ENABLE_PCH)
+ function(glslang_pch target pch)
+ target_precompile_headers(${target} PRIVATE ${pch})
+ endfunction()
+else()
+ function(glslang_pch target pch)
+ endfunction()
+ if(ENABLE_PCH)
+ message("Your CMake version is ${CMAKE_VERSION}. Update to at least 3.16 to enable precompiled headers to speed up incremental builds")
+ endif()
+endif()
+
+if(BUILD_EXTERNAL AND IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/External)
+ find_host_package(PythonInterp 3 REQUIRED)
+
+ # We depend on these for later projects, so they should come first.
+ add_subdirectory(External)
+endif()
+
if(NOT TARGET SPIRV-Tools-opt)
set(ENABLE_OPT OFF)
endif()
add_subdirectory(SPIRV)
if(ENABLE_HLSL)
add_subdirectory(hlsl)
-endif(ENABLE_HLSL)
+endif()
if(ENABLE_CTEST)
add_subdirectory(gtests)
endif()
set(RESULTS_PATH ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>/localResults)
set(VALIDATOR_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/$<CONFIGURATION>/glslangValidator)
set(REMAP_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/$<CONFIGURATION>/spirv-remap)
- else(CMAKE_CONFIGURATION_TYPES)
+ else()
set(RESULTS_PATH ${CMAKE_CURRENT_BINARY_DIR}/localResults)
set(VALIDATOR_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/glslangValidator)
set(REMAP_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/spirv-remap)
- endif(CMAKE_CONFIGURATION_TYPES)
+ endif()
add_test(NAME glslang-testsuite
COMMAND bash ${IGNORE_CR_FLAG} runtests ${RESULTS_PATH} ${VALIDATOR_PATH} ${REMAP_PATH}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Test/)
endif()
+
+if(ENABLE_GLSLANG_INSTALL)
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/glslang-config.cmake.in" [=[
+ @PACKAGE_INIT@
+ include("@PACKAGE_PATH_EXPORT_TARGETS@")
+ ]=])
+
+ set(PATH_EXPORT_TARGETS "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/glslang-targets.cmake")
+ configure_package_config_file(
+ "${CMAKE_CURRENT_BINARY_DIR}/glslang-config.cmake.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/glslang-config.cmake"
+ PATH_VARS
+ PATH_EXPORT_TARGETS
+ INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
+ )
+
+ write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/glslang-config-version.cmake"
+ VERSION ${GLSLANG_VERSION}
+ COMPATIBILITY SameMajorVersion
+ )
+
+ install(
+ EXPORT glslang-targets
+ NAMESPACE "glslang::"
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
+ )
+
+ install(
+ FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/glslang-config.cmake"
+ "${CMAKE_CURRENT_BINARY_DIR}/glslang-config-version.cmake"
+ DESTINATION
+ "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
+ )
+endif()
\ No newline at end of file