Mercurial > hg > MonetDB-extend
changeset 34:f712fa63c6cc
add cmake files
author | Niels Nes <niels@cwi.nl> |
---|---|
date | Fri, 12 Jun 2020 09:07:27 +0200 (2020-06-12) |
parents | a8ffdbc388ce |
children | 2dfbe7d90da4 |
files | CMakeLists.txt cmake/Modules/FindPCRE.cmake embedded/CMakeLists.txt embedded/example1.c regexp/CMakeLists.txt reverse/CMakeLists.txt |
diffstat | 6 files changed, 275 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CMakeLists.txt Fri Jun 12 09:07:27 2020 +0200 @@ -0,0 +1,40 @@ +#[[ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V. +#]] + +cmake_minimum_required(VERSION 3.12) + +project(MonetDB-extend VERSION "${MONETDB_VERSION}" LANGUAGES C) +set(C_STANDARD_REQUIRED ON) +set(CMAKE_C_STANDARD 99) + +set(CMAKE_MODULE_PATH + "${CMAKE_SOURCE_DIR}/cmake/Modules" + CACHE + INTERNAL + "Location of custom CMake modules.") + +find_package(MonetDB CONFIG REQUIRED) +find_package(PCRE) + +add_custom_command(OUTPUT README.html + COMMAND "rst2html" "-d" "${CMAKE_SOURCE_DIR}/README.rst" "README.html") + +add_custom_command(OUTPUT README.pdf + COMMAND "rst2pdf" "${CMAKE_SOURCE_DIR}/README.rst" "-o" "README.pdf") + +add_subdirectory(regexp) +add_subdirectory(reverse) +add_subdirectory(embedded) + +add_custom_target(docs + DEPENDS + README.html + README.pdf + regexp-docs + reverse-docs + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmake/Modules/FindPCRE.cmake Fri Jun 12 09:07:27 2020 +0200 @@ -0,0 +1,53 @@ +#[[ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V. +#]] + +# Adapted from https://github.com/LuaDist/pcre/blob/master/FindPCRE.cmake +# Copyright (C) 2007-2009 LuaDist. +# Created by Peter Kapec <kapecp@gmail.com> +# Redistribution and use of this file is allowed according to the terms of the MIT license. +# For details see the COPYRIGHT file distributed with LuaDist. + +# - Find pcre +# Find the native PCRE headers and libraries. +# +# PCRE_INCLUDE_DIR - where to find pcre.h, etc. +# PCRE_LIBRARIES - List of libraries when using pcre. +# PCRE_VERSION - The version found. +# PCRE_FOUND - True if pcre found. + +find_path(PCRE_INCLUDE_DIR NAMES pcre.h) + +find_library(PCRE_LIBRARIES NAMES pcre) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PCRE + DEFAULT_MSG + PCRE_LIBRARIES + PCRE_INCLUDE_DIR) + +mark_as_advanced(PCRE_INCLUDE_DIR PCRE_LIBRARIES PCRE_VERSION) + +if(PCRE_FOUND) + file(STRINGS "${PCRE_INCLUDE_DIR}/pcre.h" PCRE_VERSION_LINES REGEX "[ \t]*#define[ \t]+PCRE_(MAJOR|MINOR)") + string(REGEX REPLACE ".*PCRE_MAJOR *\([0-9]*\).*" "\\1" PCRE_VERSION_MAJOR "${PCRE_VERSION_LINES}") + string(REGEX REPLACE ".*PCRE_MINOR *\([0-9]*\).*" "\\1" PCRE_VERSION_MINOR "${PCRE_VERSION_LINES}") + set(PCRE_VERSION "${PCRE_VERSION_MAJOR}.${PCRE_VERSION_MINOR}") + + if(NOT TARGET PCRE::PCRE AND + (EXISTS "${PCRE_LIBRARIES}")) + add_library(PCRE::PCRE UNKNOWN IMPORTED) + set_target_properties(PCRE::PCRE PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${PCRE_INCLUDE_DIR}") + + if(EXISTS "${PCRE_LIBRARIES}") + set_target_properties(PCRE::PCRE PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${PCRE_LIBRARIES}") + endif() + endif() +endif()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/embedded/CMakeLists.txt Fri Jun 12 09:07:27 2020 +0200 @@ -0,0 +1,14 @@ +#[[ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Copyright 1997 - July 2008 CWI, August 2008 - 2020 MonetDB B.V. +#]] + +add_executable(example1 example1.c) +target_link_libraries(example1 + PRIVATE + MonetDB::monetdb_config_header + MonetDB::embedded) +add_test(run_example1 example1)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/embedded/example1.c Fri Jun 12 09:07:27 2020 +0200 @@ -0,0 +1,79 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 1997 - July 2008 CWI, August 2008 - 2020 MonetDB B.V. + */ + +#include "monetdb_embedded.h" +#include <stdlib.h> +#include <stdio.h> +#include <inttypes.h> + +#define error(msg) {fprintf(stderr, "Failure: %s\n", msg); return -1;} + +int +main(void) +{ + char* err = NULL; + monetdb_connection conn = NULL; + monetdb_result* result = NULL; + + // first argument is a string for the db directory or NULL for in-memory mode + if ((err = monetdb_startup(NULL, 0)) != NULL) + error(err) + if ((err = monetdb_connect(&conn)) != NULL) + error(err) + if ((err = monetdb_query(conn, "CREATE TABLE test (x integer, y string)", NULL, NULL, NULL)) != NULL) + error(err) + if ((err = monetdb_query(conn, "INSERT INTO test VALUES (42, 'Hello'), (NULL, 'World')", NULL, NULL, NULL)) != NULL) + error(err) + if ((err = monetdb_query(conn, "SELECT x, y FROM test; ", &result, NULL, NULL)) != NULL) + error(err) + + fprintf(stdout, "Query result with %zu cols and %"PRId64" rows\n", result->ncols, result->nrows); + for (int64_t r = 0; r < result->nrows; r++) { + for (size_t c = 0; c < result->ncols; c++) { + monetdb_column* rcol; + if ((err = monetdb_result_fetch(conn, result, &rcol, c)) != NULL) + error(err) + switch (rcol->type) { + case monetdb_int32_t: { + monetdb_column_int32_t * col = (monetdb_column_int32_t *) rcol; + if (col->data[r] == col->null_value) { + printf("NULL"); + } else { + printf("%d", col->data[r]); + } + break; + } + case monetdb_str: { + monetdb_column_str * col = (monetdb_column_str *) rcol; + if (col->is_null(col->data[r])) { + printf("NULL"); + } else { + printf("%s", (char*) col->data[r]); + } + break; + } + default: { + printf("UNKNOWN"); + } + } + + if (c + 1 < result->ncols) { + printf(", "); + } + } + printf("\n"); + } + + if ((err = monetdb_cleanup_result(conn, result)) != NULL) + error(err) + if ((err = monetdb_disconnect(conn)) != NULL) + error(err) + if ((err = monetdb_shutdown()) != NULL) + error(err) + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/regexp/CMakeLists.txt Fri Jun 12 09:07:27 2020 +0200 @@ -0,0 +1,45 @@ +#[[ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V. +#]] + +add_library(regexp SHARED) + +target_sources(regexp + PRIVATE + regexp.c) + +target_link_libraries(regexp + PRIVATE + MonetDB::monetdb_config_header + MonetDB::monetdb5 + PCRE::PCRE) + +set_target_properties(regexp + PROPERTIES + OUTPUT_NAME + _regexp) + +install(FILES + 81_regexp.mal + DESTINATION + ${CMAKE_INSTALL_LIBDIR}/monetdb5/autoload) + +install(FILES + 81_regexp.sql + DESTINATION ${CMAKE_INSTALL_LIBDIR}/monetdb5/createdb) + +add_custom_command(OUTPUT README.html + COMMAND "rst2html" "-d" "${CMAKE_SOURCE_DIR}/README.rst" "README.html") + +add_custom_command(OUTPUT README.pdf + COMMAND "rst2pdf" "${CMAKE_SOURCE_DIR}/README.rst" "-o" "README.pdf") + +add_custom_target(regexp-docs + DEPENDS + README.html + README.pdf + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/reverse/CMakeLists.txt Fri Jun 12 09:07:27 2020 +0200 @@ -0,0 +1,44 @@ +#[[ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V. +#]] + +add_library(reverse SHARED) + +target_sources(reverse + PRIVATE + reverse.c) + +target_link_libraries(reverse + PRIVATE + MonetDB::monetdb_config_header + MonetDB::monetdb5) + +set_target_properties(reverse + PROPERTIES + OUTPUT_NAME + _reverse) + +install(FILES + 80_reverse.mal + DESTINATION + ${CMAKE_INSTALL_LIBDIR}/monetdb5/autoload) + +install(FILES + 80_regexp.sql + DESTINATION ${CMAKE_INSTALL_LIBDIR}/monetdb5/createdb) + +add_custom_command(OUTPUT README.html + COMMAND "rst2html" "-d" "${CMAKE_SOURCE_DIR}/README.rst" "README.html") + +add_custom_command(OUTPUT README.pdf + COMMAND "rst2pdf" "${CMAKE_SOURCE_DIR}/README.rst" "-o" "README.pdf") + +add_custom_target(reverse-docs + DEPENDS + README.html + README.pdf + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})