From 94fa43963538afffc1fff77623cd1561a05d0e21 Mon Sep 17 00:00:00 2001 From: Sanimir Agovic Date: Mon, 25 Feb 2019 19:19:19 +0100 Subject: TCF Agent: improve native and cross builds with cmake Increase cmake build coverage e.g. Darwin, Android as well on risc64 machines. Cross builds work as well. Bumping required cmake version for finding the right pthread library or none if not needed (Windows, Android). Change-Id: I61288bc674d8e47a3bc7dfafdaffe583b8376d5c Signed-off-by: Sanimir Agovic --- agent/CMakeLists.txt | 48 +++------------------------------------ cmake-tcf-lib.txt | 63 ++++++++++++++++++++++++++++------------------------ 2 files changed, 37 insertions(+), 74 deletions(-) diff --git a/agent/CMakeLists.txt b/agent/CMakeLists.txt index d24a6bcb..d5fa5396 100644 --- a/agent/CMakeLists.txt +++ b/agent/CMakeLists.txt @@ -1,6 +1,6 @@ # -*- cmake -*- -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.1) project(tcfagent C) include(GNUInstallDirs) @@ -8,52 +8,10 @@ set(CMAKE_COLOR_MAKEFILE OFF) set(TCF_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..) set(TCF_LIB_NAME tcf-agent) - -if(NOT WIN32) - if(NOT TCF_OPSYS) - set(TCF_OPSYS "GNU/Linux") - endif() - if(NOT TCF_MACHINE) - set(TCF_MACHINE "x86_64") - endif() - if(TCF_MACHINE STREQUAL "armv6l") - set(TCF_MACHINE "arm") - endif() - if(TCF_MACHINE STREQUAL "armv7l") - set(TCF_MACHINE "arm") - endif() - if(TCF_MACHINE STREQUAL "ppc64") - set(TCF_MACHINE "powerpc") - endif() - if(TCF_MACHINE STREQUAL "aarch64") - set(TCF_MACHINE "a64") - endif() -endif() - -if(CMAKE_SYSTEM_NAME STREQUAL "SunOS") - set(MULTI_THREADED_COMPILE_FLAGS "-pthreads") - set(MULTI_THREADED_LINK_LIBS pthread rt) -elseif(APPLE) - set(MULTI_THREADED_COMPILE_FLAGS "-pthread -D_REENTRANT") - set(MULTI_THREADED_LINK_FLAGS "") - set(MULTI_THREADED_LINK_LIBS pthread) -elseif(UNIX) - set(MULTI_THREADED_COMPILE_FLAGS "-pthread -D_REENTRANT") - set(MULTI_THREADED_LINK_FLAGS "") - set(MULTI_THREADED_LINK_LIBS pthread rt) - set(UUID_LIB_NAME uuid) -elseif(WIN32) - set(SOCKET_LINK_LIBS ws2_32 iphlpapi) -endif() - include(../cmake-tcf-lib.txt) -if(WIN32) - target_link_libraries(${TCF_LIB_NAME} version.lib psapi.lib) -endif() - -message(STATUS "operating system:" ${TCF_OPSYS}) -message(STATUS "machine:" ${TCF_MACHINE}) +message(STATUS "operating system: " ${TCF_OPSYS}) +message(STATUS "machine: " ${TCF_MACHINE}) add_executable(agent tcf/main/main.c) target_link_libraries(agent ${TCF_LIB_NAME}) diff --git a/cmake-tcf-lib.txt b/cmake-tcf-lib.txt index da24175a..83c205c3 100644 --- a/cmake-tcf-lib.txt +++ b/cmake-tcf-lib.txt @@ -1,32 +1,23 @@ # -*- cmake -*- -if(WIN32) -if(NOT TCF_OPSYS) - set(TCF_OPSYS "Windows") +set(default_opsys ${CMAKE_SYSTEM_NAME}) +if(default_opsys MATCHES "Linux|Android") + set(default_opsys GNU/Linux) endif() -if(NOT TCF_MACHINE) - set(TCF_MACHINE "x86_64") + +set(default_machine ${CMAKE_SYSTEM_PROCESSOR}) +if(default_machine MATCHES "^(amd64|AMD64)$") + set(default_machine x86_64) +elseif(default_machine MATCHES "^(armv6l|armv7l|armv7-a)$") + set(default_machine arm) +elseif(default_machine STREQUAL "ppc64") + set(default_machine powerpc) +elseif(default_machine STREQUAL "aarch64") + set(default_machine a64) endif() -endif(WIN32) -if(ANDROID) - if(NOT TCF_OPSYS) - set(TCF_OPSYS "GNU/Linux") - endif() - if(NOT TCF_MACHINE) - if(ARMEABI OR ARMEABI_V6 OR ARMEABI_V7A) - set(TCF_MACHINE "arm") - elseif(ARM64_V8A ) - set(TCF_MACHINE "a64") - elseif(X86 ) - set(TCF_MACHINE "i686") - elseif(X86_64 ) - set(TCF_MACHINE "x86_64") - else() - message( FATAL_ERROR "Unsupported ABI " ${ANDROID_ABI} ) - endif() - endif() -endif(ANDROID) +set(TCF_MACHINE ${default_machine} CACHE STRING "TCF machine") +set(TCF_OPSYS ${default_opsys} CACHE STRING "TCF operating system") if (NOT TCF_DIR) set(TCF_DIR ${CMAKE_CURRENT_LIST_DIR}) @@ -91,12 +82,26 @@ endif() include_directories(${TCF_BASE_DIR} ${TCF_BASE_DIR}/system/${TCF_OPSYS} ${TCF_BASE_DIR}/machine/${TCF_MACHINE}) -set_source_files_properties(${TCF_SRCS} PROPERTIES - COMPILE_FLAGS "${MULTI_THREADED_COMPILE_FLAGS}") add_library(${TCF_LIB_NAME} ${TCF_LIB_TYPE} ${TCF_SRCS}) -target_link_libraries(${TCF_LIB_NAME} - ${UUID_LIB_NAME} ${MULTI_THREADED_LINK_LIBS} ${SOCKET_LINK_LIBS}) - +find_package(Threads) +target_link_libraries(${TCF_LIB_NAME} Threads::Threads) +find_library(LIBRT rt) +if(LIBRT) + target_link_libraries(${TCF_LIB_NAME} ${LIBRT}) +endif() +find_library(LIBUUID uuid) +if(LIBUUID) + target_link_libraries(${TCF_LIB_NAME} ${LIBUUID}) +else() + target_compile_definitions(${TCF_LIB_NAME} PUBLIC USE_uuid_generate=0) +endif() +if(WIN32) + target_link_libraries(${TCF_LIB_NAME} version.lib psapi.lib ws2_32 iphlpapi) +endif() +if(ANDROID) + find_library(LIBLOG log) + target_link_libraries(${TCF_LIB_NAME} ${LIBLOG}) +endif() if(SSL_LIB_NAME) target_link_libraries(${TCF_LIB_NAME} ${SSL_LIB_NAME}) else() -- cgit v1.2.3