<commit_before># Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_STANDARD 11)
project(SPIRV-Cross LANGUAGES CXX C)
enable_testing()

option(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS "Instead of throwing exceptions assert" OFF)
option(SPIRV_CROSS_SHARED "Build the C API as a single shared library." OFF)
option(SPIRV_CROSS_STATIC "Build the C and C++ API as static libraries." ON)
option(SPIRV_CROSS_CLI "Build the CLI binary. Requires SPIRV_CROSS_STATIC." ON)
option(SPIRV_CROSS_ENABLE_TESTS "Enable SPIRV-Cross tests." ON)

option(SPIRV_CROSS_ENABLE_GLSL "Enable GLSL support." ON)
option(SPIRV_CROSS_ENABLE_HLSL "Enable HLSL target support." ON)
option(SPIRV_CROSS_ENABLE_MSL "Enable MSL target support." ON)
option(SPIRV_CROSS_ENABLE_CPP "Enable C++ target support." ON)
option(SPIRV_CROSS_ENABLE_REFLECT "Enable JSON reflection target support." ON)
option(SPIRV_CROSS_ENABLE_C_API "Enable C API wrapper support in static library." ON)
option(SPIRV_CROSS_ENABLE_UTIL "Enable util module support." ON)

option(SPIRV_CROSS_SANITIZE_ADDRESS "Sanitize address" OFF)
option(SPIRV_CROSS_SANITIZE_MEMORY "Sanitize memory" OFF)
option(SPIRV_CROSS_SANITIZE_THREADS "Sanitize threads" OFF)
option(SPIRV_CROSS_SANITIZE_UNDEFINED "Sanitize undefined" OFF)

option(SPIRV_CROSS_NAMESPACE_OVERRIDE "" "Override the namespace used in the C++ API.")
option(SPIRV_CROSS_FORCE_STL_TYPES "Force use of STL types instead of STL replacements in certain places. Might reduce performance." OFF)

option(SPIRV_CROSS_SKIP_INSTALL "Skips installation targets." OFF)

option(SPIRV_CROSS_WERROR "Fail build on warnings." OFF)
option(SPIRV_CROSS_MISC_WARNINGS "Misc warnings useful for Travis runs." OFF)

if(${CMAKE_GENERATOR} MATCHES "Makefile")
	if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
		message(FATAL_ERROR "Build out of tree to avoid overwriting Makefile")
	endif()
endif()

set(spirv-compiler-options "")
set(spirv-compiler-defines "")
set(spirv-cross-link-flags "")

message(STATUS "Finding Git version for SPIRV-Cross.")
set(spirv-cross-build-version "unknown")
find_package(Git)
if (GIT_FOUND)
	execute_process(
		COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
		OUTPUT_VARIABLE spirv-cross-build-version
		ERROR_QUIET
		OUTPUT_STRIP_TRAILING_WHITESPACE
		)
	message(STATUS "Git hash: ${spirv-cross-build-version}")
else()
	message(STATUS "Git not found, using unknown build version.")
endif()

string(TIMESTAMP spirv-cross-timestamp)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/gitversion.in.h ${CMAKE_CURRENT_BINARY_DIR}/gitversion.h @ONLY)

if(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
	set(spirv-compiler-defines ${spirv-compiler-defines} SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
endif()

if(SPIRV_CROSS_FORCE_STL_TYPES)
	set(spirv-compiler-defines ${spirv-compiler-defines} SPIRV_CROSS_FORCE_STL_TYPES)
endif()

if (CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang"))
	set(spirv-compiler-options ${spirv-compiler-options} -Wall -Wextra -Wshadow)
	if (SPIRV_CROSS_MISC_WARNINGS)
		if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
			set(spirv-compiler-options ${spirv-compiler-options} -Wshorten-64-to-32)
		endif()
	endif()
	if (SPIRV_CROSS_WERROR)
		set(spirv-compiler-options ${spirv-compiler-options} -Werror)
	endif()

	if (SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
		set(spirv-compiler-options ${spirv-compiler-options} -fno-exceptions)
	endif()

	if (SPIRV_CROSS_SANITIZE_ADDRESS)
		set(spirv-compiler-options ${spirv-compiler-options} -fsanitize=address)
		set(spirv-cross-link-flags "${spirv-cross-link-flags} -fsanitize=address")
	endif()

	if (SPIRV_CROSS_SANITIZE_UNDEFINED)
		set(spirv-compiler-options ${spirv-compiler-options} -fsanitize=undefined)
		set(spirv-cross-link-flags "${spirv-cross-link-flags} -fsanitize=undefined")
	endif()

	if (SPIRV_CROSS_SANITIZE_MEMORY)
		set(spirv-compiler-options ${spirv-compiler-options} -fsanitize=memory)
		set(spirv-cross-link-flags "${spirv-cross-link-flags} -fsanitize=memory")
	endif()

	if (SPIRV_CROSS_SANITIZE_THREADS)
		set(spirv-compiler-options ${spirv-compiler-options} -fsanitize=thread)
		set(spirv-cross-link-flags "${spirv-cross-link-flags} -fsanitize=thread")
	endif()
elseif (MSVC)
	set(spirv-compiler-options ${spirv-compiler-options} /wd4267 /wd4996)
endif()

macro(extract_headers out_abs file_list)
	set(${out_abs}) # absolute paths
	foreach(_a ${file_list})
		# get_filename_component only returns the longest extension, so use a regex
		string(REGEX REPLACE ".*\\.(h|hpp)" "\\1" ext ${_a})

		# For shared library, we are only interested in the C header.
		if (SPIRV_CROSS_STATIC)
			if(("${ext}" STREQUAL "h") OR ("${ext}" STREQUAL "hpp"))
				list(APPEND ${out_abs} "${_a}")
			endif()
		else()
			if("${ext}" STREQUAL "h")
				list(APPEND ${out_abs} "${_a}")
			endif()
		endif()
	endforeach()
endmacro()

macro(spirv_cross_add_library name config_name library_type)
	add_library(${name} ${library_type} ${ARGN})
	extract_headers(hdrs "${ARGN}")
	target_include_directories(${name} PUBLIC
			$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
			$<INSTALL_INTERFACE:include/spirv_cross>)
	set_target_properties(${name} PROPERTIES
			PUBLIC_HEADERS "${hdrs}")
	target_compile_options(${name} PRIVATE ${spirv-compiler-options})
	target_compile_definitions(${name} PRIVATE ${spirv-compiler-defines})
	if (SPIRV_CROSS_NAMESPACE_OVERRIDE)
		if (${library_type} MATCHES "STATIC")
			target_compile_definitions(${name} PUBLIC SPIRV_CROSS_NAMESPACE_OVERRIDE=${SPIRV_CROSS_NAMESPACE_OVERRIDE})
		else()
			target_compile_definitions(${name} PRIVATE SPIRV_CROSS_NAMESPACE_OVERRIDE=${SPIRV_CROSS_NAMESPACE_OVERRIDE})
		endif()
	endif()

	if (NOT SPIRV_CROSS_SKIP_INSTALL)
		install(TARGETS ${name}
			EXPORT ${config_name}Config
			RUNTIME DESTINATION bin
			LIBRARY DESTINATION lib
			ARCHIVE DESTINATION lib
			PUBLIC_HEADER DESTINATION include/spirv_cross)
		install(FILES ${hdrs} DESTINATION include/spirv_cross)
		install(EXPORT ${config_name}Config DESTINATION share/${config_name}/cmake)
		export(TARGETS ${name} FILE ${config_name}Config.cmake)
	endif()
endmacro()

set(spirv-cross-core-sources
		${CMAKE_CURRENT_SOURCE_DIR}/GLSL.std.450.h
		${CMAKE_CURRENT_SOURCE_DIR}/spirv_common.hpp
		${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_containers.hpp
		${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_error_handling.hpp
		${CMAKE_CURRENT_SOURCE_DIR}/spirv.hpp
		${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross.hpp
		${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross.cpp<commit_msg>CMake: Add option to force -fPIC.<commit_after># Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_STANDARD 11)
project(SPIRV-Cross LANGUAGES CXX C)
enable_testing()

option(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS "Instead of throwing exceptions assert" OFF)
option(SPIRV_CROSS_SHARED "Build the C API as a single shared library." OFF)
option(SPIRV_CROSS_STATIC "Build the C and C++ API as static libraries." ON)
option(SPIRV_CROSS_CLI "Build the CLI binary. Requires SPIRV_CROSS_STATIC." ON)
option(SPIRV_CROSS_ENABLE_TESTS "Enable SPIRV-Cross tests." ON)

option(SPIRV_CROSS_ENABLE_GLSL "Enable GLSL support." ON)
option(SPIRV_CROSS_ENABLE_HLSL "Enable HLSL target support." ON)
option(SPIRV_CROSS_ENABLE_MSL "Enable MSL target support." ON)
option(SPIRV_CROSS_ENABLE_CPP "Enable C++ target support." ON)
option(SPIRV_CROSS_ENABLE_REFLECT "Enable JSON reflection target support." ON)
option(SPIRV_CROSS_ENABLE_C_API "Enable C API wrapper support in static library." ON)
option(SPIRV_CROSS_ENABLE_UTIL "Enable util module support." ON)

option(SPIRV_CROSS_SANITIZE_ADDRESS "Sanitize address" OFF)
option(SPIRV_CROSS_SANITIZE_MEMORY "Sanitize memory" OFF)
option(SPIRV_CROSS_SANITIZE_THREADS "Sanitize threads" OFF)
option(SPIRV_CROSS_SANITIZE_UNDEFINED "Sanitize undefined" OFF)

option(SPIRV_CROSS_NAMESPACE_OVERRIDE "" "Override the namespace used in the C++ API.")
option(SPIRV_CROSS_FORCE_STL_TYPES "Force use of STL types instead of STL replacements in certain places. Might reduce performance." OFF)

option(SPIRV_CROSS_SKIP_INSTALL "Skips installation targets." OFF)

option(SPIRV_CROSS_WERROR "Fail build on warnings." OFF)
option(SPIRV_CROSS_MISC_WARNINGS "Misc warnings useful for Travis runs." OFF)

option(SPIRV_CROSS_FORCE_PIC "Force position-independent code for all targets." OFF)

if(${CMAKE_GENERATOR} MATCHES "Makefile")
	if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
		message(FATAL_ERROR "Build out of tree to avoid overwriting Makefile")
	endif()
endif()

set(spirv-compiler-options "")
set(spirv-compiler-defines "")
set(spirv-cross-link-flags "")

message(STATUS "Finding Git version for SPIRV-Cross.")
set(spirv-cross-build-version "unknown")
find_package(Git)
if (GIT_FOUND)
	execute_process(
		COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
		OUTPUT_VARIABLE spirv-cross-build-version
		ERROR_QUIET
		OUTPUT_STRIP_TRAILING_WHITESPACE
		)
	message(STATUS "Git hash: ${spirv-cross-build-version}")
else()
	message(STATUS "Git not found, using unknown build version.")
endif()

string(TIMESTAMP spirv-cross-timestamp)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/gitversion.in.h ${CMAKE_CURRENT_BINARY_DIR}/gitversion.h @ONLY)

if(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
	set(spirv-compiler-defines ${spirv-compiler-defines} SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
endif()

if(SPIRV_CROSS_FORCE_STL_TYPES)
	set(spirv-compiler-defines ${spirv-compiler-defines} SPIRV_CROSS_FORCE_STL_TYPES)
endif()

if (CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang"))
	set(spirv-compiler-options ${spirv-compiler-options} -Wall -Wextra -Wshadow)
	if (SPIRV_CROSS_MISC_WARNINGS)
		if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
			set(spirv-compiler-options ${spirv-compiler-options} -Wshorten-64-to-32)
		endif()
	endif()
	if (SPIRV_CROSS_WERROR)
		set(spirv-compiler-options ${spirv-compiler-options} -Werror)
	endif()

	if (SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
		set(spirv-compiler-options ${spirv-compiler-options} -fno-exceptions)
	endif()

	if (SPIRV_CROSS_SANITIZE_ADDRESS)
		set(spirv-compiler-options ${spirv-compiler-options} -fsanitize=address)
		set(spirv-cross-link-flags "${spirv-cross-link-flags} -fsanitize=address")
	endif()

	if (SPIRV_CROSS_SANITIZE_UNDEFINED)
		set(spirv-compiler-options ${spirv-compiler-options} -fsanitize=undefined)
		set(spirv-cross-link-flags "${spirv-cross-link-flags} -fsanitize=undefined")
	endif()

	if (SPIRV_CROSS_SANITIZE_MEMORY)
		set(spirv-compiler-options ${spirv-compiler-options} -fsanitize=memory)
		set(spirv-cross-link-flags "${spirv-cross-link-flags} -fsanitize=memory")
	endif()

	if (SPIRV_CROSS_SANITIZE_THREADS)
		set(spirv-compiler-options ${spirv-compiler-options} -fsanitize=thread)
		set(spirv-cross-link-flags "${spirv-cross-link-flags} -fsanitize=thread")
	endif()
elseif (MSVC)
	set(spirv-compiler-options ${spirv-compiler-options} /wd4267 /wd4996)
endif()

macro(extract_headers out_abs file_list)
	set(${out_abs}) # absolute paths
	foreach(_a ${file_list})
		# get_filename_component only returns the longest extension, so use a regex
		string(REGEX REPLACE ".*\\.(h|hpp)" "\\1" ext ${_a})

		# For shared library, we are only interested in the C header.
		if (SPIRV_CROSS_STATIC)
			if(("${ext}" STREQUAL "h") OR ("${ext}" STREQUAL "hpp"))
				list(APPEND ${out_abs} "${_a}")
			endif()
		else()
			if("${ext}" STREQUAL "h")
				list(APPEND ${out_abs} "${_a}")
			endif()
		endif()
	endforeach()
endmacro()

macro(spirv_cross_add_library name config_name library_type)
	add_library(${name} ${library_type} ${ARGN})
	extract_headers(hdrs "${ARGN}")
	target_include_directories(${name} PUBLIC
			$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
			$<INSTALL_INTERFACE:include/spirv_cross>)
	set_target_properties(${name} PROPERTIES
			PUBLIC_HEADERS "${hdrs}")
	if (SPIRV_CROSS_FORCE_PIC)
		set_target_properties(${name} PROPERTIES POSITION_INDEPENDENT_CODE ON)
	endif()
	target_compile_options(${name} PRIVATE ${spirv-compiler-options})
	target_compile_definitions(${name} PRIVATE ${spirv-compiler-defines})
	if (SPIRV_CROSS_NAMESPACE_OVERRIDE)
		if (${library_type} MATCHES "STATIC")
			target_compile_definitions(${name} PUBLIC SPIRV_CROSS_NAMESPACE_OVERRIDE=${SPIRV_CROSS_NAMESPACE_OVERRIDE})
		else()
			target_compile_definitions(${name} PRIVATE SPIRV_CROSS_NAMESPACE_OVERRIDE=${SPIRV_CROSS_NAMESPACE_OVERRIDE})
		endif()
	endif()

	if (NOT SPIRV_CROSS_SKIP_INSTALL)
		install(TARGETS ${name}
			EXPORT ${config_name}Config
			RUNTIME DESTINATION bin
			LIBRARY DESTINATION lib
			ARCHIVE DESTINATION lib
			PUBLIC_HEADER DESTINATION include/spirv_cross)
		install(FILES ${hdrs} DESTINATION include/spirv_cross)
		install(EXPORT ${config_name}Config DESTINATION share/${config_name}/cmake)
		export(TARGETS ${name} FILE ${config_name}Config.cmake)
	endif()
endmacro()

set(spirv-cross-core-sources
		${CMAKE_CURRENT_SOURCE_DIR}/GLSL.std.450.h
		${CMAKE_CURRENT_SOURCE_DIR}/spirv_common.hpp
		${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_containers.hpp
		${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_error_handling.hpp
		${CMAKE_CURRENT_SOURCE_DIR}/spirv.hpp
		${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross.hpp
		${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross.cpp
{'fraction_non_alphanumeric': 0.11177700348432056, 'fraction_numerical': 0.003902439024390244, 'mean_word_length': 6.625398512221041, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '293597', 'n_tokens_mistral': 5558, 'n_tokens_neox': 5212, 'n_words': 1075}