Commit a2fa297d authored by Ghislain MARY's avatar Ghislain MARY

Allow building both shared and static libraries with CMake.

parent d953d56a
......@@ -21,11 +21,11 @@
############################################################################
cmake_minimum_required(VERSION 3.0)
project(BZRTP C)
set(BZRTP_VERSION 1.0.3)
project(bzrtp VERSION 1.0.3 LANGUAGES C)
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_STRICT "Build with strict compile options." YES)
option(ENABLE_TESTS "Enable compilation of unit tests." NO)
......@@ -46,6 +46,11 @@ macro(apply_compile_flags SOURCE_FILES)
endmacro()
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()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(MSVC_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/MSVC")
......@@ -53,6 +58,7 @@ if(MSVC)
list(APPEND CMAKE_REQUIRED_INCLUDES ${MSVC_INCLUDE_DIR})
endif()
include(GNUInstallDirs)
include(CheckLibraryExists)
check_library_exists("m" "sqrt" "" HAVE_SQRT)
if(ENABLE_TESTS)
......@@ -137,7 +143,7 @@ endif()
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfigVersion.cmake"
VERSION ${BZRTP_VERSION}
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
......@@ -148,14 +154,13 @@ configure_file(cmake/BZRTPConfig.cmake
COPYONLY
)
set(ConfigPackageLocation lib/cmake/BZRTP)
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE BZRTPTargets.cmake
DESTINATION ${ConfigPackageLocation}
DESTINATION ${CONFIG_PACKAGE_LOCATION}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfigVersion.cmake"
DESTINATION ${ConfigPackageLocation}
DESTINATION ${CONFIG_PACKAGE_LOCATION}
)
......@@ -47,4 +47,3 @@ list(APPEND BZRTP_INCLUDE_DIRS ${BCTOOLBOX_INCLUDE_DIRS})
list(APPEND BZRTP_LIBRARIES ${BCTOOLBOX_LIBRARIES})
set(BZRTP_LIBRARIES bzrtp)
set(BZRTP_FOUND 1)
file(GLOB HEADER_FILES "bzrtp/*.h")
############################################################################
# CMakeLists.txt
# Copyright (C) 2014 Belledonne Communications, Grenoble France
#
############################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
############################################################################
install(FILES ${HEADER_FILES}
DESTINATION include/bzrtp
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
install(FILES bzrtp/bzrtp.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/bzrtp
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
......@@ -28,40 +28,42 @@ set(SOURCE_FILES
stateMachine.c
zidCache.c
)
if (POLARSSL_FOUND)
set(SOURCE_FILES
${SOURCE_FILES}
cryptoPolarssl.c
)
elseif (MBEDTLS_FOUND)
set(SOURCE_FILES
${SOURCE_FILES}
cryptoMbedtls.c
)
if(POLARSSL_FOUND)
list(APPEND SOURCE_FILES cryptoPolarssl.c)
elseif(MBEDTLS_FOUND)
list(APPEND SOURCE_FILES cryptoMbedtls.c)
endif()
apply_compile_flags(SOURCE_FILES "CPP")
add_library(bzrtp-objects OBJECT ${SOURCE_FILES})
set_target_properties(bzrtp-objects PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
if(ENABLE_STATIC)
add_library(bzrtp STATIC ${SOURCE_FILES})
target_link_libraries(bzrtp ${LIBS})
else()
add_library(bzrtp SHARED ${SOURCE_FILES})
add_library(bzrtp-static STATIC $<TARGET_OBJECTS:bzrtp-objets>)
set_target_properties(bzrtp-static PROPERTIES OUTPUT_NAME bzrtp)
target_link_libraries(bzrtp-static ${LIBS})
install(TARGETS bzrtp-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(bzrtp SHARED $<TARGET_OBJECTS:bzrtp-objects>)
set_target_properties(bzrtp PROPERTIES VERSION 0)
target_link_libraries(bzrtp ${LIBS})
if(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Debug/bzrtp.pdb
DESTINATION bin
DESTINATION ${CMAKE_INSTALL_BINDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
endif()
endif()
install(TARGETS bzrtp EXPORT ${EXPORT_TARGETS_NAME}Targets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
install(TARGETS bzrtp 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()
......@@ -25,18 +25,11 @@ set(TEST_SOURCES
bzrtpParserTest.c
bzrtpTest.c
testUtils.c
../src/bzrtp.c
../src/cryptoUtils.c
../src/packetParser.c
../src/pgpwords.c
../src/stateMachine.c
../src/zidCache.c
)
apply_compile_flags(TEST_SOURCES "CPP")
add_executable(bzrtpTest ${TEST_SOURCES})
add_executable(bzrtpTest ${TEST_SOURCES} $<TARGET_OBJECTS:bzrtp-objects>)
set_target_properties(bzrtpTest PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
target_include_directories(bzrtpTest PUBLIC ${CUNIT_INCLUDE_DIR})
target_link_libraries(bzrtpTest ${CUNIT_LIBRARIES} bzrtp)
......
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