2017-05-10 20:29:11 +03:00
|
|
|
cmake_minimum_required(VERSION 3.1.0)
|
2019-03-29 02:40:31 +03:00
|
|
|
project(MSTelemetry)
|
2017-05-10 20:29:11 +03:00
|
|
|
|
2018-03-31 03:05:05 +03:00
|
|
|
set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
|
|
|
|
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
|
|
|
|
set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
|
|
|
|
|
|
|
|
# Begin Uncomment for i386 build
|
|
|
|
#set(CMAKE_SYSTEM_PROCESSOR i386)
|
|
|
|
#set(CMAKE_C_FLAGS -m32)
|
|
|
|
#set(CMAKE_CXX_FLAGS -m32)
|
|
|
|
# End of i386 build
|
|
|
|
|
2018-11-07 09:39:27 +03:00
|
|
|
if (NOT TARGET_ARCH)
|
|
|
|
set(TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR})
|
|
|
|
endif()
|
|
|
|
|
2019-09-11 19:27:06 +03:00
|
|
|
# iOS build options
|
|
|
|
option(BUILD_IOS "Build for iOS" NO)
|
|
|
|
option(BUILD_SIMULATOR "Build using simulator SDK" NO)
|
|
|
|
|
|
|
|
if(BUILD_IOS)
|
2019-10-01 18:15:07 +03:00
|
|
|
add_definitions(-DIOS_HTTP=1)
|
2019-09-11 19:27:06 +03:00
|
|
|
set(TARGET_ARCH "APPLE")
|
2019-09-20 06:30:24 +03:00
|
|
|
set(IOS True)
|
|
|
|
set(APPLE True)
|
2019-09-20 18:47:53 +03:00
|
|
|
set (CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE)
|
2019-09-20 06:30:24 +03:00
|
|
|
|
2019-09-11 19:27:06 +03:00
|
|
|
if(BUILD_SIMULATOR)
|
|
|
|
set(IOS_PLATFORM "iphonesimulator")
|
|
|
|
set(CMAKE_SYSTEM_PROCESSOR x86_64)
|
|
|
|
else()
|
|
|
|
set(IOS_PLATFORM "iphoneos")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch arm64")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch arm64")
|
|
|
|
set(CMAKE_SYSTEM_PROCESSOR arm64)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
execute_process(COMMAND xcodebuild -version -sdk ${IOS_PLATFORM} Path
|
|
|
|
OUTPUT_VARIABLE CMAKE_OSX_SYSROOT
|
|
|
|
ERROR_QUIET
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
message("-- CMAKE_OSX_SYSROOT ${CMAKE_OSX_SYSROOT}")
|
|
|
|
endif()
|
|
|
|
|
2018-03-31 03:05:05 +03:00
|
|
|
message("-- CMAKE_SYSTEM_INFO_FILE: ${CMAKE_SYSTEM_INFO_FILE}")
|
|
|
|
message("-- CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
|
|
|
|
message("-- CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
|
|
|
|
message("-- CMAKE_SYSTEM: ${CMAKE_SYSTEM}")
|
|
|
|
message("-- CMAKE_SYSTEM_VERSION: ${CMAKE_SYSTEM_VERSION}")
|
2018-11-07 09:39:27 +03:00
|
|
|
message("-- CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
|
|
|
|
message("-- TARGET_ARCH: ${TARGET_ARCH}")
|
2018-03-31 03:05:05 +03:00
|
|
|
|
|
|
|
include(tools/ParseOsRelease.cmake)
|
|
|
|
|
2019-04-17 01:50:11 +03:00
|
|
|
# No -pedantic -Wno-extra-semi -Wno-gnu-zero-variadic-macro-arguments
|
|
|
|
set(WARN_FLAGS "-Wall -Wextra -Wno-unused-parameter")
|
2019-07-10 07:46:31 +03:00
|
|
|
|
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
|
|
|
# Using GCC with -s and -Wl linker flags
|
|
|
|
set(REL_FLAGS "-s -Wl,--gc-sections -Os ${WARN_FLAGS} -ffunction-sections -fdata-sections -fmerge-all-constants -ffast-math")
|
|
|
|
else()
|
|
|
|
# Using clang - strip unsupported GCC options
|
|
|
|
set(REL_FLAGS "-Os ${WARN_FLAGS} -ffunction-sections -fmerge-all-constants -ffast-math")
|
|
|
|
endif()
|
2018-03-31 03:05:05 +03:00
|
|
|
|
2019-09-19 09:10:36 +03:00
|
|
|
## Uncomment this to reduce the volume of note warnings on RPi4 w/gcc-8 Ref. https://gcc.gnu.org/ml/gcc/2017-05/msg00073.html
|
|
|
|
#if (CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
|
|
|
|
# set(WARN_FLAGS "${WARN_FLAGS} -Wno-psabi"
|
|
|
|
#endif()
|
|
|
|
|
2018-03-31 03:05:05 +03:00
|
|
|
# Use libtcmalloc for Debug builds memory leaks detection
|
2019-04-17 01:50:11 +03:00
|
|
|
set(DBG_FLAGS "-ggdb -gdwarf-2 -O0 ${WARN_FLAGS} -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free")
|
2018-03-31 03:05:05 +03:00
|
|
|
|
|
|
|
if (CMAKE_BUILD_TYPE STREQUAL "Release")
|
|
|
|
#TODO: -fno-rtti
|
2018-11-07 09:39:27 +03:00
|
|
|
message("Building Release ...")
|
2019-04-17 00:50:42 +03:00
|
|
|
set(CMAKE_C_FLAGS "$ENV{CFLAGS} ${CMAKE_C_FLAGS} -std=c11 ${REL_FLAGS}")
|
|
|
|
set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} ${CMAKE_CXX_FLAGS} -std=c++11 ${REL_FLAGS}")
|
2018-03-31 03:05:05 +03:00
|
|
|
else()
|
|
|
|
set(USE_TCMALLOC 1)
|
2018-11-07 09:39:27 +03:00
|
|
|
message("Building Debug ...")
|
2018-03-31 03:05:05 +03:00
|
|
|
include(tools/FindTcmalloc.cmake)
|
2019-04-17 00:50:42 +03:00
|
|
|
set(CMAKE_C_FLAGS "$ENV{CFLAGS} ${CMAKE_C_FLAGS} -std=c11 ${DBG_FLAGS}")
|
|
|
|
set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} ${CMAKE_CXX_FLAGS} -std=c++11 ${DBG_FLAGS}")
|
2018-03-31 03:05:05 +03:00
|
|
|
endif()
|
2017-05-10 20:29:11 +03:00
|
|
|
|
2019-07-20 03:05:19 +03:00
|
|
|
#Remove /Zi for Win32 debug compiler issue
|
|
|
|
if(MSVC)
|
|
|
|
string( TOLOWER "${CMAKE_VS_PLATFORM_NAME}" PLATFORM_NAME_LOWER )
|
|
|
|
if (PLATFORM_NAME_LOWER STREQUAL "win32")
|
|
|
|
string(REGEX REPLACE "/Z[iI7]" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
|
|
|
|
string(REGEX REPLACE "/Z[iI7]" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2019-05-23 01:57:00 +03:00
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
|
|
# using Clang
|
|
|
|
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
|
|
|
# using GCC
|
|
|
|
# Prefer to generate position-independent code
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
|
|
|
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
|
|
|
|
# using Intel C++
|
|
|
|
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
|
|
|
# using Visual Studio C++
|
|
|
|
endif()
|
|
|
|
|
2018-03-31 03:05:05 +03:00
|
|
|
include(tools/Utils.cmake)
|
2017-05-10 20:29:11 +03:00
|
|
|
|
2018-11-07 09:39:27 +03:00
|
|
|
if (NOT DEFAULT_PAL_IMPLEMENTATION)
|
|
|
|
# Linux, Mac OS X, MinGW, etc.
|
|
|
|
set(DEFAULT_PAL_IMPLEMENTATION CPP11)
|
|
|
|
endif()
|
2017-05-10 20:29:11 +03:00
|
|
|
|
2018-03-31 03:05:05 +03:00
|
|
|
set(PAL_IMPLEMENTATION ${DEFAULT_PAL_IMPLEMENTATION})
|
2017-05-10 20:29:11 +03:00
|
|
|
|
2018-11-07 09:39:27 +03:00
|
|
|
message(STATUS "-- PAL implementation: ${PAL_IMPLEMENTATION}")
|
2017-05-10 20:29:11 +03:00
|
|
|
string(TOUPPER ${PAL_IMPLEMENTATION} PAL_IMPLEMENTATION_UPPER)
|
2019-03-29 02:40:31 +03:00
|
|
|
add_definitions(-DMATSDK_PAL_${PAL_IMPLEMENTATION_UPPER}=1)
|
2017-05-10 20:29:11 +03:00
|
|
|
|
2019-03-08 08:24:15 +03:00
|
|
|
option(GCC5_CXX11_ABI_WORKAROUND "Workaround: Use legacy C++11 ABI (for GCC 5 compatibility)" OFF)
|
2017-05-10 20:29:11 +03:00
|
|
|
if(GCC5_CXX11_ABI_WORKAROUND)
|
|
|
|
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
|
|
|
|
endif()
|
|
|
|
|
2019-02-01 12:08:09 +03:00
|
|
|
if(PAL_IMPLEMENTATION STREQUAL "WIN32")
|
|
|
|
add_definitions(-DZLIB_WINAPI)
|
|
|
|
endif()
|
|
|
|
|
2018-11-07 09:39:27 +03:00
|
|
|
################################################################################################
|
|
|
|
# Build prefix and version
|
|
|
|
################################################################################################
|
|
|
|
|
|
|
|
set(SDK_VERSION_PREFIX "EVT")
|
2019-03-29 02:40:31 +03:00
|
|
|
add_definitions("-DMATSDK_VERSION_PREFIX=\"${SDK_VERSION_PREFIX}\"")
|
2017-05-10 20:29:11 +03:00
|
|
|
|
2019-04-23 01:14:38 +03:00
|
|
|
set(MATSDK_API_VERSION "3.2")
|
2018-03-31 03:05:05 +03:00
|
|
|
string(TIMESTAMP DAYNUMBER "%j")
|
|
|
|
string(REGEX REPLACE "^00" "" DAYNUMBER ${DAYNUMBER})
|
|
|
|
string(REGEX REPLACE "^0" "" DAYNUMBER ${DAYNUMBER})
|
|
|
|
|
2017-05-10 20:29:11 +03:00
|
|
|
if(DEFINED BUILD_VERSION AND NOT BUILD_VERSION STREQUAL "0.0.0.0")
|
|
|
|
message(STATUS "Using externally set build version: ${BUILD_VERSION}")
|
2019-03-29 02:40:31 +03:00
|
|
|
string(REPLACE "." "\\." MATSDK_API_VERSION_ESCAPED ${MATSDK_API_VERSION})
|
|
|
|
if(NOT BUILD_VERSION MATCHES "^${MATSDK_API_VERSION_ESCAPED}\\.")
|
|
|
|
message(WARNING "BUILD_VERSION (${BUILD_VERSION}) does not start with the current API version prefix (${MATSDK_API_VERSION}).")
|
2017-05-10 20:29:11 +03:00
|
|
|
endif()
|
2019-03-29 02:40:31 +03:00
|
|
|
set(MATSDK_BUILD_VERSION ${BUILD_VERSION})
|
2017-05-10 20:29:11 +03:00
|
|
|
else()
|
2019-03-29 02:40:31 +03:00
|
|
|
set(MATSDK_BUILD_VERSION ${MATSDK_API_VERSION}.${DAYNUMBER}.0)
|
2017-05-10 20:29:11 +03:00
|
|
|
endif()
|
|
|
|
|
2019-03-29 02:40:31 +03:00
|
|
|
message(STATUS "-- SDK version: ${SDK_VERSION_PREFIX}-${MATSDK_BUILD_VERSION}")
|
2018-11-07 09:39:27 +03:00
|
|
|
|
|
|
|
################################################################################################
|
|
|
|
# HTTP stack section
|
|
|
|
################################################################################################
|
|
|
|
|
|
|
|
# Only use custom curl if compiling with CPP11 PAL
|
|
|
|
if (PAL_IMPLEMENTATION STREQUAL "CPP11")
|
2019-09-11 19:27:06 +03:00
|
|
|
|
|
|
|
if(NOT BUILD_IOS)
|
|
|
|
include(FindCURL)
|
|
|
|
find_package(CURL REQUIRED)
|
|
|
|
if (NOT CURL_FOUND)
|
|
|
|
message (FATAL_ERROR "libcurl not found! Have you installed deps?")
|
|
|
|
endif (NOT CURL_FOUND)
|
|
|
|
include_directories(CURL_INCLUDE_DIRS)
|
|
|
|
set(CMAKE_REQUIRED_LIBRARIES "${CURL_LIBRARIES}")
|
|
|
|
list(APPEND LIBS "${CURL_LIBRARIES}")
|
|
|
|
endif()
|
2018-11-07 09:39:27 +03:00
|
|
|
endif()
|
2017-05-10 20:29:11 +03:00
|
|
|
|
2018-11-07 09:39:27 +03:00
|
|
|
################################################################################################
|
|
|
|
# User options
|
|
|
|
################################################################################################
|
|
|
|
option(BUILD_HEADERS "Build API headers" YES)
|
|
|
|
option(BUILD_LIBRARY "Build library" YES)
|
|
|
|
option(BUILD_TEST_TOOL "Build console test tool" YES)
|
2019-02-01 12:08:09 +03:00
|
|
|
option(BUILD_UNIT_TESTS "Build unit tests" YES)
|
|
|
|
option(BUILD_FUNC_TESTS "Build functional tests" YES)
|
2018-11-07 09:39:27 +03:00
|
|
|
option(BUILD_JNI_WRAPPER "Build JNI wrapper" NO)
|
|
|
|
option(BUILD_PACKAGE "Build package" YES)
|
2017-05-10 20:29:11 +03:00
|
|
|
|
2018-03-31 03:05:05 +03:00
|
|
|
if(BUILD_UNIT_TESTS OR BUILD_FUNC_TESTS)
|
2019-02-01 12:08:09 +03:00
|
|
|
message("Adding gtest")
|
2017-05-10 20:29:11 +03:00
|
|
|
add_library(gtest STATIC IMPORTED GLOBAL)
|
2019-02-01 12:08:09 +03:00
|
|
|
message("Adding gmock")
|
2017-05-10 20:29:11 +03:00
|
|
|
add_library(gmock STATIC IMPORTED GLOBAL)
|
2019-02-01 12:08:09 +03:00
|
|
|
|
|
|
|
# message("Building libraries! - Path: ${CMAKE_CURRENT_SOURCE_DIR} ")
|
|
|
|
# message("Building gtest")
|
|
|
|
# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/googletest/googletest/)
|
|
|
|
# message("Building gmock")
|
|
|
|
# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/googletest/googlemock/)
|
2017-05-10 20:29:11 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Bond Lite subdirectories
|
|
|
|
include_directories(bondlite/include)
|
|
|
|
|
2019-02-01 12:08:09 +03:00
|
|
|
include_directories(lib/pal)
|
|
|
|
|
|
|
|
#if(BUILD_UNIT_TESTS)
|
|
|
|
# message("Adding bondlite tests")
|
|
|
|
# enable_testing()
|
|
|
|
# add_subdirectory(bondlite/tests)
|
|
|
|
#endif()
|
2017-05-10 20:29:11 +03:00
|
|
|
|
|
|
|
if(BUILD_HEADERS)
|
|
|
|
add_subdirectory(lib/include)
|
|
|
|
endif()
|
|
|
|
include_directories(lib/include)
|
|
|
|
|
|
|
|
if(BUILD_LIBRARY)
|
|
|
|
add_subdirectory(lib)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(BUILD_UNIT_TESTS OR BUILD_FUNC_TESTS)
|
2019-02-01 12:08:09 +03:00
|
|
|
message("Building tests")
|
2017-05-10 20:29:11 +03:00
|
|
|
enable_testing()
|
|
|
|
add_subdirectory(tests)
|
|
|
|
endif()
|
|
|
|
|
2018-11-07 09:39:27 +03:00
|
|
|
################################################################################################
|
|
|
|
# Packaging
|
|
|
|
################################################################################################
|
|
|
|
|
|
|
|
if (BUILD_PACKAGE)
|
|
|
|
if (${CMAKE_PACKAGE_TYPE} STREQUAL "deb")
|
|
|
|
# FIXME: hardcode it for 64-bit Linux for now
|
|
|
|
set(INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib/${CPACK_DEBIAN_ARCHITECTURE}-linux-gnu)
|
|
|
|
include(tools/MakeDeb.cmake)
|
|
|
|
endif()
|
|
|
|
if (${CMAKE_PACKAGE_TYPE} STREQUAL "rpm")
|
|
|
|
# TODO: [MG] - fix path
|
|
|
|
set(INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu)
|
|
|
|
include(tools/MakeRpm.cmake)
|
|
|
|
endif()
|
|
|
|
if (${CMAKE_PACKAGE_TYPE} STREQUAL "tgz")
|
|
|
|
# TODO: [MG] - fix path... should we simply use /usr/local/lib without CPU?
|
2019-03-29 02:40:31 +03:00
|
|
|
# TODO: [MG] - Windows path is not ideal -- C:/Program Files (x86)/MSTelemetry/* - what should we use instead?
|
2018-11-07 09:39:27 +03:00
|
|
|
include(tools/MakeTgz.cmake)
|
|
|
|
endif()
|
|
|
|
endif()
|