summaryrefslogtreecommitdiffstats
path: root/src/cmake/crypto_engines.cmake
blob: ae8214621b10a7ece18bb28be125ce3092801f4a (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
# Copyright (c) 2018 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

macro(add_vpp_crypto_engine name)
  cmake_parse_arguments(CRYPTO_ENGINE
    ""
    "LINK_FLAGS;COMPONENT;DEV_COMPONENT"
    "SOURCES;LINK_LIBRARIES;SUPPORTED_OS_LIST"
    ${ARGN}
  )
  if (CRYPTO_ENGINE_SUPPORTED_OS_LIST AND NOT ${CMAKE_SYSTEM_NAME} IN_LIST CRYPTO_ENGINE_SUPPORTED_OS_LIST)
    message(WARNING "unsupported OS - ${name} crypto engine disabled")
    return()
  endif()
  set(crypto_engine_name ${name}_crypto_engine)
  if(NOT CRYPTO_ENGINE_COMPONENT)
    set(CRYPTO_ENGINE_COMPONENT vpp-crypto-engines)
  endif()
  if(NOT CRYPTO_ENGINE_DEV_COMPONENT)
    if(NOT VPP_EXTERNAL_PROJECT)
      set(CRYPTO_ENGINE_DEV_COMPONENT vpp-dev)
    else()
      set(CRYPTO_ENGINE_DEV_COMPONENT ${CRYPTO_ENGINE_COMPONENT}-dev)
    endif()
  endif()

  add_library(${crypto_engine_name} SHARED ${CRYPTO_ENGINE_SOURCES})
  target_compile_options(${crypto_engine_name} PUBLIC ${VPP_DEFAULT_MARCH_FLAGS})
  set_target_properties(${crypto_engine_name} PROPERTIES NO_SONAME 1)
  target_compile_options(${crypto_engine_name} PRIVATE "-fvisibility=hidden")
  target_compile_options (${crypto_engine_name} PRIVATE "-ffunction-sections")
  target_compile_options (${crypto_engine_name} PRIVATE "-fdata-sections")
  target_link_libraries (${crypto_engine_name} "-Wl,--gc-sections")
  set(deps "")
  if(NOT VPP_EXTERNAL_PROJECT)
    list(APPEND deps vpp_version_h)
  endif()
  if(deps)
    add_dependencies(${crypto_engine_name} ${deps})
  endif()
  set_target_properties(${crypto_engine_name} PROPERTIES
    PREFIX ""
    LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/vpp_crypto_engines)
  if(CRYPTO_ENGINE_LINK_LIBRARIES)
    target_link_libraries(${crypto_engine_name} ${CRYPTO_ENGINE_LINK_LIBRARIES})
  endif()
  if(CRYPTO_ENGINE_LINK_FLAGS)
    set_target_properties(${crypto_engine_name} PROPERTIES LINK_FLAGS "${CRYPTO_ENGINE_LINK_FLAGS}")
  endif()

  install(
    TARGETS ${crypto_engine_name}
    DESTINATION ${VPP_LIBRARY_DIR}/vpp_crypto_engines
    COMPONENT ${CRYPTO_ENGINE_COMPONENT}
  )
endmacro()

macro(vpp_crypto_engine_find_library n var name)
  find_library(${var} NAMES ${name} ${ARGN})
  mark_as_advanced(${var})
if (NOT ${var})
  message(WARNING "-- ${name} library not found - ${n} crypto engine disabled")
  return()
endif()
    message(STATUS "${n} crypto engine needs ${name} library - found at ${${var}}")
endmacro()