AMQP-CPP/CMakeLists.txt

95 lines
2.7 KiB
CMake
Raw Normal View History

2018-01-25 01:22:11 +08:00
# Builds AMQP-CPP
#
# Options:
#
# - BUILD_SHARED (default OFF)
# ON: Build shared lib
# OFF: Build static lib
#
# - LINUX_TCP (default OFF)
# ON: Build posix handler implementation
# OFF: Don't build posix handler implementation
cmake_minimum_required(VERSION 3.1)
2018-01-24 01:58:51 +08:00
# project name
project(amqpcpp)
# build options
option(BUILD_SHARED "Build shared library. If off, build will be static." OFF)
option(LINUX_TCP "Build linux sockets implementation." OFF)
# ensure c++11 on all compilers
set (CMAKE_CXX_STANDARD 11)
2018-01-25 01:22:11 +08:00
# add source files
# ------------------------------------------------------------------------------------------------------
# set include/ as include directory
include_directories(${CMAKE_SOURCE_DIR}/include)
2018-01-25 01:22:11 +08:00
# macro that adds a list of provided source files to a list called SRCS.
# if variable SRCS does not yet exist, it is created.
macro (add_sources)
file (RELATIVE_PATH _relPath "${PROJECT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
foreach (_src ${ARGN})
if (_relPath)
list (APPEND SRCS "${_relPath}/${_src}")
else()
list (APPEND SRCS "${_src}")
endif()
endforeach()
if (_relPath)
# propagate SRCS to parent directory
set (SRCS ${SRCS} PARENT_SCOPE)
endif()
endmacro()
# add source files
add_subdirectory(src)
if(LINUX_TCP)
add_subdirectory(src/linux_tcp)
endif()
2018-01-25 01:22:11 +08:00
# settings for specific compilers
# ------------------------------------------------------------------------------------------------------
2018-01-24 09:09:44 +08:00
# we have to prevent windows from defining the max macro. TODO why WIN32_LEAN_AND_MEAN?
if (WIN32)
add_definitions(-DNOMINMAX -DWIN32_LEAN_AND_MEAN)
endif()
2018-01-25 01:22:11 +08:00
# build targets
# ------------------------------------------------------------------------------------------------------
# set output directory
set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)
if(BUILD_SHARED)
2018-01-25 01:22:11 +08:00
# create shared lib
add_library(${PROJECT_NAME} SHARED ${SRCS})
2018-01-25 01:22:11 +08:00
# set shared lib version
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION 2.8)
else()
# create static lib
add_library(${PROJECT_NAME} STATIC ${SRCS})
endif()
# install rules
# ------------------------------------------------------------------------------------------------------
if(BUILD_SHARED)
# copy static lib
install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION lib
)
else()
2018-01-25 01:22:11 +08:00
# copy shared lib and its static counter part
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib
)
endif()
2018-01-25 01:22:11 +08:00
# copy header files
install(DIRECTORY include/amqpcpp DESTINATION include/amqpcpp
FILES_MATCHING PATTERN "*.h")
2018-01-25 01:22:11 +08:00
install(FILES amqpcpp.h DESTINATION include)