title: How to create both static and shared libraries at one go using CMake?
body: <p>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.</p>
  <p>Could someone please help me how to proceed with that?</p>
  <p>Below is my existing script for the static library:</p>
  <pre><code>include(bundle_static_library.cmake)
  
  set(BINARY camsdk)
  
  set(CMAKE_VERBOSE_MAKEFILE ON)
  
  include_directories(&quot;../../OpenSource/boost_1_75_0&quot;)
  if(CMAKE_HOST_WIN32)
  add_definitions(-DBOOST_DATE_TIME_NO_LIB)
  endif()
  include_directories(Include)
  include_directories(&quot;../Dependencies/CamSupport/h&quot;)
  
  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 &quot;Debug&quot;)
      set(BUILD_TYPE &quot;debug&quot;)
  else()
      set(BUILD_TYPE &quot;release&quot;)
  endif() 
  
  if(${CMAKE_SYSTEM_NAME} STREQUAL &quot;Darwin&quot;)
      set(PLATFORM &quot;macos&quot;)
  elseif(${CMAKE_SYSTEM_NAME} STREQUAL &quot;Windows&quot;)
      set(PLATFORM &quot;windows&quot;)
  else()
      set(PLATFORM &quot;linux&quot;)
  endif()
  
  # We depend on another static library EMR
  add_library(EMR STATIC IMPORTED)
  if(${CMAKE_SYSTEM_NAME} STREQUAL &quot;Windows&quot;)
      if(NOT CMAKE_CL_64)
          message(STATUS &quot;Architecture: x86&quot;)
          set_property(TARGET EMR PROPERTY IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/Library/emr/lib/${PLATFORM}-x86-${BUILD_TYPE}-static/testemr-cc.lib)
      else()
          message(STATUS &quot;Architecture: x64&quot;)
          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})
  </code></pre>