diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..41fe9b8 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,67 @@ +cmake_minimum_required(VERSION 3.8) + +set(VERSION 3.2) + +project( + mxml + VERSION ${VERSION} + LANGUAGES C) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() + +include(CheckTypeSize) +check_type_size("long long" HAVE_LONG_LONG) +include(CheckFunctionExists) +check_function_exists(snprintf HAVE_SNPRINTF) +check_function_exists(vasprintf HAVE_VASPRINTF) +check_function_exists(vsnprintf HAVE_VSNPRINTF) +check_function_exists(strdup HAVE_STRDUP) +check_function_exists(strlcat HAVE_STRLCAT) +check_function_exists(strlcpy HAVE_STRLCPY) +set(MXML_VERSION "Mini-XML v${VERSION}") + +configure_file(cmake/config.h.in config.h) +set(HEADERS mxml-private.h ${CMAKE_CURRENT_BINARY_DIR}/config.h) + +set(SOURCES + mxml-attr.c + mxml-entity.c + mxml-file.c + mxml-get.c + mxml-index.c + mxml-node.c + mxml-private.c + mxml-search.c + mxml-set.c + mxml-string.c) + +add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS}) +target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) +add_library(MSweet::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) + +# install library +install( + TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}Targets + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin + INCLUDES + DESTINATION include) + +install( + EXPORT ${PROJECT_NAME}Targets + DESTINATION lib/cmake/${PROJECT_NAME} + FILE ${PROJECT_NAME}Targets.cmake + NAMESPACE MSweet::) + +install(FILES mxml.h DESTINATION include) + +include(CMakePackageConfigHelpers) +write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake + COMPATIBILITY SameMajorVersion) +install(FILES cmake/${PROJECT_NAME}Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + DESTINATION lib/cmake/${PROJECT_NAME}) diff --git a/cmake/config.h.in b/cmake/config.h.in new file mode 100644 index 0000000..e81b88c --- /dev/null +++ b/cmake/config.h.in @@ -0,0 +1,74 @@ +/* + * Xcode configuration file for Mini-XML, a small XML file parsing library. + * + * https://www.msweet.org/mxml + * + * Copyright © 2003-2020 by Michael R Sweet. + * + * Licensed under Apache License v2.0. See the file "LICENSE" for more + * information. + */ + +/* + * Include necessary headers... + */ + +#include +#include +#include +#include +#include + + +/* + * Version number... + */ + +#cmakedefine MXML_VERSION "@MXML_VERSION@" + + +/* + * Inline function support... + */ + +#define inline + + +/* + * Long long support... + */ + +#cmakedefine HAVE_LONG_LONG 1 + + +/* + * Do we have the *printf() functions? + */ + +#cmakedefine HAVE_SNPRINTF 1 +#cmakedefine HAVE_VASPRINTF 1 +#cmakedefine HAVE_VSNPRINTF 1 + + +/* + * Do we have the strXXX() functions? + */ + +#cmakedefine HAVE_STRDUP 1 +#cmakedefine HAVE_STRLCAT 1 +#cmakedefine HAVE_STRLCPY 1 + + +/* + * Do we have threading support? + */ + +#define HAVE_PTHREAD_H 1 + + +/* + * Define prototypes for string functions as needed... + */ + +extern char *_mxml_strdupf(const char *, ...); +extern char *_mxml_vstrdupf(const char *, va_list); diff --git a/cmake/mxmlConfig.cmake b/cmake/mxmlConfig.cmake new file mode 100644 index 0000000..7c78a22 --- /dev/null +++ b/cmake/mxmlConfig.cmake @@ -0,0 +1,2 @@ +include(CMakeFindDependencyMacro) +include("${CMAKE_CURRENT_LIST_DIR}/mxmlTargets.cmake")