aboutsummaryrefslogtreecommitdiff
path: root/cmake/modules/PaludisAddLibrary.cmake
blob: d57666c264116f1602c21cd9e6638ac70fdea7f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
include(CMakeParseArguments)
include(PaludisGeneratorUtils)

function(paludis_add_library library_name)
  set(options SHARED_LIBRARY STATIC_LIBRARY OBJECT_LIBRARY UNVERSIONED)
  set(single_value_args)
  set(multiple_value_args NN_SOURCES SE_SOURCES INCORPORATE_OBJECT_LIBRARIES)

  cmake_parse_arguments(PAL "${options}" "${single_value_args}" "${multiple_value_args}" ${ARGN})

  if(PAL_STATIC_LIBRARY AND PAL_OBJECT_LIBRARY)
    message(SEND_ERROR "paludis_add_library(${library_name}) called with STATIC_LIBRARY and OBJECT_LIBRARY")
  endif()

  if(PAL_STATIC_LIBRARY)
    set(libkind STATIC)
  elseif(PAL_OBJECT_LIBRARY)
    set(libkind OBJECT)
  elseif(PAL_SHARED_LIBRARY)
    set(libkibd SHARED)
  else()
    set(libkind)
  endif()

  set(nnsources)
  set(nndependencies)
  foreach(nn_source ${PAL_NN_SOURCES})
    get_filename_component(nnname ${nn_source} NAME_WE)
    paludis_nnprocess(${nn_source}
                      HEADER_TARGET
                        ${nnname}_HEADER_TARGET
                      SOURCE_TARGET
                        ${nnname}_SOURCE_TARGET
                      SOURCE_FILE
                        ${nnname}_SOURCE_FILE)
    list(APPEND nnsources ${${nnname}_SOURCE_FILE})
    list(APPEND nndependencies ${${nnname}_HEADER_TARGET};${${nnname}_SOURCE_TARGET})
  endforeach()
  add_custom_target(${library_name}_NN
                    DEPENDS
                      ${nndependencies})

  set(sedependencies)
  foreach(se_source ${PAL_SE_SOURCES})
    paludis_seprocess(${se_source}
                      HEADER_TARGET
                        ${se_source}_HEADER_TARGET
                      SOURCE_TARGET
                        ${se_source}_SOURCE_TARGET)
    list(APPEND sedependencies ${${se_source}_HEADER_TARGET};${${se_source}_SOURCE_TARGET})
  endforeach()
  add_custom_target(${library_name}_SE
                    DEPENDS
                      ${sedependencies})

  set(object_libraries_expressions)
  foreach(library ${PAL_INCORPORATE_OBJECT_LIBRARIES})
    list(APPEND object_libraries_expressions $<TARGET_OBJECTS:${library}>)
  endforeach()

  add_library(${library_name}
              ${libkind}
                ${PAL_UNPARSED_ARGUMENTS}
                ${object_libraries_expressions}
                ${nnsources})
  if(nndependencies)
    add_dependencies(${library_name} ${nndependencies})
  endif()
  if(sedependencies)
    add_dependencies(${library_name} ${sedependencies})
  endif()

  if(NOT PAL_OBJECT_LIBRARY)
    get_target_property(libkind ${library_name} TYPE)
    string(REGEX REPLACE "^lib" "" output_name ${library_name})
    set(output_name ${output_name}_${PALUDIS_PKG_CONFIG_SLOT})
    set_target_properties(${library_name} PROPERTIES OUTPUT_NAME ${output_name})
  endif()

  if("${libkind}" STREQUAL "SHARED_LIBRARY" AND NOT PAL_UNVERSIONED)
    math(EXPR version_major "${PROJECT_VERSION_MAJOR} * 100 + ${PROJECT_VERSION_MINOR}")
    set_target_properties(${library_name}
                          PROPERTIES
                            VERSION
                              "${version_major}.${PROJECT_VERSION_PATCH}.0"
                            SOVERSION
                              "${version_major}")
  endif()
endfunction()