# 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)
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()
-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
-find_package(PythonInterp 3 REQUIRED)
+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_PY "${CMAKE_CURRENT_SOURCE_DIR}/build_info.py")
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")
-# Command to build the build_info.h file
-add_custom_command(
- OUTPUT ${GLSLANG_BUILD_INFO_H}
- COMMAND ${PYTHON_EXECUTABLE} "${GLSLANG_BUILD_INFO_PY}"
- ${CMAKE_CURRENT_SOURCE_DIR}
- "-i" ${GLSLANG_BUILD_INFO_H_TMPL}
- "-o" ${GLSLANG_BUILD_INFO_H}
- DEPENDS ${GLSLANG_BUILD_INFO_PY}
- ${GLSLANG_CHANGES_FILE}
- ${GLSLANG_BUILD_INFO_H_TMPL}
- COMMENT "Generating ${GLSLANG_BUILD_INFO_H}")
-
-# Target to build the build_info.h file
-add_custom_target(glslang-build-info DEPENDS ${GLSLANG_BUILD_INFO_H})
-
-# Populate the CMake GLSLANG_VERSION* variables with the build version
-# information.
-execute_process(
- COMMAND ${PYTHON_EXECUTABLE} "${GLSLANG_BUILD_INFO_PY}"
- ${CMAKE_CURRENT_SOURCE_DIR} "<major>.<minor>.<patch><-flavor>;<major>;<minor>;<patch>;<flavor>"
- OUTPUT_VARIABLE "GLSLANG_VERSIONS"
- OUTPUT_STRIP_TRAILING_WHITESPACE)
-list(GET "GLSLANG_VERSIONS" 0 "GLSLANG_VERSION")
-list(GET "GLSLANG_VERSIONS" 1 "GLSLANG_VERSION_MAJOR")
-list(GET "GLSLANG_VERSIONS" 2 "GLSLANG_VERSION_MINOR")
-list(GET "GLSLANG_VERSIONS" 3 "GLSLANG_VERSION_PATCH")
-list(GET "GLSLANG_VERSIONS" 4 "GLSLANG_VERSION_FLAVOR")
-configure_file(${GLSLANG_CHANGES_FILE} "${CMAKE_CURRENT_BINARY_DIR}/CHANGES.md") # Required to re-run cmake on version change
+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}>)
- add_dependencies(${target} glslang-build-info)
endfunction()
# glslang_only_export_explicit_symbols() makes the symbol visibility hidden by
# 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")
+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()
- message(NOTICE "Your CMake version is ${CMAKE_VERSION}. Update to at least 3.16 to enable precompiled headers to speed up incremental builds")
+ 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()
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