In my project, static library is created using cmake. But now i wanted to change it to create and support both static and shared libraries.
Could someone please help me how to proceed with that?
Below is my existing script for the static library:
include(bundle_static_library.cmake)
set(BINARY camsdk)
set(CMAKE_VERBOSE_MAKEFILE ON)
include_directories("../../OpenSource/boost_1_75_0")
if(CMAKE_HOST_WIN32)
add_definitions(-DBOOST_DATE_TIME_NO_LIB)
endif()
include_directories(Include)
include_directories("../Dependencies/CamSupport/h")
file(GLOB_RECURSE SOURCES LIST_DIRECTORIES true *.h *.cpp)
set(SOURCES
${SOURCES}
${CMAKE_CURRENT_LIST_DIR}/../CamVisionLibrary/Source/VisionClient.cpp)
if(CMAKE_HOST_UNIX)
add_compile_options(-fpic -Wall -Werror)
add_definitions(-DBOOST_UUID_RANDOM_PROVIDER_FORCE_POSIX)
elseif(CMAKE_HOST_WIN32)
# all warnings as errors
add_compile_options(/W4 /WX)
add_definitions(-D_UNICODE -DUNICODE)
endif ()
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set(BUILD_TYPE "debug")
else()
set(BUILD_TYPE "release")
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(PLATFORM "macos")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set(PLATFORM "windows")
else()
set(PLATFORM "linux")
endif()
# We depend on another static library EMR
add_library(EMR STATIC IMPORTED)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
if(NOT CMAKE_CL_64)
message(STATUS "Architecture: x86")
set_property(TARGET EMR PROPERTY IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/Library/emr/lib/${PLATFORM}-x86-${BUILD_TYPE}-static/testemr-cc.lib)
else()
message(STATUS "Architecture: x64")
set_property(TARGET EMR PROPERTY IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/Library/emr/lib/${PLATFORM}-x64-${BUILD_TYPE}-static/testemr-cc.lib)
endif()
else()
set_property(TARGET EMR PROPERTY IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/Library/emr/lib/${PLATFORM}-x64-${BUILD_TYPE}-static/libtestemr-cc.a)
endif()
# First build a temporary library
set(TMP_BINARY camsdk-tmp)
add_library(${TMP_BINARY} STATIC ${SOURCES})
target_link_libraries(${TMP_BINARY} PUBLIC EMR)
bundle_static_library(${TMP_BINARY} ${BINARY})