set(SH4LT_LIBRARY_FILES
  c/cfollower.cpp
  c/clogger.cpp
  c/cshtype.cpp
  c/cwriter.cpp
  follower.cpp
  infotree/information-tree.cpp
  infotree/json-serializer.cpp
  infotree/key-val-serializer.cpp
  ipcs/file-monitor.cpp
  ipcs/reader.cpp
  ipcs/sysv-sem.cpp
  ipcs/sysv-shm.cpp
  ipcs/unix-socket-client.cpp
  ipcs/unix-socket-protocol.cpp
  ipcs/unix-socket-server.cpp
  ipcs/unix-socket.cpp
  jsoncpp/jsoncpp.cpp
  monitor/dir-watcher.cpp
  monitor/follower-stat.cpp
  monitor/monitor.cpp
  shtype/shtype-from-gst-caps.cpp
  shtype/shtype.cpp
  time.cpp
  utils/any.cpp
  utils/bool-log.cpp
  utils/safe-bool-log.cpp
  utils/scope-exit.hpp
  utils/string-utils.cpp
  writer.cpp
)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_library(${SH4LT_LIBRARY} SHARED
    ${SH4LT_LIBRARY_FILES})
add_library(${SH4LT_LIBRARY}_static STATIC
    ${SH4LT_LIBRARY_FILES})

set(HEADER_DIR_INCLUDES
  c
  infotree
  ipcs
  jsoncpp
  logger
  shtype
  utils
  )

# define SH4LT_VERSION_STRING for Sh4lt shared library 
set_target_properties(${SH4LT_LIBRARY} PROPERTIES VERSION ${SH4LT_VERSION_STRING} SOVERSION ${SH4LT_VERSION_MAJOR})
target_compile_options(${SH4LT_LIBRARY} PUBLIC -DSH4LT_VERSION_STRING="${SH4LT_VERSION_STRING}" )

# define SH4LT_VERSION_STRING for Sh4lt static library 
set_target_properties(${SH4LT_LIBRARY}_static PROPERTIES VERSION ${SH4LT_VERSION_STRING} SOVERSION ${SH4LT_VERSION_MAJOR})
target_compile_options(${SH4LT_LIBRARY}_static PUBLIC -DSH4LT_VERSION_STRING="${SH4LT_VERSION_STRING}" )

# Pkg-config
if (UNIX)
    include(FindPkgConfig QUIET)
    if (PKG_CONFIG_FOUND)
        configure_file("sh4lt.pc.in" "sh4lt-${SH4LT_API_VERSION}.pc" @ONLY)
        # Install Pkg-config file for the 'lib' package
        install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sh4lt-${SH4LT_API_VERSION}.pc"
          COMPONENT lib
          DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
        # Install Pkg-config file for the 'dev' package
        install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sh4lt-${SH4LT_API_VERSION}.pc"
          COMPONENT dev
          DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
        # Install Pkg-config file for the 'dbg' package
        install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sh4lt-${SH4LT_API_VERSION}.pc"
          COMPONENT dbg
          DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
        # install for python packaging with scikit_build
        install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sh4lt-${SH4LT_API_VERSION}.pc"
          DESTINATION .)
    endif ()
endif ()

# install shared library
install(TARGETS ${SH4LT_LIBRARY}
    LIBRARY DESTINATION lib
    COMPONENT lib)

install(TARGETS ${SH4LT_LIBRARY}
    LIBRARY DESTINATION lib
    COMPONENT dev)

install(TARGETS ${SH4LT_LIBRARY}
    LIBRARY DESTINATION lib
    COMPONENT dbg)

# install static library
install(TARGETS ${SH4LT_LIBRARY}_static
    ARCHIVE DESTINATION lib
    COMPONENT dev)

install(TARGETS ${SH4LT_LIBRARY}_static
    ARCHIVE DESTINATION lib
    COMPONENT dbg)

# install headers
install(DIRECTORY .
    DESTINATION include/sh4lt-${SH4LT_API_VERSION}/sh4lt
    COMPONENT dev
    FILES_MATCHING # install only matched files
    PATTERN "*.hpp" # select header files
    PATTERN "*.h" # select header files
    )

  install(DIRECTORY .
    DESTINATION include/sh4lt-${SH4LT_API_VERSION}/sh4lt
    COMPONENT dbg
    FILES_MATCHING # install only matched files
    PATTERN "*.hpp" # select header files
    PATTERN "*.h" # select header files
    )
