mirror of
https://github.com/KhronosGroup/glslang
synced 2024-11-08 11:30:06 +00:00
Modernise CMake
* Use `GNUInstallDirs` in order to respect GNU conventions. This is especially important for multi-arch/multi-lib setups. * Specify position independent mode building properly, without using the historic hack of adding `-fPIC` as a definition. This makes the build system more portable. * Only detect C++ (and not C) to slightly speed up configuring. * Specify C++11 mode using modern CMake idioms. * Fix some whitespace issues.
This commit is contained in:
parent
acce8dce1b
commit
5a5699bdbd
@ -1,6 +1,11 @@
|
||||
cmake_minimum_required(VERSION 2.8.11)
|
||||
# increase to 3.1 once all major distributions
|
||||
# include a version of CMake >= 3.1
|
||||
cmake_minimum_required(VERSION 2.8.12)
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
|
||||
# Adhere to GNU filesystem layout conventions
|
||||
include(GNUInstallDirs)
|
||||
|
||||
option(ENABLE_AMD_EXTENSIONS "Enables support of AMD-specific extensions" ON)
|
||||
option(ENABLE_GLSLANG_BINARIES "Builds glslangValidator and spirv-remap" ON)
|
||||
|
||||
@ -8,10 +13,6 @@ option(ENABLE_NV_EXTENSIONS "Enables support of Nvidia-specific extensions" ON)
|
||||
|
||||
option(ENABLE_HLSL "Enables HLSL input support" ON)
|
||||
|
||||
enable_testing()
|
||||
|
||||
set(CMAKE_INSTALL_PREFIX "install" CACHE STRING "prefix")
|
||||
|
||||
project(glslang)
|
||||
|
||||
if(ENABLE_AMD_EXTENSIONS)
|
||||
@ -33,33 +34,39 @@ if(WIN32)
|
||||
endif(MSVC)
|
||||
add_definitions(-DGLSLANG_OSINCLUDE_WIN32)
|
||||
elseif(UNIX)
|
||||
add_definitions(-fPIC)
|
||||
add_definitions(-DGLSLANG_OSINCLUDE_UNIX)
|
||||
else(WIN32)
|
||||
message("unknown platform")
|
||||
endif(WIN32)
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
add_definitions(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs
|
||||
-Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable)
|
||||
add_definitions(-Wno-reorder) # disable this from -Wall, since it happens all over.
|
||||
add_definitions(-std=c++11)
|
||||
if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
|
||||
add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs
|
||||
-Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable)
|
||||
add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
|
||||
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
||||
add_definitions(-Wall -Wuninitialized -Wunused -Wunused-local-typedefs
|
||||
-Wunused-parameter -Wunused-value -Wunused-variable)
|
||||
add_definitions(-Wno-reorder) # disable this from -Wall, since it happens all over.
|
||||
add_definitions(-std=c++11)
|
||||
add_compile_options(-Wall -Wuninitialized -Wunused -Wunused-local-typedefs
|
||||
-Wunused-parameter -Wunused-value -Wunused-variable)
|
||||
add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
|
||||
endif()
|
||||
|
||||
# Request C++11
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.1)
|
||||
# CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD
|
||||
# remove this block once CMake >=3.1 has fixated in the ecosystem
|
||||
add_compile_options(-std=c++11)
|
||||
else()
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
endif()
|
||||
|
||||
function(glslang_set_link_args TARGET)
|
||||
# For MinGW compiles, statically link against the GCC and C++ runtimes.
|
||||
# This avoids the need to ship those runtimes as DLLs.
|
||||
if(WIN32)
|
||||
if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
|
||||
set_target_properties(${TARGET} PROPERTIES
|
||||
LINK_FLAGS "-static -static-libgcc -static-libstdc++")
|
||||
endif()
|
||||
endif(WIN32)
|
||||
if(WIN32 AND ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
|
||||
set_target_properties(${TARGET} PROPERTIES
|
||||
LINK_FLAGS "-static -static-libgcc -static-libstdc++")
|
||||
endif()
|
||||
endfunction(glslang_set_link_args)
|
||||
|
||||
# We depend on these for later projects, so they should come first.
|
||||
@ -68,7 +75,7 @@ add_subdirectory(External)
|
||||
add_subdirectory(glslang)
|
||||
add_subdirectory(OGLCompilersDLL)
|
||||
if(ENABLE_GLSLANG_BINARIES)
|
||||
add_subdirectory(StandAlone)
|
||||
add_subdirectory(StandAlone)
|
||||
endif()
|
||||
add_subdirectory(SPIRV)
|
||||
if(ENABLE_HLSL)
|
||||
|
53
External/CMakeLists.txt
vendored
53
External/CMakeLists.txt
vendored
@ -2,33 +2,32 @@
|
||||
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS -w)
|
||||
|
||||
if (TARGET gmock)
|
||||
message(STATUS "Google Mock already configured - use it")
|
||||
message(STATUS "Google Mock already configured - use it")
|
||||
elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
|
||||
# We need to make sure Google Test does not mess up with the
|
||||
# global CRT settings on Windows.
|
||||
if(WIN32)
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
endif(WIN32)
|
||||
add_subdirectory(googletest)
|
||||
set(GTEST_TARGETS
|
||||
gtest
|
||||
gtest_main
|
||||
gmock
|
||||
gmock_main
|
||||
)
|
||||
foreach(target ${GTEST_TARGETS})
|
||||
set_property(TARGET ${target} PROPERTY FOLDER gtest)
|
||||
endforeach()
|
||||
mark_as_advanced(gmock_build_tests
|
||||
BUILD_GMOCK
|
||||
BUILD_GTEST
|
||||
BUILD_SHARED_LIBS
|
||||
gtest_build_samples
|
||||
gtest_build_tests
|
||||
gtest_disable_pthreads
|
||||
gtest_force_shared_crt
|
||||
gtest_hide_internal_symbols)
|
||||
# We need to make sure Google Test does not mess up with the
|
||||
# global CRT settings on Windows.
|
||||
if(WIN32)
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
endif(WIN32)
|
||||
add_subdirectory(googletest)
|
||||
set(GTEST_TARGETS
|
||||
gtest
|
||||
gtest_main
|
||||
gmock
|
||||
gmock_main)
|
||||
foreach(target ${GTEST_TARGETS})
|
||||
set_property(TARGET ${target} PROPERTY FOLDER gtest)
|
||||
endforeach()
|
||||
mark_as_advanced(gmock_build_tests
|
||||
BUILD_GMOCK
|
||||
BUILD_GTEST
|
||||
BUILD_SHARED_LIBS
|
||||
gtest_build_samples
|
||||
gtest_build_tests
|
||||
gtest_disable_pthreads
|
||||
gtest_force_shared_crt
|
||||
gtest_hide_internal_symbols)
|
||||
else()
|
||||
message(STATUS
|
||||
"Google Mock was not found - tests based on that will not build")
|
||||
message(STATUS
|
||||
"Google Mock was not found - tests based on that will not build")
|
||||
endif()
|
||||
|
@ -1,11 +1,11 @@
|
||||
set(SOURCES InitializeDll.cpp InitializeDll.h)
|
||||
|
||||
add_library(OGLCompiler STATIC ${SOURCES})
|
||||
set_property(TARGET OGLCompiler PROPERTY FOLDER glslang)
|
||||
set_property(TARGET OGLCompiler PROPERTY FOLDER glslang POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
if(WIN32)
|
||||
source_group("Source" FILES ${SOURCES})
|
||||
endif(WIN32)
|
||||
|
||||
install(TARGETS OGLCompiler
|
||||
ARCHIVE DESTINATION lib)
|
||||
install(TARGETS OGLCompiler
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
@ -40,11 +40,11 @@ if(ENABLE_NV_EXTENSIONS)
|
||||
endif(ENABLE_NV_EXTENSIONS)
|
||||
|
||||
add_library(SPIRV STATIC ${SOURCES} ${HEADERS})
|
||||
set_property(TARGET SPIRV PROPERTY FOLDER glslang)
|
||||
set_property(TARGET SPIRV PROPERTY FOLDER glslang POSITION_INDEPENDENT_CODE ON)
|
||||
target_link_libraries(SPIRV glslang)
|
||||
|
||||
add_library(SPVRemapper STATIC ${SPVREMAP_SOURCES} ${SPVREMAP_HEADERS})
|
||||
set_property(TARGET SPVRemapper PROPERTY FOLDER glslang)
|
||||
set_property(TARGET SPVRemapper PROPERTY FOLDER glslang POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
if(WIN32)
|
||||
source_group("Source" FILES ${SOURCES} ${HEADERS})
|
||||
@ -52,6 +52,6 @@ if(WIN32)
|
||||
endif(WIN32)
|
||||
|
||||
install(TARGETS SPIRV SPVRemapper
|
||||
ARCHIVE DESTINATION lib)
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
install(FILES ${HEADERS} ${SPVREMAP_HEADERS} DESTINATION include/SPIRV/)
|
||||
install(FILES ${HEADERS} ${SPVREMAP_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SPIRV/)
|
||||
|
@ -1,12 +1,10 @@
|
||||
add_library(glslang-default-resource-limits
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ResourceLimits.cpp
|
||||
)
|
||||
set_property(TARGET glslang-default-resource-limits PROPERTY FOLDER glslang)
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ResourceLimits.cpp)
|
||||
set_property(TARGET glslang-default-resource-limits PROPERTY FOLDER glslang POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
target_include_directories(glslang-default-resource-limits
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
PUBLIC ${PROJECT_SOURCE_DIR}
|
||||
)
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
PUBLIC ${PROJECT_SOURCE_DIR})
|
||||
|
||||
set(SOURCES StandAlone.cpp)
|
||||
set(REMAPPER_SOURCES spirv-remap.cpp)
|
||||
@ -41,7 +39,7 @@ if(WIN32)
|
||||
endif(WIN32)
|
||||
|
||||
install(TARGETS glslangValidator
|
||||
RUNTIME DESTINATION bin)
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
install(TARGETS spirv-remap
|
||||
RUNTIME DESTINATION bin)
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
@ -81,10 +81,10 @@ set(HEADERS
|
||||
# set(BISON_GLSLParser_OUTPUT_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/MachineIndependent/glslang_tab.cpp)
|
||||
|
||||
add_library(glslang STATIC ${BISON_GLSLParser_OUTPUT_SOURCE} ${SOURCES} ${HEADERS})
|
||||
set_property(TARGET glslang PROPERTY FOLDER glslang)
|
||||
set_property(TARGET glslang PROPERTY FOLDER glslang POSITION_INDEPENDENT_CODE ON)
|
||||
target_link_libraries(glslang OGLCompiler OSDependent)
|
||||
if(ENABLE_HLSL)
|
||||
target_link_libraries(glslang HLSL)
|
||||
target_link_libraries(glslang HLSL)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
@ -95,10 +95,10 @@ if(WIN32)
|
||||
source_group("MachineIndependent\\Preprocessor" REGULAR_EXPRESSION "MachineIndependent/preprocessor/*")
|
||||
endif(WIN32)
|
||||
|
||||
install(TARGETS glslang
|
||||
ARCHIVE DESTINATION lib)
|
||||
install(TARGETS glslang
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
foreach(file ${HEADERS})
|
||||
get_filename_component(dir ${file} DIRECTORY)
|
||||
install(FILES ${file} DESTINATION include/glslang/${dir})
|
||||
install(FILES ${file} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/glslang/${dir})
|
||||
endforeach()
|
||||
|
@ -1,5 +1,5 @@
|
||||
add_library(OSDependent STATIC ossource.cpp ../osinclude.h)
|
||||
set_property(TARGET OSDependent PROPERTY FOLDER glslang)
|
||||
set_property(TARGET OSDependent PROPERTY FOLDER glslang POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
install(TARGETS OSDependent
|
||||
ARCHIVE DESTINATION lib)
|
||||
install(TARGETS OSDependent
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
@ -1,17 +1,17 @@
|
||||
set(SOURCES ossource.cpp ../osinclude.h)
|
||||
|
||||
add_library(OSDependent STATIC ${SOURCES})
|
||||
set_property(TARGET OSDependent PROPERTY FOLDER glslang)
|
||||
set_property(TARGET OSDependent PROPERTY FOLDER glslang POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
# MinGW GCC complains about function pointer casts to void*.
|
||||
# Turn that off with -fpermissive.
|
||||
if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
|
||||
target_compile_options(OSDependent PRIVATE -fpermissive)
|
||||
target_compile_options(OSDependent PRIVATE -fpermissive)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
source_group("Source" FILES ${SOURCES})
|
||||
endif(WIN32)
|
||||
|
||||
install(TARGETS OSDependent
|
||||
ARCHIVE DESTINATION lib)
|
||||
install(TARGETS OSDependent
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
@ -1,55 +1,55 @@
|
||||
if (TARGET gmock)
|
||||
message(STATUS "Google Mock found - building tests")
|
||||
message(STATUS "Google Mock found - building tests")
|
||||
|
||||
set(TEST_SOURCES
|
||||
# Framework related source files
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Initializer.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Settings.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Settings.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TestFixture.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TestFixture.h
|
||||
set(TEST_SOURCES
|
||||
# Framework related source files
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Initializer.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Settings.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Settings.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TestFixture.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TestFixture.h
|
||||
|
||||
# Test related source files
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/AST.FromFile.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BuiltInResource.FromFile.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Config.FromFile.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/HexFloat.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Hlsl.FromFile.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Link.FromFile.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Link.FromFile.Vk.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Pp.FromFile.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Spv.FromFile.cpp
|
||||
# -- Remapper tests
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Remap.FromFile.cpp
|
||||
)
|
||||
# Test related source files
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/AST.FromFile.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BuiltInResource.FromFile.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Config.FromFile.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/HexFloat.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Hlsl.FromFile.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Link.FromFile.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Link.FromFile.Vk.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Pp.FromFile.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Spv.FromFile.cpp
|
||||
|
||||
add_executable(glslangtests ${TEST_SOURCES})
|
||||
set_property(TARGET glslangtests PROPERTY FOLDER tests)
|
||||
glslang_set_link_args(glslangtests)
|
||||
install(TARGETS glslangtests
|
||||
RUNTIME DESTINATION bin)
|
||||
# -- Remapper tests
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Remap.FromFile.cpp)
|
||||
|
||||
set(GLSLANG_TEST_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../Test")
|
||||
# Supply a default test root directory, so that manual testing
|
||||
# doesn't have to specify the --test-root option in the normal
|
||||
# case that you want to use the tests from the same source tree.
|
||||
target_compile_definitions(glslangtests
|
||||
PRIVATE GLSLANG_TEST_DIRECTORY="${GLSLANG_TEST_DIRECTORY}")
|
||||
target_include_directories(glslangtests PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${PROJECT_SOURCE_DIR}
|
||||
${gmock_SOURCE_DIR}/include
|
||||
${gtest_SOURCE_DIR}/include)
|
||||
add_executable(glslangtests ${TEST_SOURCES})
|
||||
set_property(TARGET glslangtests PROPERTY FOLDER tests)
|
||||
glslang_set_link_args(glslangtests)
|
||||
install(TARGETS glslangtests
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
set(LIBRARIES
|
||||
SPVRemapper glslang OSDependent OGLCompiler glslang
|
||||
SPIRV glslang-default-resource-limits)
|
||||
if(ENABLE_HLSL)
|
||||
set(LIBRARIES ${LIBRARIES} HLSL)
|
||||
endif(ENABLE_HLSL)
|
||||
target_link_libraries(glslangtests PRIVATE ${LIBRARIES} gmock)
|
||||
set(GLSLANG_TEST_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../Test")
|
||||
# Supply a default test root directory, so that manual testing
|
||||
# doesn't have to specify the --test-root option in the normal
|
||||
# case that you want to use the tests from the same source tree.
|
||||
target_compile_definitions(glslangtests
|
||||
PRIVATE GLSLANG_TEST_DIRECTORY="${GLSLANG_TEST_DIRECTORY}")
|
||||
target_include_directories(glslangtests PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${PROJECT_SOURCE_DIR}
|
||||
${gmock_SOURCE_DIR}/include
|
||||
${gtest_SOURCE_DIR}/include)
|
||||
|
||||
add_test(NAME glslang-gtests
|
||||
COMMAND glslangtests --test-root "${GLSLANG_TEST_DIRECTORY}")
|
||||
set(LIBRARIES
|
||||
SPVRemapper glslang OSDependent OGLCompiler glslang
|
||||
SPIRV glslang-default-resource-limits)
|
||||
if(ENABLE_HLSL)
|
||||
set(LIBRARIES ${LIBRARIES} HLSL)
|
||||
endif(ENABLE_HLSL)
|
||||
target_link_libraries(glslangtests PRIVATE ${LIBRARIES} gmock)
|
||||
|
||||
add_test(NAME glslang-gtests
|
||||
COMMAND glslangtests --test-root "${GLSLANG_TEST_DIRECTORY}")
|
||||
endif()
|
||||
|
@ -7,7 +7,7 @@ set(SOURCES
|
||||
hlslGrammar.cpp
|
||||
hlslParseables.cpp)
|
||||
|
||||
set(HEADERS
|
||||
set(HEADERS
|
||||
hlslAttributes.h
|
||||
hlslParseHelper.h
|
||||
hlslTokens.h
|
||||
@ -18,11 +18,11 @@ set(SOURCES
|
||||
hlslParseables.h)
|
||||
|
||||
add_library(HLSL STATIC ${SOURCES} ${HEADERS})
|
||||
set_property(TARGET HLSL PROPERTY FOLDER hlsl)
|
||||
set_property(TARGET HLSL PROPERTY FOLDER hlsl POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
if(WIN32)
|
||||
source_group("Source" FILES ${SOURCES} ${HEADERS})
|
||||
endif(WIN32)
|
||||
|
||||
install(TARGETS HLSL
|
||||
ARCHIVE DESTINATION lib)
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
Loading…
Reference in New Issue
Block a user