From e11139a18c5f98ba014155179163fd5a30fe3923 Mon Sep 17 00:00:00 2001 From: Dmitry Ilyin Date: Sat, 27 Feb 2021 12:40:49 +0300 Subject: [PATCH 1/4] Add CMakeLists.txt stuff --- CMakeLists.txt | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ mxmlConfig.cmake | 2 ++ 2 files changed, 57 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 mxmlConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ab5b2d9 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,55 @@ +cmake_minimum_required(VERSION 3.8) + +set(VERSION 3.2) + +project( + mxml + VERSION ${VERSION} + LANGUAGES C) + +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) + +set(HEADERS mxml-private.h) + +configure_file(config.h.in config.h) + +add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS}) +target_include_directories( + ${PROJECT_NAME} PUBLIC $ + $) +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 ${PROJECT_NAME}Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + DESTINATION lib/cmake/${PROJECT_NAME}) diff --git a/mxmlConfig.cmake b/mxmlConfig.cmake new file mode 100644 index 0000000..7c78a22 --- /dev/null +++ b/mxmlConfig.cmake @@ -0,0 +1,2 @@ +include(CMakeFindDependencyMacro) +include("${CMAKE_CURRENT_LIST_DIR}/mxmlTargets.cmake") From bc02a80705608c86eda12353f529e5a7a033a9f2 Mon Sep 17 00:00:00 2001 From: Dmitry Ilyin Date: Sat, 27 Feb 2021 12:51:28 +0300 Subject: [PATCH 2/4] Fix paths --- CMakeLists.txt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ab5b2d9..612f9c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,14 +19,11 @@ set(SOURCES mxml-set.c mxml-string.c) -set(HEADERS mxml-private.h) - configure_file(config.h.in config.h) +set(HEADERS mxml-private.h ${CMAKE_CURRENT_BINARY_DIR}/config.h) add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS}) -target_include_directories( - ${PROJECT_NAME} PUBLIC $ - $) +target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) add_library(MSweet::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) # install library From dd246ab5f0cb16d597dc136a459188f7617faa3e Mon Sep 17 00:00:00 2001 From: Dmitry Ilyin Date: Sat, 27 Feb 2021 13:10:39 +0300 Subject: [PATCH 3/4] Move CMake stuff to separate directory --- CMakeLists.txt | 8 +-- cmake/config.h | 74 ++++++++++++++++++++++ mxmlConfig.cmake => cmake/mxmlConfig.cmake | 0 3 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 cmake/config.h rename mxmlConfig.cmake => cmake/mxmlConfig.cmake (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 612f9c7..8daabc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,11 +19,11 @@ set(SOURCES mxml-set.c mxml-string.c) -configure_file(config.h.in config.h) -set(HEADERS mxml-private.h ${CMAKE_CURRENT_BINARY_DIR}/config.h) +#configure_file(config.h.in config.h) +set(HEADERS mxml-private.h cmake/config.h) add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS}) -target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) add_library(MSweet::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) # install library @@ -47,6 +47,6 @@ install(FILES mxml.h DESTINATION include) include(CMakePackageConfigHelpers) write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake COMPATIBILITY SameMajorVersion) -install(FILES ${PROJECT_NAME}Config.cmake +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 b/cmake/config.h new file mode 100644 index 0000000..ebcc302 --- /dev/null +++ b/cmake/config.h @@ -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... + */ + +#define MXML_VERSION "Mini-XML v3.2" + + +/* + * Inline function support... + */ + +#define inline + + +/* + * Long long support... + */ + +#define HAVE_LONG_LONG 1 + + +/* + * Do we have the *printf() functions? + */ + +#define HAVE_SNPRINTF 1 +#define HAVE_VASPRINTF 1 +#define HAVE_VSNPRINTF 1 + + +/* + * Do we have the strXXX() functions? + */ + +#define HAVE_STRDUP 1 +#define HAVE_STRLCAT 1 +#define 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/mxmlConfig.cmake b/cmake/mxmlConfig.cmake similarity index 100% rename from mxmlConfig.cmake rename to cmake/mxmlConfig.cmake From 7d3223e14b5118c459051e015aed1b37735f47f0 Mon Sep 17 00:00:00 2001 From: Dmitry Ilyin Date: Sat, 27 Feb 2021 14:01:38 +0300 Subject: [PATCH 4/4] Make config.h generatable for CMake --- CMakeLists.txt | 21 ++++++++++++++++++--- cmake/{config.h => config.h.in} | 16 ++++++++-------- 2 files changed, 26 insertions(+), 11 deletions(-) rename cmake/{config.h => config.h.in} (77%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8daabc5..41fe9b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,24 @@ project( 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 @@ -19,9 +37,6 @@ set(SOURCES mxml-set.c mxml-string.c) -#configure_file(config.h.in config.h) -set(HEADERS mxml-private.h cmake/config.h) - add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS}) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) add_library(MSweet::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) diff --git a/cmake/config.h b/cmake/config.h.in similarity index 77% rename from cmake/config.h rename to cmake/config.h.in index ebcc302..e81b88c 100644 --- a/cmake/config.h +++ b/cmake/config.h.in @@ -24,7 +24,7 @@ * Version number... */ -#define MXML_VERSION "Mini-XML v3.2" +#cmakedefine MXML_VERSION "@MXML_VERSION@" /* @@ -38,25 +38,25 @@ * Long long support... */ -#define HAVE_LONG_LONG 1 +#cmakedefine HAVE_LONG_LONG 1 /* * Do we have the *printf() functions? */ -#define HAVE_SNPRINTF 1 -#define HAVE_VASPRINTF 1 -#define HAVE_VSNPRINTF 1 +#cmakedefine HAVE_SNPRINTF 1 +#cmakedefine HAVE_VASPRINTF 1 +#cmakedefine HAVE_VSNPRINTF 1 /* * Do we have the strXXX() functions? */ -#define HAVE_STRDUP 1 -#define HAVE_STRLCAT 1 -#define HAVE_STRLCPY 1 +#cmakedefine HAVE_STRDUP 1 +#cmakedefine HAVE_STRLCAT 1 +#cmakedefine HAVE_STRLCPY 1 /*