Blame view

library.cmake 1.27 KB
6048802d   Peter M. Groen   Add switch for bu...
1
2
  # @brief Adds a single shared or static library target and performs related actions,
  # such as target properties and some packaging variables.
772ec5a4   Peter M. Groen   Added cmake envir...
3
4
5
6
7
8
9
10
11
12
13
14
  # @note The default binary directory is CMAKE_BINARY_DIR, but can be overridden by specifying the ${PROJECT_NAME}_CURRENT_BINARY_DIR.
  function(add_libraries)
  
  message( STATUS "${PROJECT_NAME} linking libraries : ${ARGN}")
  
  # Use CMAKE_BINARY_DIR by default, but override if necessary.
  set(CURRENT_PROJECT_BINARY_DIR ${CMAKE_BINARY_DIR})
  if (${PROJECT_NAME}_CURRENT_BINARY_DIR)
      set(CURRENT_PROJECT_BINARY_DIR ${${PROJECT_NAME}_CURRENT_BINARY_DIR})
  endif()
  message(STATUS "CURRENT_PROJECT_BINARY_DIR : ${CURRENT_PROJECT_BINARY_DIR}")
  
6048802d   Peter M. Groen   Add switch for bu...
15
16
17
18
19
20
21
22
23
  if(DEFINED ${BUILD_STATIC})
      if(${BUILD_STATIC} STREQUAL "ON")
          set(SHARED_OR_STATIC "STATIC")
      else()
          set(SHARED_OR_STATIC "SHARED")
      endif()
  else()
      set(SHARED_OR_STATIC "SHARED")
  endif()
772ec5a4   Peter M. Groen   Added cmake envir...
24
  
6048802d   Peter M. Groen   Add switch for bu...
25
  add_library( ${PROJECT_NAME} ${SHARED_OR_STATIC}
772ec5a4   Peter M. Groen   Added cmake envir...
26
27
28
29
30
31
32
33
34
35
36
37
      ${SRC_LIST}
  )
  
  target_link_libraries( ${PROJECT_NAME}
      ${ARGN}
  )
  
  set_target_properties( ${PROJECT_NAME}
      PROPERTIES
          VERSION ${PROJECT_VERSION}
          SOVERSION ${PROJECT_VERSION_MAJOR}
          LIBRARY_OUTPUT_DIRECTORY ${CURRENT_PROJECT_BINARY_DIR}/lib
6048802d   Peter M. Groen   Add switch for bu...
38
          ARCHIVE_OUTPUT_DIRECTORY ${CURRENT_PROJECT_BINARY_DIR}/lib
772ec5a4   Peter M. Groen   Added cmake envir...
39
40
41
  )
  
  endfunction()