# 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)
# 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()
if(ENABLE_CTEST)
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)
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()
if(BUILD_EXTERNAL AND IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/External)
- find_package(PythonInterp 3 REQUIRED)
+ find_host_package(PythonInterp 3 REQUIRED)
# We depend on these for later projects, so they should come first.
add_subdirectory(External)
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