Browse Source

WIP: Add meta header for libraries

experiment/meta_header
Martchus 5 years ago
parent
commit
71c401dcc4
  1. 4
      cmake/modules/BasicConfig.cmake
  2. 20
      cmake/modules/LibraryTarget.cmake
  3. 26
      cmake/templates/meta.cpp.in
  4. 24
      cmake/templates/meta.h.in

4
cmake/modules/BasicConfig.cmake

@ -11,6 +11,10 @@ endif()
if(NOT META_PROJECT_VARNAME_UPPER)
string(TOUPPER ${META_PROJECT_VARNAME} META_PROJECT_VARNAME_UPPER)
endif()
if(NOT META_PROJECT_VARNAME_LOWER)
string(REGEX REPLACE "_+" "" META_PROJECT_VARNAME_LOWER "${META_PROJECT_VARNAME}")
string(TOLOWER "${META_PROJECT_VARNAME_LOWER}" META_PROJECT_VARNAME_LOWER)
endif()
# set META_GENERIC_NAME to META_APP_NAME if not specified explicitely
if(NOT META_GENERIC_NAME)

20
cmake/modules/LibraryTarget.cmake

@ -80,6 +80,26 @@ if(NOT META_SOVERSION)
endif()
endif()
# add header providing meta information about the library
find_template_file("meta.h" CPP_UTILITIES META_H_TEMPLATE_FILE)
find_template_file("meta.cpp" CPP_UTILITIES META_CPP_TEMPLATE_FILE)
configure_file(
"${META_H_TEMPLATE_FILE}"
"${CMAKE_CURRENT_BINARY_DIR}/meta.h"
NEWLINE_STYLE UNIX # since this will be installed ensure consistency
)
configure_file(
"${META_CPP_TEMPLATE_FILE}"
"${CMAKE_CURRENT_BINARY_DIR}/meta.cpp"
NEWLINE_STYLE UNIX # since this will be installed ensure consistency
)
list(APPEND SOURCE_FILES "${CMAKE_CURRENT_BINARY_DIR}/.cpp")
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/meta.h"
DESTINATION "include/${META_PROJECT_NAME}"
COMPONENT header
)
# add target for building the library
if(BUILD_SHARED_LIBS)
if(STATIC_LIBRARY_LINKAGE)

26
cmake/templates/meta.cpp.in

@ -0,0 +1,26 @@
// Created via CMake from template meta.h.in
// WARNING! Any changes to this file will be overwritten by the next CMake run!
namespace Meta {
const char *@META_PROJECT_VARNAME_LOWER@Author()
{
return "@META_APP_AUTHOR@";
}
const char *@META_PROJECT_VARNAME_LOWER@Url()
{
return "@META_APP_URL@";
}
const char *@META_PROJECT_VARNAME_LOWER@Description()
{
return "@META_APP_DESCRIPTION@";
}
const char *@META_PROJECT_VARNAME_LOWER@Version()
{
return "@META_VERSION_MAJOR@.@META_VERSION_MINOR@.@META_VERSION_PATCH@";
}
}

24
cmake/templates/meta.h.in

@ -0,0 +1,24 @@
// Created via CMake from template meta.h.in
// WARNING! Any changes to this file will be overwritten by the next CMake run!
#ifndef @META_PROJECT_VARNAME_UPPER@_META
#define @META_PROJECT_VARNAME_UPPER@_META
#include <@META_PROJECT_NAME@/global.h>
#define @META_PROJECT_VARNAME_UPPER@_NAME "@META_APP_NAME@"
#define @META_PROJECT_VARNAME_UPPER@_AUTHOR "@META_APP_AUTHOR@"
#define @META_PROJECT_VARNAME_UPPER@_URL "@META_APP_URL@"
#define @META_PROJECT_VARNAME_UPPER@_DESCRIPTION "@META_APP_DESCRIPTION@"
#define @META_PROJECT_VARNAME_UPPER@_VERSION_MAJOR "@META_VERSION_MAJOR@"
#define @META_PROJECT_VARNAME_UPPER@_VERSION_MINOR "@META_VERSION_MINOR@"
#define @META_PROJECT_VARNAME_UPPER@_VERSION_PATCH "@META_VERSION_PATCH@"
namespace Meta {
@META_PROJECT_VARNAME_UPPER@_EXPORT const char *@META_PROJECT_VARNAME_LOWER@Author();
@META_PROJECT_VARNAME_UPPER@_EXPORT const char *@META_PROJECT_VARNAME_LOWER@Url();
@META_PROJECT_VARNAME_UPPER@_EXPORT const char *@META_PROJECT_VARNAME_LOWER@Description();
@META_PROJECT_VARNAME_UPPER@_EXPORT const char *@META_PROJECT_VARNAME_LOWER@Version();
}
#endif // @META_PROJECT_VARNAME_UPPER@_META
Loading…
Cancel
Save