2017-04-20 18:38:20 +00:00
|
|
|
# Copyright 2017 The NXT Authors
|
|
|
|
#
|
|
|
|
# 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-07-07 18:41:17 +00:00
|
|
|
################################################################################
|
|
|
|
# Configuration options
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
option(NXT_USE_WERROR "Treat warnings as error (useful for CI)" 0)
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Precompute compile flags and defines, functions to set them
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
set(NXT_FLAGS "")
|
|
|
|
set(NXT_DEFS "")
|
|
|
|
set(NXT_INTERNAL_FLAGS "")
|
|
|
|
set(NXT_INTERNAL_DEFS "")
|
2017-07-11 00:09:59 +00:00
|
|
|
set(NXT_GENERATED_FLAGS "")
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-07-10 17:46:05 +00:00
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
|
|
|
list(APPEND NXT_DEFS "NXT_ENABLE_ASSERTS")
|
|
|
|
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
|
|
|
|
list(APPEND NXT_DEFS "NOMINMAX")
|
2017-05-29 18:33:33 +00:00
|
|
|
# Remove compile error where the mock NXT creates too many sections for the old obj format.
|
2017-07-07 18:41:17 +00:00
|
|
|
list(APPEND NXT_FLAGS "/bigobj")
|
2017-05-29 18:33:33 +00:00
|
|
|
endif()
|
|
|
|
|
2017-07-07 18:41:17 +00:00
|
|
|
if (MSVC)
|
|
|
|
list(APPEND NXT_FLAGS "/std:c++14")
|
2017-07-11 00:09:59 +00:00
|
|
|
list(APPEND NXT_INTERNAL_FLAGS "/W4")
|
|
|
|
# Allow declarations hiding members as it is used all over NXT
|
|
|
|
list(APPEND NXT_INTERNAL_FLAGS "/wd4458")
|
|
|
|
list(APPEND NXT_INTERNAL_FLAGS "/wd4996") # Allow deprecated functions like strncpy
|
|
|
|
|
|
|
|
list(APPEND NXT_GENERATED_FLAGS "/wd4702") # Allow unreachable code
|
|
|
|
list(APPEND NXT_GENERATED_FLAGS "/wd4189") # Allow unused variable
|
|
|
|
|
|
|
|
if(NXT_USE_WERROR)
|
|
|
|
list(APPEND NXT_INTERNAL_FLAGS "/WX")
|
|
|
|
endif()
|
2017-07-07 18:41:17 +00:00
|
|
|
else()
|
|
|
|
# Activate C++14 only on C++ files, not C files.
|
|
|
|
list(APPEND NXT_FLAGS "$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,CXX>:-std=c++14>")
|
|
|
|
list(APPEND NXT_FLAGS "-fPIC")
|
|
|
|
|
|
|
|
list(APPEND NXT_INTERNAL_FLAGS "-Wall" "-Wextra")
|
2017-07-11 00:09:59 +00:00
|
|
|
list(APPEND NXT_GENERATED_FLAGS "-Wno-unused-variable" "-Wno-unused-function")
|
2017-07-07 18:41:17 +00:00
|
|
|
if(NXT_USE_WERROR)
|
|
|
|
list(APPEND NXT_INTERNAL_FLAGS "-Werror")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
function(NXTExternalTarget folder target)
|
|
|
|
set_property(TARGET ${target} APPEND PROPERTY COMPILE_OPTIONS ${NXT_FLAGS})
|
|
|
|
set_property(TARGET ${target} APPEND PROPERTY COMPILE_DEFINITIONS ${NXT_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})
|
|
|
|
set_property(TARGET ${target} APPEND PROPERTY COMPILE_OPTIONS ${NXT_INTERNAL_FLAGS})
|
|
|
|
set_property(TARGET ${target} APPEND PROPERTY COMPILE_DEFINITIONS ${NXT_INTERNAL_DEFS})
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# 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)
|