/ CMakeLists.txt
CMakeLists.txt
  1  # Licensed under the Apache License, Version 2.0 (the "License");
  2  # you may not use this file except in compliance with the License.
  3  # See the NOTICE file distributed with this work for additional
  4  # information regarding copyright ownership.
  5  # You may obtain a copy of the License at
  6  #
  7  #     http://www.apache.org/licenses/LICENSE-2.0
  8  #
  9  # Unless required by applicable law or agreed to in writing, software
 10  # distributed under the License is distributed on an "AS IS" BASIS,
 11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  # See the License for the specific language governing permissions and
 13  # limitations under the License.
 14  
 15  cmake_minimum_required(VERSION 3.23 FATAL_ERROR)
 16  project(
 17    ltc-plugin
 18    VERSION 0.1
 19    DESCRIPTION "'ltc' is a Le'Sec plugin that leverages libtomcrypt (https://www.libtom.net/LibTomCrypt/)."
 20    LANGUAGES C)
 21  set(CMAKE_C_STANDARD 99)
 22  
 23  # Global CMake stuff we use
 24  
 25  include(GNUInstallDirs)
 26  include(FetchContent)
 27  
 28  # Global facts
 29  
 30  set(LSC_PLUGIN_DIR ${CMAKE_INSTALL_LIBDIR}/LeSec/plugins)
 31  set(LSC_PLUGIN_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
 32  
 33  # Get all the things this project depends on
 34  
 35  find_package(Perl REQUIRED)
 36  find_package(LeUtils REQUIRED)
 37  find_package(LeSecCore REQUIRED)
 38  find_package(LeSecPlugin REQUIRED)
 39  find_package(LeSecApp REQUIRED)
 40  find_package(libtomcrypt QUIET)
 41  if (libtomcrypt_FOUND)
 42    set(LIBTOMCRYPT libtomcrypt)
 43  else()
 44    find_package(PkgConfig)
 45    pkg_check_modules(libtomcrypt REQUIRED IMPORTED_TARGET libtomcrypt)
 46    set(LIBTOMCRYPT PkgConfig::libtomcrypt)
 47  endif()
 48  
 49  # This project's sources
 50  
 51  set(ltc_source
 52    ltc.c
 53    ltc-rand.c
 54    ltc-dh.c
 55    ltc-dsa.c
 56    ltc-rsa.c
 57    ltc-sym-keys.c
 58    ltc-sym-ciphers.c
 59    ltc-stream-ciphers.c
 60    ltc-digests.c
 61    ltc-macs.c
 62  )
 63  
 64  # The static variant of the plugin
 65  add_library(ltc_s STATIC)
 66  target_compile_definitions(ltc_s PRIVATE LTC_STATIC_DEFINE)
 67  set_target_properties(ltc_s PROPERTIES
 68    PREFIX "" OUTPUT_NAME "ltc_s"
 69  )
 70  
 71  # The module variant of the plugin
 72  add_library(ltc MODULE)
 73  set_target_properties(ltc PROPERTIES
 74    PREFIX "" OUTPUT_NAME "ltc" SUFFIX ${LSC_PLUGIN_SUFFIX}
 75  )
 76  
 77  # Specify everything that's common for both the static and the shared libraries
 78  foreach(ltc_lib ltc_s ltc)
 79    target_sources(${ltc_lib}
 80      PRIVATE
 81        ${ltc_source}
 82        # $<TARGET_OBJECTS:leutils>
 83    )
 84    target_compile_definitions(${ltc_lib} PRIVATE
 85      AUTHOR="Le’"
 86      VERSION="${PROJECT_VERSION}"
 87      BUILDTYPE="${CMAKE_BUILD_TYPE}"
 88      # Make sure that LibTomMath is used
 89      LTM_DESC
 90    )
 91    set_target_properties(${ltc_lib}
 92      PROPERTIES
 93        VISIBILITY_INLINES_HIDDEN 1
 94        C_VISIBILITY_PRESET hidden
 95        LINKER_LANGUAGE C
 96    )
 97    target_link_libraries(${ltc_lib}
 98      PRIVATE LeSecCore::lscrypto_s LeSecCore::lscore_s LeSecPlugin::lsplugin_s ${LIBTOMCRYPT})
 99  endforeach()
100  
101  file(GENERATE OUTPUT wrap.sh INPUT wrap.sh.in
102    FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)
103  
104  install(TARGETS ltc_s ltc
105    LIBRARY
106      DESTINATION ${LSC_PLUGIN_DIR}
107      COMPONENT Plugins
108    ARCHIVE
109      DESTINATION ${CMAKE_INSTALL_LIBDIR}
110      COMPONENT Plugins
111  )
112  
113  # Tests
114  enable_testing()
115  add_subdirectory(tests)