From bee8ed82abbc1ee8c631691a131c3d6ec6ba0836 Mon Sep 17 00:00:00 2001 From: Heiko Thiery Date: Wed, 15 Apr 2020 09:14:23 +0200 Subject: [PATCH] cmake: Add autogenerated libssh_version.h Set the cmake project verision to the autogenerated file to have a single point to set the version. This will be included in the libssh.h file. Pair-Programmed-With: Andreas Schneider Signed-off-by: Heiko Thiery Signed-off-by: Andreas Schneider Reviewed-by: Jakub Jelen --- examples/CMakeLists.txt | 2 +- include/libssh/CMakeLists.txt | 6 ++++ include/libssh/libssh.h | 19 ++---------- include/libssh/libssh_version.h.cmake | 41 +++++++++++++++++++++++++ src/CMakeLists.txt | 1 + tests/CMakeLists.txt | 1 + tests/pkd/CMakeLists.txt | 1 + tests/server/CMakeLists.txt | 1 + tests/server/test_server/CMakeLists.txt | 1 + 9 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 include/libssh/libssh_version.h.cmake diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index b3b6b358..4e09083a 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -6,7 +6,7 @@ set(examples_SRCS connect_ssh.c ) -include_directories(${libssh_BINARY_DIR}) +include_directories(${libssh_BINARY_DIR}/include ${libssh_BINARY_DIR}) if (ARGP_INCLUDE_DIR) include_directories(${ARGP_INCLUDE_DIR}) diff --git a/include/libssh/CMakeLists.txt b/include/libssh/CMakeLists.txt index acc966e3..83e7b9f8 100644 --- a/include/libssh/CMakeLists.txt +++ b/include/libssh/CMakeLists.txt @@ -31,3 +31,9 @@ install( headers ) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libssh_version.h.cmake + ${libssh_BINARY_DIR}/include/libssh/libssh_version.h + @ONLY) +install(FILES ${libssh_BINARY_DIR}/include/libssh/libssh_version.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${APPLICATION_NAME} + COMPONENT headers) diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h index 7b96541a..12ff322d 100644 --- a/include/libssh/libssh.h +++ b/include/libssh/libssh.h @@ -21,6 +21,8 @@ #ifndef _LIBSSH_H #define _LIBSSH_H +#include + #if defined _WIN32 || defined __CYGWIN__ #ifdef LIBSSH_STATIC #define LIBSSH_API @@ -71,23 +73,6 @@ #define SSH_STRINGIFY(s) SSH_TOSTRING(s) #define SSH_TOSTRING(s) #s -/* libssh version macros */ -#define SSH_VERSION_INT(a, b, c) ((a) << 16 | (b) << 8 | (c)) -#define SSH_VERSION_DOT(a, b, c) a ##.## b ##.## c -#define SSH_VERSION(a, b, c) SSH_VERSION_DOT(a, b, c) - -/* libssh version */ -#define LIBSSH_VERSION_MAJOR 0 -#define LIBSSH_VERSION_MINOR 8 -#define LIBSSH_VERSION_MICRO 90 - -#define LIBSSH_VERSION_INT SSH_VERSION_INT(LIBSSH_VERSION_MAJOR, \ - LIBSSH_VERSION_MINOR, \ - LIBSSH_VERSION_MICRO) -#define LIBSSH_VERSION SSH_VERSION(LIBSSH_VERSION_MAJOR, \ - LIBSSH_VERSION_MINOR, \ - LIBSSH_VERSION_MICRO) - /* GCC have printf type attribute check. */ #ifdef __GNUC__ #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b))) diff --git a/include/libssh/libssh_version.h.cmake b/include/libssh/libssh_version.h.cmake new file mode 100644 index 00000000..464fa14d --- /dev/null +++ b/include/libssh/libssh_version.h.cmake @@ -0,0 +1,41 @@ +/* + * This file is part of the SSH Library + * + * Copyright (c) 2020 by Heiko Thiery + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _LIBSSH_VERSION_H +#define _LIBSSH_VERSION_H + +/* libssh version macros */ +#define SSH_VERSION_INT(a, b, c) ((a) << 16 | (b) << 8 | (c)) +#define SSH_VERSION_DOT(a, b, c) a ##.## b ##.## c +#define SSH_VERSION(a, b, c) SSH_VERSION_DOT(a, b, c) + +/* libssh version */ +#define LIBSSH_VERSION_MAJOR @libssh_VERSION_MAJOR@ +#define LIBSSH_VERSION_MINOR @libssh_VERSION_MINOR@ +#define LIBSSH_VERSION_MICRO @libssh_VERSION_PATCH@ + +#define LIBSSH_VERSION_INT SSH_VERSION_INT(LIBSSH_VERSION_MAJOR, \ + LIBSSH_VERSION_MINOR, \ + LIBSSH_VERSION_MICRO) +#define LIBSSH_VERSION SSH_VERSION(LIBSSH_VERSION_MAJOR, \ + LIBSSH_VERSION_MINOR, \ + LIBSSH_VERSION_MICRO) + +#endif /* _LIBSSH_VERSION_H */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a5129ba4..c6246625 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,7 @@ set(LIBSSH_PUBLIC_INCLUDE_DIRS ${libssh_SOURCE_DIR}/include) set(LIBSSH_PRIVATE_INCLUDE_DIRS + ${libssh_BINARY_DIR}/include ${libssh_BINARY_DIR} ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 31a16a39..33a187fb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,6 +9,7 @@ set(TORTURE_LIBRARY torture) include_directories(${OPENSSL_INCLUDE_DIR} ${CMOCKA_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} + ${libssh_BINARY_DIR}/include ${libssh_BINARY_DIR} ${libssh_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR} diff --git a/tests/pkd/CMakeLists.txt b/tests/pkd/CMakeLists.txt index 85a57775..9e550462 100644 --- a/tests/pkd/CMakeLists.txt +++ b/tests/pkd/CMakeLists.txt @@ -3,6 +3,7 @@ project(pkd C) if (WITH_SERVER AND UNIX AND NOT WIN32) include_directories(${libssh_SOURCE_DIR}/include + ${libssh_BINARY_DIR}/include ${CMOCKA_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ${CMAKE_BINARY_DIR} diff --git a/tests/server/CMakeLists.txt b/tests/server/CMakeLists.txt index 9476ea91..ebe2d169 100644 --- a/tests/server/CMakeLists.txt +++ b/tests/server/CMakeLists.txt @@ -13,6 +13,7 @@ set(LIBSSH_SERVER_TESTS ) include_directories(${libssh_SOURCE_DIR}/include + ${libssh_BINARY_DIR}/include ${libssh_BINARY_DIR} test_server) diff --git a/tests/server/test_server/CMakeLists.txt b/tests/server/test_server/CMakeLists.txt index 10bf4b7d..fe5e7d09 100644 --- a/tests/server/test_server/CMakeLists.txt +++ b/tests/server/test_server/CMakeLists.txt @@ -17,6 +17,7 @@ set(LIBSSH_SERVER_TESTS ) include_directories(${libssh_SOURCE_DIR}/include + ${libssh_BINARY_DIR}/include ${libssh_BINARY_DIR}) if (ARGP_INCLUDE_DIR)