2019-07-28 10:31:56 +08:00
|
|
|
cmake_minimum_required(VERSION 2.8)
|
2017-02-12 21:39:38 +08:00
|
|
|
#set(CMAKE_BUILD_TYPE Release)
|
|
|
|
#set(CMAKE_BUILD_TYPE Release CACHE STRING "set build type to release")
|
|
|
|
|
|
|
|
if (${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
message(FATAL_ERROR "Please into another dir to build!")
|
|
|
|
endif()
|
|
|
|
|
2017-03-25 23:05:44 +08:00
|
|
|
#string(TOUPPER ${CMAKE_SYSTEM_NAME} CMAKE_SYSTEM_NAME)
|
|
|
|
if (CMAKE_SYSTEM_NAME MATCHES "Android")
|
2019-09-19 09:00:59 +08:00
|
|
|
add_definitions("-flto")
|
2017-02-12 21:39:38 +08:00
|
|
|
add_definitions("-DANDROID")
|
2019-09-19 09:00:59 +08:00
|
|
|
add_definitions("-Wno-invalid-source-encoding")
|
2019-09-24 11:21:36 +08:00
|
|
|
add_definitions("-Wno-unused-command-line-argument")
|
2019-09-30 14:19:27 +08:00
|
|
|
# add_definitions("-fvisibility=hidden")
|
|
|
|
# add_definitions("-fvisibility-inlines-hidden")
|
|
|
|
add_definitions("-fdata-sections -ffunction-sections")
|
2019-09-24 11:21:36 +08:00
|
|
|
string(APPEND CMAKE_C_FLAGS " -Qunused-arguments")
|
2017-03-31 23:04:16 +08:00
|
|
|
set(UNIX_OS true)
|
2017-03-25 23:05:44 +08:00
|
|
|
elseif (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
2019-09-19 09:00:59 +08:00
|
|
|
add_definitions("-Wno-invalid-source-encoding")
|
2019-09-18 17:10:49 +08:00
|
|
|
add_definitions("-O2")
|
2017-07-11 15:18:41 +08:00
|
|
|
set(UNIX_OS true)
|
2019-09-19 09:00:59 +08:00
|
|
|
elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
2019-09-18 17:10:49 +08:00
|
|
|
add_definitions("-O2")
|
2017-03-31 23:04:16 +08:00
|
|
|
set(UNIX_OS true)
|
2019-09-19 09:00:59 +08:00
|
|
|
elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
|
|
|
|
add_definitions("-Wno-invalid-source-encoding")
|
2019-09-30 14:19:27 +08:00
|
|
|
# add_definitions("-fvisibility=hidden")
|
|
|
|
# add_definitions("-fvisibility-inlines-hidden")
|
2019-09-30 11:46:56 +08:00
|
|
|
add_definitions("-fdata-sections -ffunction-sections")
|
|
|
|
add_definitions("-flto")
|
2019-09-18 17:10:49 +08:00
|
|
|
add_definitions("-Os")
|
2019-09-19 09:00:59 +08:00
|
|
|
set(UNIX_OS true)
|
2017-03-31 23:04:16 +08:00
|
|
|
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
|
|
|
|
set(WIN_OS true)
|
2017-02-12 21:39:38 +08:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "unknown CMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
set(acl_path ${CMAKE_CURRENT_SOURCE_DIR}/../lib_acl)
|
|
|
|
set(acl_include ${acl_path}/include)
|
|
|
|
|
|
|
|
include_directories(
|
|
|
|
${acl_include}
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
|
|
)
|
|
|
|
|
|
|
|
set(src ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
|
|
|
set(sources
|
|
|
|
${src}
|
|
|
|
${src}/http
|
|
|
|
${src}/smtp
|
|
|
|
${src}/icmp
|
|
|
|
)
|
|
|
|
|
2017-03-25 23:05:44 +08:00
|
|
|
foreach (iter ${sources})
|
2017-02-12 21:39:38 +08:00
|
|
|
aux_source_directory(${iter} lib_src)
|
|
|
|
endforeach()
|
|
|
|
|
2017-03-31 23:04:16 +08:00
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
if (${UNIX_OS})
|
|
|
|
add_definitions(
|
|
|
|
"-W"
|
|
|
|
"-fPIC"
|
|
|
|
"-Wall"
|
|
|
|
"-Werror"
|
|
|
|
"-Wshadow"
|
|
|
|
"-Wpointer-arith"
|
|
|
|
"-Waggregate-return"
|
|
|
|
"-Wmissing-prototypes"
|
|
|
|
"-D_REENTRANT"
|
|
|
|
"-D_USE_FAST_MACRO"
|
|
|
|
"-DACL_WRITEABLE_CHECK"
|
|
|
|
"-Wno-long-long"
|
|
|
|
"-Wuninitialized"
|
|
|
|
"-D_POSIX_PTHREAD_SEMANTICS"
|
|
|
|
"-DACL_PREPARE_COMPILE"
|
|
|
|
"-Wstrict-prototypes"
|
|
|
|
)
|
|
|
|
|
2019-09-06 11:27:36 +08:00
|
|
|
# if (CMAKE_BUILD_TYPE STREQUAL "")
|
|
|
|
# set(CMAKE_BUILD_TYPE "DEBUG")
|
|
|
|
# else()
|
|
|
|
# string(TOUPPER CMAKE_BUILD_TYPE CMAKE_BUILD_TYPE)
|
|
|
|
# endif()
|
2017-03-31 23:04:16 +08:00
|
|
|
|
2019-09-18 17:10:49 +08:00
|
|
|
if (!CMAKE_BUILD_TYPE STREQUAL "RELEASE")
|
2017-03-31 23:04:16 +08:00
|
|
|
add_definitions("-g")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
elseif (${WIN_OS})
|
|
|
|
add_definitions(
|
|
|
|
"-Yc"
|
2018-03-30 14:35:34 +08:00
|
|
|
"-D_WINSOCK_DEPRECATED_NO_WARNINGS"
|
2017-03-31 23:04:16 +08:00
|
|
|
"-DACL_WRITEABLE_CHECK"
|
|
|
|
"-DACL_PREPARE_COMPILE")
|
|
|
|
endif()
|
|
|
|
|
2017-03-25 23:05:44 +08:00
|
|
|
if (CMAKE_SYSTEM_NAME MATCHES "Android")
|
2019-09-19 09:00:59 +08:00
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "-shared -flto")
|
2019-06-28 16:36:00 +08:00
|
|
|
|
2019-08-27 15:18:31 +08:00
|
|
|
set(lib_output_path ${CMAKE_CURRENT_SOURCE_DIR}/../android/lib/${ANDROID_ABI})
|
2019-06-28 16:36:00 +08:00
|
|
|
set(LIBRARY_OUTPUT_PATH ${lib_output_path})
|
|
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${lib_output_path})
|
2019-08-21 17:35:56 +08:00
|
|
|
|
|
|
|
add_library(protocol_static STATIC ${lib_src})
|
|
|
|
SET_TARGET_PROPERTIES(protocol_static PROPERTIES OUTPUT_NAME "protocol")
|
2019-06-28 16:36:00 +08:00
|
|
|
link_directories(${lib_output_path})
|
2017-03-25 23:05:44 +08:00
|
|
|
else()
|
2017-02-12 21:39:38 +08:00
|
|
|
set(lib_output_path ${PROJECT_BINARY_DIR}/lib)
|
|
|
|
set(LIBRARY_OUTPUT_PATH ${lib_output_path})
|
2019-08-27 15:18:31 +08:00
|
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${lib_output_path})
|
2017-02-12 21:39:38 +08:00
|
|
|
|
2019-09-30 14:19:27 +08:00
|
|
|
add_library(protocol_static STATIC ${lib_src})
|
|
|
|
SET_TARGET_PROPERTIES(protocol_static PROPERTIES OUTPUT_NAME "protocol")
|
2017-03-31 23:04:16 +08:00
|
|
|
if (${UNIX_OS})
|
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "-shared -Wl,-rpath,. -L${lib_output_path} -lacl")
|
2019-09-30 14:19:27 +08:00
|
|
|
target_compile_options(protocol_static PRIVATE
|
|
|
|
-fvisibility=hidden
|
|
|
|
-fvisibility-inlines-hidden)
|
2017-03-31 23:04:16 +08:00
|
|
|
elseif (${WIN_OS})
|
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "/DYNAMICBASE ws2_32.lib")
|
|
|
|
endif()
|
|
|
|
|
2017-02-12 21:39:38 +08:00
|
|
|
link_directories(${lib_output_path})
|
|
|
|
endif()
|
|
|
|
|
2017-03-25 23:05:44 +08:00
|
|
|
if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
|
|
|
add_library(protocol SHARED ${lib_src})
|
|
|
|
target_link_libraries(protocol acl)
|
2017-02-12 21:39:38 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
##############################################################################
|