2018-07-18 09:40:26 +00:00
|
|
|
# Copyright 2017 The Dawn Authors
|
2017-04-20 18:38:20 +00:00
|
|
|
#
|
|
|
|
# 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)
|
|
|
|
project(nxt C CXX)
|
|
|
|
|
2017-08-03 18:45:12 +00:00
|
|
|
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
|
|
|
|
message(FATAL_ERROR
|
|
|
|
"In-source builds are unsupported. Use another directory, like build/, "
|
|
|
|
"as your CMake build directory.\n"
|
|
|
|
"Note: CMakeFiles/ and CMakeCache.txt may have been generated in the "
|
|
|
|
"source directory. These may be removed.")
|
|
|
|
endif()
|
|
|
|
|
2017-07-20 14:28:00 +00:00
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
|
|
|
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
|
|
|
|
"Build type (Debug, Release, RelWithDebInfo, MinSizeRel)" FORCE)
|
|
|
|
endif()
|
|
|
|
|
2017-07-07 18:41:17 +00:00
|
|
|
################################################################################
|
|
|
|
# Configuration options
|
|
|
|
################################################################################
|
|
|
|
|
2018-07-18 11:52:46 +00:00
|
|
|
option(DAWN_USE_WERROR "Treat warnings as error (useful for CI)" 0)
|
2017-07-07 18:41:17 +00:00
|
|
|
|
2017-07-12 16:43:24 +00:00
|
|
|
# Default values for the backend-enabling options
|
2017-07-14 13:53:59 +00:00
|
|
|
set(ENABLE_D3D12 OFF)
|
|
|
|
set(ENABLE_METAL OFF)
|
2017-07-12 16:43:24 +00:00
|
|
|
if (WIN32)
|
2017-07-14 13:53:59 +00:00
|
|
|
set(ENABLE_D3D12 ON)
|
2017-07-12 16:43:24 +00:00
|
|
|
elseif(APPLE)
|
2017-07-14 13:53:59 +00:00
|
|
|
set(ENABLE_METAL ON)
|
2017-07-12 16:43:24 +00:00
|
|
|
endif()
|
|
|
|
|
2018-07-18 11:52:46 +00:00
|
|
|
option(DAWN_ENABLE_D3D12 "Enable compilation of the D3D12 backend" ${ENABLE_D3D12})
|
|
|
|
option(DAWN_ENABLE_METAL "Enable compilation of the Metal backend" ${ENABLE_METAL})
|
|
|
|
option(DAWN_ENABLE_NULL "Enable compilation of the Null backend" ON)
|
|
|
|
option(DAWN_ENABLE_OPENGL "Enable compilation of the OpenGL backend" ON)
|
|
|
|
option(DAWN_ENABLE_VULKAN "Enable compilation of the Vulkan backend" OFF)
|
|
|
|
option(DAWN_ALWAYS_ASSERT "Enable assertions on all build types" OFF)
|
|
|
|
option(DAWN_USE_CPP17 "Use some optional C++17 features for compile-time checks" OFF)
|
2017-07-12 16:43:24 +00:00
|
|
|
|
2017-07-07 18:41:17 +00:00
|
|
|
################################################################################
|
|
|
|
# Precompute compile flags and defines, functions to set them
|
|
|
|
################################################################################
|
|
|
|
|
2018-07-18 11:52:46 +00:00
|
|
|
set(DAWN_FLAGS "")
|
|
|
|
set(DAWN_DEFS "")
|
|
|
|
set(DAWN_INTERNAL_FLAGS "")
|
|
|
|
set(DAWN_INTERNAL_DEFS "")
|
|
|
|
set(DAWN_GENERATED_FLAGS "")
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-18 11:52:46 +00:00
|
|
|
set(DAWN_ENABLE_ASSERTS $<OR:$<CONFIG:Debug>,$<BOOL:${DAWN_ALWAYS_ASSERT}>>)
|
2017-07-20 14:28:00 +00:00
|
|
|
|
2018-07-18 11:52:46 +00:00
|
|
|
list(APPEND DAWN_DEFS $<${DAWN_ENABLE_ASSERTS}:DAWN_ENABLE_ASSERTS>)
|
2017-07-10 17:46:05 +00:00
|
|
|
|
2018-07-18 11:52:46 +00:00
|
|
|
if (DAWN_USE_CPP17)
|
|
|
|
list(APPEND DAWN_INTERNAL_DEFS "DAWN_CPP_VERSION=17")
|
2018-05-23 20:56:55 +00:00
|
|
|
else()
|
2018-07-18 11:52:46 +00:00
|
|
|
list(APPEND DAWN_INTERNAL_DEFS "DAWN_CPP_VERSION=14")
|
2018-05-23 20:56:55 +00:00
|
|
|
endif()
|
|
|
|
|
2018-07-18 11:52:46 +00:00
|
|
|
if (DAWN_ENABLE_D3D12)
|
|
|
|
list(APPEND DAWN_INTERNAL_DEFS "DAWN_ENABLE_BACKEND_D3D12")
|
2017-07-12 16:43:24 +00:00
|
|
|
endif()
|
2018-07-18 11:52:46 +00:00
|
|
|
if (DAWN_ENABLE_METAL)
|
|
|
|
list(APPEND DAWN_INTERNAL_DEFS "DAWN_ENABLE_BACKEND_METAL")
|
2017-07-12 16:43:24 +00:00
|
|
|
endif()
|
2018-07-18 11:52:46 +00:00
|
|
|
if (DAWN_ENABLE_NULL)
|
|
|
|
list(APPEND DAWN_INTERNAL_DEFS "DAWN_ENABLE_BACKEND_NULL")
|
2017-07-12 16:43:24 +00:00
|
|
|
endif()
|
2018-07-18 11:52:46 +00:00
|
|
|
if (DAWN_ENABLE_OPENGL)
|
|
|
|
list(APPEND DAWN_INTERNAL_DEFS "DAWN_ENABLE_BACKEND_OPENGL")
|
2017-07-12 16:43:24 +00:00
|
|
|
endif()
|
2018-07-18 11:52:46 +00:00
|
|
|
if (DAWN_ENABLE_VULKAN)
|
|
|
|
list(APPEND DAWN_INTERNAL_DEFS "DAWN_ENABLE_BACKEND_VULKAN")
|
2017-07-12 16:43:24 +00:00
|
|
|
endif()
|
|
|
|
|
2017-05-29 18:33:33 +00:00
|
|
|
if (WIN32)
|
2017-07-07 18:41:17 +00:00
|
|
|
# Define NOMINMAX to prevent conflicts between std::min/max and the min/max macros in WinDef.h
|
2018-07-18 11:52:46 +00:00
|
|
|
list(APPEND DAWN_DEFS "NOMINMAX")
|
2017-07-12 16:55:15 +00:00
|
|
|
# Avoid Windows.h including a lot of headers
|
2018-07-18 11:52:46 +00:00
|
|
|
list(APPEND DAWN_DEFS "WIN32_LEAN_AND_MEAN")
|
2017-05-29 18:33:33 +00:00
|
|
|
# Remove compile error where the mock NXT creates too many sections for the old obj format.
|
2018-07-18 11:52:46 +00:00
|
|
|
list(APPEND DAWN_FLAGS "/bigobj")
|
2017-05-29 18:33:33 +00:00
|
|
|
endif()
|
|
|
|
|
2017-07-07 18:41:17 +00:00
|
|
|
if (MSVC)
|
2018-07-18 11:52:46 +00:00
|
|
|
list(APPEND DAWN_FLAGS "/std:c++14")
|
|
|
|
list(APPEND DAWN_FLAGS "/EHsc")
|
|
|
|
list(APPEND DAWN_INTERNAL_FLAGS "/W4")
|
2017-07-11 00:09:59 +00:00
|
|
|
# Allow declarations hiding members as it is used all over NXT
|
2018-07-18 11:52:46 +00:00
|
|
|
list(APPEND DAWN_INTERNAL_FLAGS "/wd4458")
|
|
|
|
list(APPEND DAWN_INTERNAL_FLAGS "/wd4996") # Allow deprecated functions like strncpy
|
2017-07-11 00:09:59 +00:00
|
|
|
|
2018-07-18 11:52:46 +00:00
|
|
|
list(APPEND DAWN_GENERATED_FLAGS "/wd4702") # Allow unreachable code
|
|
|
|
list(APPEND DAWN_GENERATED_FLAGS "/wd4189") # Allow unused variable
|
2017-07-20 14:28:00 +00:00
|
|
|
|
2018-07-18 11:52:46 +00:00
|
|
|
if(DAWN_USE_WERROR)
|
|
|
|
list(APPEND DAWN_INTERNAL_FLAGS "/WX")
|
2017-07-11 00:09:59 +00:00
|
|
|
endif()
|
2017-07-07 18:41:17 +00:00
|
|
|
else()
|
|
|
|
# Activate C++14 only on C++ files, not C files.
|
2018-07-18 11:52:46 +00:00
|
|
|
list(APPEND DAWN_FLAGS "$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,CXX>:-std=c++14>")
|
2017-07-22 00:00:22 +00:00
|
|
|
# enable -Wold-style-cast on C++
|
2018-07-18 11:52:46 +00:00
|
|
|
list(APPEND DAWN_FLAGS "$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,CXX>:-Wold-style-cast>")
|
|
|
|
list(APPEND DAWN_FLAGS "-fPIC")
|
2017-07-07 18:41:17 +00:00
|
|
|
|
2018-07-18 11:52:46 +00:00
|
|
|
list(APPEND DAWN_INTERNAL_FLAGS "-Wall" "-Wextra")
|
|
|
|
list(APPEND DAWN_INTERNAL_FLAGS "-pedantic")
|
|
|
|
list(APPEND DAWN_GENERATED_FLAGS "-Wno-unused-variable" "-Wno-unused-function")
|
2017-07-22 00:00:22 +00:00
|
|
|
|
|
|
|
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
|
|
# don't break the build on older clang versions
|
2018-07-18 11:52:46 +00:00
|
|
|
list(APPEND DAWN_INTERNAL_FLAGS "-Wno-error=unknown-warning-option")
|
2017-07-22 00:00:22 +00:00
|
|
|
# GCC's conversion warnings are less useful than clang's
|
2018-07-18 11:52:46 +00:00
|
|
|
list(APPEND DAWN_INTERNAL_FLAGS "-Wconversion" "-Wno-sign-conversion")
|
2017-07-22 00:00:22 +00:00
|
|
|
# disable a clang-only -pedantic warning
|
2018-07-18 11:52:46 +00:00
|
|
|
list(APPEND DAWN_INTERNAL_FLAGS "-Wno-gnu-zero-variadic-macro-arguments")
|
2017-07-22 00:00:22 +00:00
|
|
|
# additional potentially useful warnings (feel free to remove if they prove un-useful)
|
2018-07-18 11:52:46 +00:00
|
|
|
list(APPEND DAWN_INTERNAL_FLAGS "-Wextra-semi")
|
|
|
|
list(APPEND DAWN_INTERNAL_FLAGS "-Wstrict-aliasing")
|
|
|
|
list(APPEND DAWN_INTERNAL_FLAGS "-Wunreachable-code")
|
|
|
|
list(APPEND DAWN_GENERATED_FLAGS "-Wno-unreachable-code")
|
2017-07-22 00:00:22 +00:00
|
|
|
# Probably okay to enable if we establish a field naming convention:
|
2018-07-18 11:52:46 +00:00
|
|
|
#list(APPEND DAWN_INTERNAL_FLAGS "-Wshadow")
|
2017-07-22 00:00:22 +00:00
|
|
|
endif()
|
2018-07-18 11:52:46 +00:00
|
|
|
if(DAWN_USE_WERROR)
|
|
|
|
list(APPEND DAWN_INTERNAL_FLAGS "-Werror")
|
2017-07-07 18:41:17 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
function(NXTExternalTarget folder target)
|
2018-07-18 11:52:46 +00:00
|
|
|
set_property(TARGET ${target} APPEND PROPERTY COMPILE_OPTIONS ${DAWN_FLAGS})
|
|
|
|
set_property(TARGET ${target} APPEND PROPERTY COMPILE_DEFINITIONS ${DAWN_DEFS})
|
2017-07-10 23:08:46 +00:00
|
|
|
set_property(TARGET ${target} PROPERTY FOLDER "nxt/${folder}")
|
2017-07-07 18:41:17 +00:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(NXTInternalTarget folder target)
|
|
|
|
NXTExternalTarget("${folder}" ${target})
|
2018-07-18 11:52:46 +00:00
|
|
|
set_property(TARGET ${target} APPEND PROPERTY COMPILE_OPTIONS ${DAWN_INTERNAL_FLAGS})
|
|
|
|
set_property(TARGET ${target} APPEND PROPERTY COMPILE_DEFINITIONS ${DAWN_INTERNAL_DEFS})
|
2017-07-11 02:39:04 +00:00
|
|
|
|
|
|
|
# Group the target sources by folder to have folders show in Visual Studio
|
|
|
|
if (MSVC)
|
|
|
|
get_target_property(targetSources ${target} SOURCES)
|
|
|
|
foreach(sourceFile IN ITEMS ${targetSources})
|
|
|
|
if (IS_ABSOLUTE "${sourceFile}")
|
|
|
|
file(RELATIVE_PATH sourceFile "${CMAKE_CURRENT_SOURCE_DIR}" "${sourceFile}")
|
|
|
|
endif()
|
|
|
|
get_filename_component(sourceDir "${sourceFile}" PATH)
|
|
|
|
string(REPLACE "/" "\\" sourceDir "${sourceDir}")
|
|
|
|
source_group("${sourceDir}" FILES "${sourceFile}")
|
|
|
|
endforeach()
|
|
|
|
endif()
|
2017-07-07 18:41:17 +00:00
|
|
|
endfunction()
|
|
|
|
|
2017-07-11 02:39:04 +00:00
|
|
|
# Enable the creation of folders for Visual Studio projects
|
|
|
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
|
|
|
|
2017-11-28 18:08:17 +00:00
|
|
|
# Output shared libs and executables directly in the build directory
|
|
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
|
|
|
|
2017-07-07 18:41:17 +00:00
|
|
|
################################################################################
|
|
|
|
# Generate the C and C++ NXT APIs
|
|
|
|
################################################################################
|
2017-04-20 18:38:20 +00:00
|
|
|
|
|
|
|
set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/include)
|
2017-07-07 18:41:17 +00:00
|
|
|
set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
|
|
|
|
|
|
|
add_subdirectory(generator)
|
2017-04-20 18:38:20 +00:00
|
|
|
|
|
|
|
Generate(
|
|
|
|
LIB_NAME nxt
|
2017-05-29 18:21:33 +00:00
|
|
|
LIB_TYPE STATIC
|
2017-04-20 18:38:20 +00:00
|
|
|
PRINT_NAME libNXT
|
|
|
|
COMMAND_LINE_ARGS
|
|
|
|
${GENERATOR_COMMON_ARGS}
|
|
|
|
-T nxt
|
|
|
|
)
|
|
|
|
target_include_directories(nxt PUBLIC ${GENERATED_DIR})
|
|
|
|
|
|
|
|
Generate(
|
|
|
|
LIB_NAME nxtcpp
|
2017-05-29 18:21:33 +00:00
|
|
|
LIB_TYPE STATIC
|
2017-04-20 18:38:20 +00:00
|
|
|
PRINT_NAME libNXT++
|
|
|
|
COMMAND_LINE_ARGS
|
|
|
|
${GENERATOR_COMMON_ARGS}
|
|
|
|
-T nxtcpp
|
|
|
|
)
|
|
|
|
target_include_directories(nxtcpp PUBLIC ${GENERATED_DIR} PUBLIC ${INCLUDE_DIR})
|
|
|
|
target_link_libraries(nxtcpp nxt)
|
|
|
|
|
2017-07-07 18:41:17 +00:00
|
|
|
################################################################################
|
|
|
|
# Call to other CMakeLists.txt
|
|
|
|
################################################################################
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-07-07 18:41:17 +00:00
|
|
|
add_subdirectory(third_party)
|
2017-05-16 18:16:56 +00:00
|
|
|
|
2017-07-06 18:41:13 +00:00
|
|
|
add_subdirectory(src/common)
|
2017-04-20 18:38:20 +00:00
|
|
|
add_subdirectory(src/backend)
|
|
|
|
add_subdirectory(src/wire)
|
2017-06-19 16:53:38 +00:00
|
|
|
add_subdirectory(src/utils)
|
2017-04-20 18:38:20 +00:00
|
|
|
add_subdirectory(src/tests)
|
|
|
|
|
|
|
|
add_subdirectory(examples)
|