|
| 1 | +#=============================================================================== |
| 2 | +# Copyright 2019-2020 Intel Corporation |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +#=============================================================================== |
| 16 | + |
| 17 | +# |
| 18 | +# Intel(R) Integrated Performance Primitives (Intel(R) IPP) Cryptography examples |
| 19 | +# |
| 20 | + |
| 21 | +# List of examples for targets generation |
| 22 | +set(IPPCP_EXAMPLES |
| 23 | + # AES examples |
| 24 | + aes/aes-256-ctr-encryption.cpp |
| 25 | + aes/aes-256-ctr-decryption.cpp |
| 26 | + # RSA SSA-PSS examples |
| 27 | + rsa/rsa-3k-pss-sha384-type1-signature.cpp |
| 28 | + rsa/rsa-1k-pss-sha1-verification.cpp |
| 29 | + # RSA OAEP examples |
| 30 | + rsa/rsa-1k-oaep-sha1-encryption.cpp |
| 31 | + rsa/rsa-1k-oaep-sha1-type2-decryption.cpp |
| 32 | + # RSA MB examples |
| 33 | + rsa_mb/rsa_mb-1k-type1-encryption-decryption.cpp |
| 34 | + # SMS4 examples |
| 35 | + sms4/sms4-128-cbc-encryption.cpp |
| 36 | + sms4/sms4-128-cbc-decryption.cpp |
| 37 | + ) |
| 38 | + |
| 39 | +cmake_policy(SET CMP0003 NEW) |
| 40 | + |
| 41 | +# Custom target to build ALL examples at once |
| 42 | +add_custom_target(ippcp_examples_all) |
| 43 | +set_target_properties(ippcp_examples_all PROPERTIES FOLDER "examples") |
| 44 | + |
| 45 | +function(ippcp_define_example out_target source_file category) |
| 46 | + # Extract file name without directory or longest extension |
| 47 | + get_filename_component(name "${source_file}" NAME_WE) |
| 48 | + # Add suffix for nonpic build |
| 49 | + if (NONPIC_LIB) |
| 50 | + set(suffix "-nonpic") |
| 51 | + endif() |
| 52 | + set(local_target "example_${name}${suffix}") |
| 53 | + # link additional sources if defined in categoryOptions.cmake |
| 54 | + set(additional_sources "${category}_CATEGORY_COMMON_SOURCES") |
| 55 | + add_executable(${local_target} "${source_file}" |
| 56 | + $<$<BOOL:${${additional_sources}}>:${${additional_sources}}>) |
| 57 | + # Static linking with merged lib is only supported |
| 58 | + ippcp_example_set_build_options(${local_target} ${IPPCP_LIB_MERGED}) |
| 59 | + set_target_properties(${local_target} PROPERTIES |
| 60 | + PROJECT_LABEL "(example) ${name}" # Set name of the target in IDE |
| 61 | + FOLDER "examples/${category}" # Group projects in solution folder |
| 62 | + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_OUTPUT_DIR}/$<UPPER_CASE:$<CONFIG>>/examples") # Set output directory for examples in the build folder |
| 63 | + |
| 64 | + # Add a single target to build all examples of the same category (e.g. 'make ippcp_examples_aes') |
| 65 | + set(parent_target ippcp_examples_${category}) |
| 66 | + if(NOT TARGET ${parent_target}) |
| 67 | + add_custom_target(${parent_target}) |
| 68 | + set_target_properties(${parent_target} PROPERTIES FOLDER "examples") |
| 69 | + if(TARGET ippcp_examples_all) |
| 70 | + add_dependencies(ippcp_examples_all ${parent_target}) |
| 71 | + endif() |
| 72 | + endif() |
| 73 | + add_dependencies(${parent_target} ${local_target}) |
| 74 | + set(${out_target} ${local_target} PARENT_SCOPE) |
| 75 | +endfunction() |
| 76 | + |
| 77 | +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_LIST_DIR) |
| 78 | +# Build with standalone library |
| 79 | + cmake_minimum_required(VERSION 3.15) |
| 80 | + |
| 81 | + project("Intel(R) IPP Cryptography Examples" CXX) |
| 82 | + set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE) |
| 83 | + |
| 84 | + option(BUILD_EXAMPLES "Build examples" ON) |
| 85 | + |
| 86 | + list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) |
| 87 | + find_package(IPPCrypto REQUIRED MODULE) |
| 88 | + |
| 89 | + if (NOT IPPCRYPTO_FOUND) |
| 90 | + message(FATAL_ERROR "No Intel(R) IPP Cryptography library found on the system. To build examples with pre-built library, please specify -DIPPCRYPTO_ROOT_DIR=<path> option, where <path> is the path to directory that contains include/ and lib/ folders of Intel(R) IPP Cryptography product.") |
| 91 | + endif() |
| 92 | + |
| 93 | + # Define library to link |
| 94 | + list(GET IPPCRYPTO_LIBRARIES 0 IPPCP_LIB_MERGED) |
| 95 | + # Define include folder |
| 96 | + set(IPP_CRYPTO_INCLUDE_DIR ${IPPCRYPTO_INCLUDE_DIRS}) |
| 97 | + # Define output directory |
| 98 | + if(NOT CMAKE_OUTPUT_DIR) |
| 99 | + set(CMAKE_OUTPUT_DIR "${CMAKE_BINARY_DIR}/.build") |
| 100 | + endif() |
| 101 | +else() |
| 102 | +# Build with library sources |
| 103 | + if(NOT BUILD_EXAMPLES OR NOT MERGED_BLD) |
| 104 | + message(FATAL_ERROR "Only merged library build is currently supported for Intel(R) IPP Cryptography examples. Use -DMERGED_BLD:BOOL=on options.") |
| 105 | + endif() |
| 106 | +endif() |
| 107 | + |
| 108 | +include(examplesBuildOptions.cmake) |
| 109 | + |
| 110 | +foreach(example_filename ${IPPCP_EXAMPLES}) |
| 111 | + # Extract example category from its subdirectory |
| 112 | + get_filename_component(category "${example_filename}" DIRECTORY) |
| 113 | + |
| 114 | + # Source additional options that may exist for category |
| 115 | + include(${category}/categoryOptions.cmake OPTIONAL) |
| 116 | + |
| 117 | + ippcp_define_example(example ${example_filename} ${category}) |
| 118 | +endforeach() |
0 commit comments