Commit bcade61e authored by Ghislain MARY's avatar Ghislain MARY

Enable build of both shared and static libraries.

parent 1bbca651
......@@ -21,7 +21,7 @@
############################################################################
cmake_minimum_required(VERSION 3.0)
project(BCTOOLBOX C CXX)
project(BCTOOLBOX LANGUAGES C CXX)
set(PACKAGE "bctoolbox")
set(PACKAGE_NAME ${PACKAGE})
......@@ -35,7 +35,8 @@ set(PACKAGE_TARNAME "bctoolbox")
set(PACKAGE_URL "")
set(VERSION "${PACKAGE_VERSION}")
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_POLARSSL "Enable polarssl support" ON)
option(ENABLE_MBEDTLS "Enable mabedtls support" ON)
......@@ -141,17 +142,6 @@ if(APPLE)
endif()
endif()
string(REPLACE ";" " " LINK_FLAGS_STR "${LINK_FLAGS}")
if(WIN32)
add_definitions(
-DBCTOOLBOX_EXPORTS
-DBCTOOLBOX_INTERNAL_EXPORTS
)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone")
add_definitions(
-DHAVE_COMPILER_TLS
)
endif()
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
......@@ -191,4 +181,3 @@ install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/BcToolboxConfigVersion.cmake"
DESTINATION ${ConfigPackageLocation}
)
......@@ -32,8 +32,10 @@ if(POLARSSL_FOUND)
endif()
if(ENABLE_STATIC)
add_library(bctoolbox STATIC ${BCTOOLBOX_HEADER_FILES} ${BCTOOLBOX_SOURCE_FILES})
else()
add_library(bctoolbox-static STATIC ${BCTOOLBOX_HEADER_FILES} ${BCTOOLBOX_SOURCE_FILES})
set_target_properties(bctoolbox-static PROPERTIES OUTPUT_NAME bctoolbox)
endif()
if(ENABLE_SHARED)
add_library(bctoolbox SHARED ${BCTOOLBOX_HEADER_FILES} ${BCTOOLBOX_SOURCE_FILES})
set_target_properties(bctoolbox PROPERTIES VERSION 0.0.0 SOVERSION 0)
set_target_properties(bctoolbox PROPERTIES LINKER_LANGUAGE "CXX")
......@@ -49,19 +51,38 @@ endif()
if(MBEDTLS_FOUND)
target_include_directories(bctoolbox PUBLIC ${MBEDTLS_INCLUDE_DIRS})
target_link_libraries(bctoolbox ${MBEDTLS_LIBRARIES})
if(ENABLE_STATIC)
target_include_directories(bctoolbox-static PUBLIC ${MBEDTLS_INCLUDE_DIRS})
target_link_libraries(bctoolbox-static ${MBEDTLS_LIBRARIES})
endif()
if(ENABLE_SHARED)
target_include_directories(bctoolbox PUBLIC ${MBEDTLS_INCLUDE_DIRS})
target_link_libraries(bctoolbox ${MBEDTLS_LIBRARIES})
endif()
endif()
if(POLARSSL_FOUND)
target_include_directories(bctoolbox PUBLIC ${POLARSSL_INCLUDE_DIRS})
target_link_libraries(bctoolbox ${POLARSSL_LIBRARIES})
if(ENABLE_STATIC)
target_include_directories(bctoolbox-static PUBLIC ${POLARSSL_INCLUDE_DIRS})
target_link_libraries(bctoolbox-static ${POLARSSL_LIBRARIES})
endif()
if(ENABLE_SHARED)
target_include_directories(bctoolbox PUBLIC ${POLARSSL_INCLUDE_DIRS})
target_link_libraries(bctoolbox ${POLARSSL_LIBRARIES})
endif()
endif()
install(TARGETS bctoolbox 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
)
if(ENABLE_STATIC)
install(TARGETS bctoolbox-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)
install(TARGETS bctoolbox 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()
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