Commit 92b6ef1c authored by Ghislain MARY's avatar Ghislain MARY

Allow building both shared and static libraries with CMake.

parent ba12aea5
......@@ -21,17 +21,18 @@
############################################################################
cmake_minimum_required(VERSION 3.0)
project(ORTP)
project(oRTP VERSION 0.26.0)
set(ORTP_MAJOR_VERSION "0")
set(ORTP_MINOR_VERSION "26")
set(ORTP_MICRO_VERSION "0")
set(ORTP_VERSION "${ORTP_MAJOR_VERSION}.${ORTP_MINOR_VERSION}.${ORTP_MICRO_VERSION}")
set(ORTP_MAJOR_VERSION ${PROJECT_VERSION_MAJOR})
set(ORTP_MINOR_VERSION ${PROJECT_VERSION_MINOR})
set(ORTP_MICRO_VERSION ${PROJECT_VERSION_PATCH})
set(ORTP_VERSION ${PROJECT_VERSION})
set(ORTP_SO_VERSION "11") # incremented on January, the 20th 2015. DO NOT INCREMENT BEFORE ORTP 0.26
option(ENABLE_STATIC "Build static library (default is shared library)." NO)
option(ENABLE_SHARED "Build shared library." YES)
option(ENABLE_STATIC "Build static library." YES)
option(ENABLE_DOC "Enable documentation generation with Doxygen." YES)
option(ENABLE_NTP_TIMESTAMP "Turn on NTP timestamping on packet reception." NO)
option(ENABLE_PERF "Disable costly features to reduce cpu consumtion and increase performance." NO)
......@@ -57,10 +58,14 @@ macro(apply_compile_flags SOURCE_FILES)
endmacro()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_PREFIX_PATH}/share/cmake/Modules)
include(CheckIncludeFile)
include(CheckFunctionExists)
include(GNUInstallDirs)
if(NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
message(STATUS "Setting install rpath to ${CMAKE_INSTALL_RPATH}")
endif()
set(MSVC_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/MSVC")
if(MSVC)
......@@ -170,7 +175,7 @@ if(ENABLE_DOC)
)
add_custom_target(ortp-html-doc ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/doc/html/index.html")
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doc/html"
DESTINATION "share/doc/oRTP-${ORTP_VERSION}")
DESTINATION "${CMAKE_INSTALL_DATADIR}/doc/oRTP-${ORTP_VERSION}")
endif()
endif()
......@@ -185,7 +190,7 @@ set(ORTP_PKGCONFIG_VERSION "${ORTP_VERSION}")
set(ORTPDEPS_LIBS )
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ortp.pc.in ${CMAKE_CURRENT_BINARY_DIR}/ortp.pc)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ortp.pc DESTINATION lib/pkgconfig)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ortp.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
include(CMakePackageConfigHelpers)
......@@ -202,13 +207,13 @@ configure_file(ORTPConfig.cmake.in
@ONLY
)
set(ConfigPackageLocation lib/cmake/oRTP)
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE ORTPTargets.cmake
DESTINATION ${ConfigPackageLocation}
DESTINATION ${CONFIG_PACKAGE_LOCATION}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/ORTPConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/ORTPConfigVersion.cmake"
DESTINATION ${ConfigPackageLocation}
DESTINATION ${CONFIG_PACKAGE_LOCATION}
)
......@@ -44,5 +44,5 @@ endforeach()
set(ORTP_HEADER_FILES ${ORTP_HEADER_FILES} PARENT_SCOPE)
install(FILES ${ORTP_HEADER_FILES}
DESTINATION include/ortp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ortp
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
......@@ -83,28 +83,37 @@ endif()
apply_compile_flags(ORTP_SOURCE_FILES_C "CPP" "C")
apply_compile_flags(ORTP_SOURCE_FILES_CXX "CPP" "CXX")
add_library(ortp-objects OBJECT ${ORTP_HEADER_FILES} ${ORTP_SOURCE_FILES_C} ${ORTP_SOURCE_FILES_CXX})
set_target_properties(ortp-objects PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
if(ENABLE_STATIC)
add_library(ortp STATIC ${ORTP_HEADER_FILES} ${ORTP_SOURCE_FILES_C} ${ORTP_SOURCE_FILES_CXX})
else()
add_library(ortp SHARED ${ORTP_HEADER_FILES} ${ORTP_SOURCE_FILES_C} ${ORTP_SOURCE_FILES_CXX})
add_library(ortp-static STATIC $<TARGET_OBJECTS:ortp-objects>)
set_target_properties(ortp-static PROPERTIES OUTPUT_NAME ortp)
target_link_libraries(ortp-static ${LIBS})
install(TARGETS ortp-static EXPORT ${EXPORT_TARGETS_NAME}Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
if(ENABLE_SHARED)
add_library(ortp SHARED $<TARGET_OBJECTS:ortp-objects>)
set_target_properties(ortp PROPERTIES VERSION ${ORTP_SO_VERSION})
target_link_libraries(ortp ${LIBS})
if(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Debug/ortp.pdb
DESTINATION bin
DESTINATION ${CMAKE_INSTALL_BINDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
endif()
install(TARGETS ortp EXPORT ${EXPORT_TARGETS_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
target_link_libraries(ortp ${LIBS})
install(TARGETS ortp EXPORT ${EXPORT_TARGETS_NAME}Targets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
if(ENABLE_TESTS)
#add_subdirectory(tests)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment