Skip to content

Commit

Permalink
Add FindCrypt.cmake module
Browse files Browse the repository at this point in the history
This allows to find libcrypt.so by full path, and avoid being dependent
on the compiler directory search.

Re ECFLOW-1987
  • Loading branch information
marcosbento committed Nov 8, 2024
1 parent e40d0a1 commit 9876f2d
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
12 changes: 12 additions & 0 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,15 @@ if (ENABLE_HTTP_COMPRESSION)
message(FATAL_ERROR "HTTP compression support requested, but zlib was not found")
endif ()
endif ()

# =========================================================================================
# Crypt
# =========================================================================================
ecbuild_info( "Locating Crypt" )

find_package(Crypt)

ecbuild_info( "Crypt details:" )
ecbuild_info( " * Crypt_FOUND : ${Crypt_FOUND}" )
ecbuild_info( " * Crypt_INCLUDE_DIRS : ${Crypt_INCLUDE_DIRS}" )
ecbuild_info( " * Crypt_LIBRARIES : ${Crypt_LIBRARIES}" )
76 changes: 76 additions & 0 deletions cmake/FindCrypt.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#
# Copyright 2009- ECMWF.
#
# This software is licensed under the terms of the Apache Licence version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.
#

# FindCrypt
# ---------
#

#
# Find Crypt library and include dirs
#
# Use this module by invoking find_package with the form:
#
# find_package(Crypt
# [REQUIRED] # Fail with error if library is not found
# )
#
# This module finds headers and libraries, specifying the following variables:
#
# Crypt_FOUND - True if library is found
# Crypt_INCLUDE_DIRS - Include directories to be used
# Crypt_DEFINITIONS - Compiler flags to be used
#
# The following `IMPORTED` targets are also defined:
#
# crypt::crypt - Generic target for the Crypt library
#
#

#
# -----------------------------------------------------------------------------
# Search for include DIRs
# -----------------------------------------------------------------------------

find_path(Crypt_INCLUDE_DIRS
NAMES unistd.h
HINTS
/usr/include)

find_library(Crypt_LIBRARIES
NAMES libcrypt.so
HINTS
/usr/lib)

#
# -----------------------------------------------------------------------------
# Handle find_package() REQUIRED and QUIET parameters
# -----------------------------------------------------------------------------

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Crypt
REQUIRED_VARS
Crypt_INCLUDE_DIRS
Crypt_LIBRARIES)

#
# -----------------------------------------------------------------------------
# Define library as exported targets
# -----------------------------------------------------------------------------

set(NAME "crypt")

add_library(${NAME} INTERFACE IMPORTED GLOBAL)

set_target_properties(${NAME}
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Crypt_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${Crypt_LIBRARIES}")

add_library(crypt::crypt ALIAS crypt)
2 changes: 1 addition & 1 deletion libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ ecbuild_add_library(
Boost::date_time
Boost::program_options
$<$<BOOL:${OPENSSL_FOUND}>:OpenSSL::SSL>
$<$<NOT:$<BOOL:${APPLE}>>:crypt>
$<$<BOOL:${Crypt_FOUND}>:crypt::crypt>
Threads::Threads
DEFINITIONS
CMAKE
Expand Down

0 comments on commit 9876f2d

Please sign in to comment.