I trying to make a crypt(3)
sample with CMake.
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <crypt.h>
/* To compile: $ gcc check.c -lcrypt -o check */
int main(void) {
/* Hashed form of "GNU libc manual". */
char *pass = "$1$/iSaq7rB$EoUw5jJPPvAPECNaaWzMK/";
/* Read in the user’s password and encrypt it,
passing the expected password in as the salt. */
char *result = crypt(getpass("Password:"), pass);
/* Test the result. */
int ok = strcmp (result, pass) == 0;
puts(ok ? "Access granted." : "Access denied.");
return ok ? 0 : 1;
}
To build it it should be pass the -lcrypt
option to gcc.
My CMakeLists.txt
looks like:
project(cryptexample)
set(SOURCE_FILES check.c)
add_executable(check ${SOURCE_FILES})
How can I pass this option and build it?
Something like:
target_link_libraries(check crypt)
Source: https://cmake.org/cmake/help/latest/command/target_link_libraries.html