Skip to content

Commit

Permalink
Implement BUILD_TR31_TOOL option for CMake build
Browse files Browse the repository at this point in the history
BUILD_TR31_TOOL is ON by default and determines whether the dependencies
for tr31-tool are mandatory as well as whether tr31-tool will be built.
This makes it more explicit whether tr31-tool should be built which may
be useful for when only the libraries are needed.
  • Loading branch information
leonlynch committed Oct 9, 2022
1 parent a8e226e commit c4c9058
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ Dependencies
* [CMake](https://cmake.org/)
* TR-31 library require [MbedTLS](https://github.com/Mbed-TLS/mbedtls)
(preferred), or [OpenSSL](https://www.openssl.org/)
* TR-31 tool requires `argp` (either via Glibc, a system-provided standalone
implementation, or a downloaded implementation;
see [MacOS / Windows](#macos--windows))
* TR-31 tool will be built by default and requires `argp` (either via Glibc, a
system-provided standalone or a downloaded implementation; see
[MacOS / Windows](#macos--windows)). Use the `BUILD_TR31_TOOL` option to
prevent TR-31 tool from being built and avoid the dependency on `argp`.

This project also makes use of sub-projects that can either be provided as
git submodules using `git clone --recurse-submodules`, or provided as CMake
Expand Down
34 changes: 24 additions & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ if(NOT HAVE_ARPA_INET_H AND NOT HAVE_WINSOCK_H)
message(FATAL_ERROR "Failed to find either arpa/inet.h or winsock.h")
endif()

# build TR-31 tool by default
option(BUILD_TR31_TOOL "Build tr31-tool" ON)

# check for argp or allow the FETCH_ARGP option to download and build a local
# copy of libargp for monolithic builds on platforms without package managers
# like MacOS and Windows.
Expand All @@ -32,7 +35,9 @@ else()
find_package(argp)
endif()
if(NOT argp_FOUND)
message(FATAL_ERROR "Could NOT find argp on target system. Enable FETCH_ARGP to download and build libargp.")
if(BUILD_TR31_TOOL)
message(FATAL_ERROR "Could NOT find argp. Enable FETCH_ARGP to download and build libargp. This is required to build tr31-tool.")
endif()
endif()

include(GNUInstallDirs) # provides CMAKE_INSTALL_* variables and good defaults for install()
Expand Down Expand Up @@ -62,21 +67,13 @@ if(HAVE_WINSOCK_H AND NOT HAVE_ARPA_INET_H)
target_link_libraries(tr31 PRIVATE ws2_32)
endif()

# TR-31 command line tool
add_executable(tr31-tool tr31-tool.c)
target_link_libraries(tr31-tool PRIVATE tr31)
if(TARGET libargp::argp)
target_link_libraries(tr31-tool PRIVATE libargp::argp)
endif()

install(
TARGETS
crypto_tdes
crypto_aes
crypto_mem
crypto_rand
tr31
tr31-tool
EXPORT tr31Targets # for use by install(EXPORT) command
PUBLIC_HEADER
DESTINATION "include/${PROJECT_NAME}"
Expand All @@ -90,7 +87,24 @@ install(
COMPONENT tr31_development
)

if(TR31_IS_TOP_LEVEL AND BUILD_TESTING)
# TR-31 command line tool
if(BUILD_TR31_TOOL)
add_executable(tr31-tool tr31-tool.c)
target_link_libraries(tr31-tool PRIVATE tr31)
if(TARGET libargp::argp)
target_link_libraries(tr31-tool PRIVATE libargp::argp)
endif()

install(
TARGETS
tr31-tool
EXPORT tr31Targets # for use by install(EXPORT) command
RUNTIME
COMPONENT tr31_runtime
)
endif()

if(TARGET tr31-tool AND BUILD_TESTING)
add_test(NAME tr31_tool_test1
COMMAND tr31-tool --import B0128B1TX00N0300KS18FFFF00A0200001E00000KC0C000169E3KP0C00ECAD626F9F1A826814AA066D86C8C18BD0E14033E1EBEC75BEDF586E6E325F3AA8C0E5 --kbpk AB2E09DB3EF0BA71E0CE6CD755C23A3B
)
Expand Down

0 comments on commit c4c9058

Please sign in to comment.