Commit dc861c70 authored by Thorsten Alteholz's avatar Thorsten Alteholz

Import Upstream version 1.4.2

parent 67cbba3e
......@@ -5,5 +5,6 @@ example_sqlite3
example_mariadb
example_pgsql
example_mariadb_json
example_multi_mariadb
core
valgrind.txt
# Hoel Changelog
## 1.4.2
- Fix Makefile soname
## 1.4.1
- Add Debian hardening patch on Makefile
## 1.4
- Add CMake installation script
- Various bugfixes
#
# Hoel library
#
# CMake file used to build all programs
#
# Copyright 2018 Nicolas Mora <mail@babelouest.org>
# Copyright 2018 Silvio Clecio <silvioprog@gmail.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the MIT License
#
# 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.
#
cmake_minimum_required(VERSION 3.5)
project(hoel C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
# library info
set(PROJECT_DESCRIPTION "C Database abstraction library with json based language")
set(PROJECT_BUGREPORT_PATH "https://github.com/babelouest/hoel/issues")
set(LIBRARY_VERSION_MAJOR "1")
set(LIBRARY_VERSION_MINOR "4")
set(LIBRARY_VERSION_PATCH "2")
set(LIBRARY_VERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}")
set(LIBRARY_SOVERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}")
set(YDER_VERSION_DOWNLOAD "1.3.3")
# cmake modules
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules)
include(GNUInstallDirs)
include(CheckSymbolExists)
# check if _GNU_SOURCE is available
if (NOT _GNU_SOURCE)
check_symbol_exists(__GNU_LIBRARY__ "features.h" _GNU_SOURCE)
if (NOT _GNU_SOURCE)
unset(_GNU_SOURCE CACHE)
check_symbol_exists(_GNU_SOURCE "features.h" _GNU_SOURCE)
endif ()
endif ()
if (_GNU_SOURCE)
add_definitions(-D_GNU_SOURCE)
endif ()
# directories and source
set(INC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
include_directories(${INC_DIR})
set(LIB_SRC
${INC_DIR}/hoel.h
${INC_DIR}/h-private.h
${SRC_DIR}/hoel-simple-json.c
${SRC_DIR}/hoel-mariadb.c
${SRC_DIR}/hoel-pgsql.c
${SRC_DIR}/hoel-sqlite.c
${SRC_DIR}/hoel.c)
# dependencies
include(FindJansson)
set(JANSSON_MIN_VERSION 2.4)
find_package(Jansson ${JANSSON_MIN_VERSION} REQUIRED)
if (JANSSON_FOUND)
set(LIBS ${JANSSON_LIBRARIES})
endif ()
option(WITH_SQLITE3 "Use SQLite3 library" ON)
if (WITH_SQLITE3)
include(FindSQLite3)
find_package(SQLite3 REQUIRED)
if (SQLITE3_FOUND)
set(LIBS ${LIBS} ${SQLITE3_LIBRARIES})
add_definitions(-D_HOEL_SQLITE)
include_directories(${SQLITE3_INCLUDE_DIR})
set(LIBS ${LIBS} ${SQLITE3_LIBRARIES})
else ()
message("SQLite3 not found")
endif ()
endif ()
option(WITH_MARIADB "Use MariaDB/MySQL library" ON)
if (WITH_MARIADB)
include(FindMYSQL)
find_package(MYSQL REQUIRED)
if (MYSQL_FOUND)
set(LIBS ${LIBS} ${MYSQL_LIBRARIES})
add_definitions(-D_HOEL_MARIADB)
include_directories(${MYSQL_INCLUDE_DIRS})
set(LIBS ${LIBS} ${MYSQL_LIBRARIES})
else ()
message("MariaDB not found")
endif ()
endif ()
option(WITH_PGSQL "Use PostgreSQL library" ON)
if (WITH_PGSQL)
include(FindLibPQ)
find_package(LibPQ REQUIRED)
if(LIBPQ_FOUND)
set(LIBS ${LIBS} ${LIBPQ_LIBRARIES})
add_definitions(-D_HOEL_PGSQL)
include_directories(${LIBPQ_INCLUDE_DIRS})
set(LIBS ${LIBS} ${LIBPQ_LIBRARIES})
else ()
message("LibPQ not found")
endif()
endif ()
if (NOT WITH_PGSQL AND NOT WITH_MARIADB AND NOT WITH_SQLITE3)
MESSAGE(FATAL_ERROR "You must enable at least one databasse backend: Sqlite3, MariaDB/MySQL or PostgreSQL")
endif ()
# static library
option(BUILD_STATIC "Build static library." OFF)
if (BUILD_STATIC)
add_library(hoel_static STATIC ${LIB_SRC})
target_compile_definitions(hoel_static PUBLIC -DO_STATIC_LIBRARY)
set_target_properties(hoel_static PROPERTIES
OUTPUT_NAME libhoel)
endif ()
# shared library
add_library(hoel SHARED ${LIB_SRC})
set_target_properties(hoel PROPERTIES
COMPILE_OPTIONS -Wextra
PUBLIC_HEADER ${INC_DIR}/hoel.h
VERSION "${LIBRARY_VERSION}"
SOVERSION "${LIBRARY_SOVERSION}")
if (WIN32)
set_target_properties(hoel PROPERTIES SUFFIX "-${LIBRARY_VERSION_MAJOR}.dll")
endif ()
target_link_libraries(hoel ${LIBS})
option(CHECK_YDER "Check Yder library." ON)
if (CHECK_YDER)
set(Yder_FIND_QUIETLY ON) # force to find Yder quietly
include(FindYder)
find_package(Yder 1.1 QUIET) # try to find Yder
if (NOT YDER_FOUND)
include(DownloadProject)
download_project(PROJ yder # ... otherwise, download archive
URL "https://github.com/babelouest/yder/archive/v${YDER_VERSION_DOWNLOAD}.tar.gz"
QUIET)
add_subdirectory(${yder_SOURCE_DIR} ${yder_BINARY_DIR})
include_directories(${yder_SOURCE_DIR}/include)
include_directories(${orcania_SOURCE_DIR}/include)
add_dependencies(hoel yder)
add_dependencies(hoel orcania)
set(HOEL_LIBRARIES yder orcania)
endif ()
endif ()
# tests
option(BUILD_TESTING "Build the testing tree." OFF) # because we don not use include(CTest)
if (BUILD_TESTING)
include(FindCheck)
find_package(Check)
if (CHECK_FOUND)
if (NOT WIN32)
include(FindSubunit)
find_package(Subunit REQUIRED)
endif ()
enable_testing()
set(CMAKE_CTEST_COMMAND ctest -V)
set(TST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test)
set(LIBS hoel ${LIBS} ${CHECK_LIBRARIES})
if (NOT WIN32)
find_package(Threads REQUIRED)
set(LIBS ${LIBS} ${SUBUNIT_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} m rt)
endif ()
set(TESTS
str_test
split_test
memory_test)
if (WITH_JANSSON)
set(TESTS ${TESTS} jansson_test)
endif ()
configure_file(
"${CMAKE_MODULE_PATH}/CTestCustom.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake"
@ONLY)
foreach (t ${TESTS})
add_executable(${t} EXCLUDE_FROM_ALL ${TST_DIR}/${t}.c)
target_include_directories(${t} PUBLIC ${TST_DIR})
target_link_libraries(${t} PUBLIC ${LIBS})
add_test(NAME ${t}
WORKING_DIRECTORY ${TST_DIR}
COMMAND ${t})
endforeach ()
endif ()
endif ()
# install target
option(INSTALL_HEADER "Install the header files" ON) # Install hoel.h or not
configure_file(libhoel.pc.in libhoel.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libhoel.pc
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
set(TARGETS hoel)
if (BUILD_STATIC)
set(TARGETS ${TARGETS} hoel_static)
endif ()
if (INSTALL_HEADER)
install(TARGETS ${TARGETS}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(DIRECTORY examples/
DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples/ COMPONENT runtime)
install(FILES README.md
DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT runtime)
else ()
install(TARGETS ${TARGETS}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif ()
# uninstall target
if (NOT TARGET uninstall)
configure_file(
"${CMAKE_MODULE_PATH}/CMakeUninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif ()
# packaging
set(CPACK_PACKAGE_VERSION_MAJOR ${LIBRARY_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${LIBRARY_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${LIBRARY_VERSION_PATCH})
if (INSTALL_HEADER)
set(PACKAGE_FILE_NAME
"lib${CMAKE_PROJECT_NAME}-dev_${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
else ()
set(PACKAGE_FILE_NAME
"lib${CMAKE_PROJECT_NAME}_${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
endif ()
set(PACKAGE_IGNORED_FILES
"${CMAKE_CURRENT_BINARY_DIR}/;/.git/;.gitignore;~$;${CPACK_SOURCE_IGNORE_FILES}")
set(CPACK_GENERATOR "TGZ;DEB")
set(CPACK_DEBIAN_PACKAGE_NAME "libhoel")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "mail@babelouest.org")
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${PROJECT_DESCRIPTION})
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/babelouest/hoel")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.14), libjansson4 (>= 2.4), liborcania (>= 1.2), libyder (>= 1.3), zlib1g (>= 1:1.1.4)")
if (WITH_SQLITE3)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libsqlite3-0 (>= 3.5.9)")
endif ()
if (WITH_MARIADB)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libmariadbclient18 (>= 5.5.36)")
endif ()
if (WITH_PGSQL)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libpq5 (>= 9.0~)")
endif ()
set(CPACK_PACKAGE_FILE_NAME ${PACKAGE_FILE_NAME})
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_PACKAGE_FILE_NAME ${PACKAGE_FILE_NAME})
set(CPACK_SOURCE_IGNORE_FILES ${PACKAGE_IGNORED_FILES})
include(CPack)
add_custom_target(dist_h
COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
......@@ -3,7 +3,7 @@
#
# Makefile used to build all programs
#
# Copyright 2014-2015 Nicolas Mora <mail@babelouest.org>
# Copyright 2014-2018 Nicolas Mora <mail@babelouest.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the MIT License
......@@ -18,6 +18,7 @@ LIBHOEL_LOCATION=./src
EXAMPLE_LOCATION=./examples
TEST_LOCATION=./test
.NOTPARALLEL:
all: libhoel.so example_sqlite3 example_mariadb example_pgsql
debug:
......
......@@ -6,6 +6,23 @@ Simple and easy to use database access library. Works with SQLite 3, MariaDB/Mys
# Installation
## Prerequisites
### Jansson
Install [Jansson](http://www.digip.org/jansson/) library for JSON manipulation, minimum version 2.4. On a debian-based platform, run the following command:
```shell
$ sudo apt-get install libjansson-dev
```
### Database libraries
Install Hoel database dependencies based on your requirements:
- SQLite3: Install the package `libsqlite3-dev`
- MariaDB/Mysql: Install the package `libmysqlclient-dev` or `libmariadbclient-dev`
- PostgreSQL: Install the package `libpq-dev`
## Debian-ish distribution package
[![Packaging status](https://repology.org/badge/vertical-allrepos/hoel.svg)](https://repology.org/metapackage/hoel)
......@@ -16,8 +33,51 @@ Hoel is now available in Debian Buster (testing) and some Debian based distribut
# apt install libhoel-dev
```
### Pre-compiled packages
You can install Hoel with a pre-compiled package available in the [release pages](https://github.com/babelouest/hoel/releases/latest/). `jansson`, `sqlite3`, `libmariadb-client` and `libpq` development files packages are required to install Hoel. The packages files `hoel-dev-full_*` contain the libraries `orcania`, `yder` and `hoel`. It's also compiled with all the database backends.
For example, to install Hoel with the `hoel-dev-full_2.3.0_Debian_stretch_x86_64.tar.gz` package downloaded on the `releases` page, you must execute the following commands:
```shell
$ sudo apt install -y libjansson-dev libmariadbclient-dev libsqlite3-dev libpq-dev
$ wget https://github.com/babelouest/hoel/releases/download/v1.4.0/hoel-dev-full_1.4.0_Debian_stretch_x86_64.tar.gz
$ tar xf hoel-dev-full_1.4.0_Debian_stretch_x86_64.tar.gz
$ sudo dpkg -i liborcania-dev_1.2.0_Debian_stretch_x86_64.deb
$ sudo dpkg -i libyder-dev_1.2.0_Debian_stretch_x86_64.deb
$ sudo dpkg -i libhoel-dev_1.4.0_Debian_stretch_x86_64.deb
```
If there's no package available for your distribution, you can recompile it manually using `CMake` or `Makefile`.
## Install from the source
### CMake - Multi architecture
[CMake](https://cmake.org/download/) minimum 3.5 is required.
Run the cmake script in a subdirectory, example:
```shell
$ git clone https://github.com/babelouest/hoel.git
$ cd hoel/
$ mkdir build
$ cd build
$ cmake ..
$ make && sudo make install
```
The available options for cmake are:
- `-DWITH_SQLITE3=[on|off]` (default `on`): Enable/disabe SQLite3 database backend
- `-DWITH_MARIADB=[on|off]` (default `on`): Enable/disabe MariaDB/Mysql database backend
- `-DWITH_PGSQL=[on|off]` (default `on`): Enable/disabe PostgreSQL database backend
- `-DBUILD_STATIC=[on|off]` (default `off`): Build the static archive in addition to the shared library
- `-DBUILD_TESTING=[on|off]` (default `off`): Build unit tests
- `-DINSTALL_HEADER=[on|off]` (default `on`): Install header file `hoel.h`
- `-DCMAKE_BUILD_TYPE=[Debug|Release]` (default `Release`): Compile with debugging symbols or not
### Good ol' Makefile
Clone, compile and install [Orcania](https://github.com/babelouest/orcania) and [Yder](https://github.com/babelouest/yder) libraries.
### Orcania (Miscellaneous functions)
......@@ -37,21 +97,8 @@ $ make
$ sudo make install
```
### Jansson
Install [Jansson](http://www.digip.org/jansson/) library for JSON manipulation. On a debian-based platform, run the following command:
```shell
$ sudo apt-get install libjansson-dev
```
### Hoel
Install Hoel dependencies:
- SQLite3: Install the package `libsqlite3-dev`
- MariaDB/Mysql: Install the package `libmysqlclient-dev` or `libmariadbclient-dev`
- PostgreSQL: Install the package `libpq-dev`
Download hoel from github repository.
```shell
......@@ -105,7 +152,7 @@ $ sudo make install
### Installation folder
By default, the shared library and the header file will be installed in the `/usr/local` location. To change this setting, you can modify the `PREFIX` value in the `src/Makefile`.
By default, the shared library and the header file will be installed in the `/usr/local` location. To change this setting, you can modify the `DESTDIR` value in the `src/Makefile`.
# API Documentation
......@@ -169,9 +216,9 @@ struct _h_connection * h_connect_sqlite(const char * db_path);
/**
* h_connect_mariadb
* Opens a database connection to a mariadb server
* return pointer to a struct _h_connection * on sucess, NULL on error
* return pointer to a struct _h_connection * on success, NULL on error
*/
struct _h_connection * h_connect_mariadb(char * host, char * user, char * passwd, char * db, unsigned int port, char * unix_socket);
struct _h_connection * h_connect_mariadb(const char * host, const char * user, const char * passwd, const char * db, const unsigned int port, const char * unix_socket);
/**
* h_connect_pgsql
......
if (NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
endif (NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
foreach (file ${files})
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
if (IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
exec_program(
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
OUTPUT_VARIABLE rm_out
RETURN_VALUE rm_retval
)
if (NOT "${rm_retval}" STREQUAL 0)
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
endif (NOT "${rm_retval}" STREQUAL 0)
else (IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
endif (IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
endforeach (file)
string(REPLACE ";" " " TESTS "@TESTS@")
set(CTEST_CUSTOM_PRE_TEST "@CMAKE_MAKE_PROGRAM@ ${TESTS}")
\ No newline at end of file
# Distributed under the OSI-approved MIT License. See accompanying
# file LICENSE or https://github.com/Crascit/DownloadProject for details.
cmake_minimum_required(VERSION 2.8.2)
project(${DL_ARGS_PROJ}-download NONE)
include(ExternalProject)
ExternalProject_Add(${DL_ARGS_PROJ}-download
${DL_ARGS_UNPARSED_ARGUMENTS}
SOURCE_DIR "${DL_ARGS_SOURCE_DIR}"
BINARY_DIR "${DL_ARGS_BINARY_DIR}"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
# Distributed under the OSI-approved MIT License. See accompanying
# file LICENSE or https://github.com/Crascit/DownloadProject for details.
#
# MODULE: DownloadProject
#
# PROVIDES:
# download_project( PROJ projectName
# [PREFIX prefixDir]
# [DOWNLOAD_DIR downloadDir]
# [SOURCE_DIR srcDir]
# [BINARY_DIR binDir]
# [QUIET]
# ...
# )
#
# Provides the ability to download and unpack a tarball, zip file, git repository,
# etc. at configure time (i.e. when the cmake command is run). How the downloaded
# and unpacked contents are used is up to the caller, but the motivating case is
# to download source code which can then be included directly in the build with
# add_subdirectory() after the call to download_project(). Source and build
# directories are set up with this in mind.
#
# The PROJ argument is required. The projectName value will be used to construct
# the following variables upon exit (obviously replace projectName with its actual
# value):
#
# projectName_SOURCE_DIR
# projectName_BINARY_DIR
#
# The SOURCE_DIR and BINARY_DIR arguments are optional and would not typically
# need to be provided. They can be specified if you want the downloaded source
# and build directories to be located in a specific place. The contents of
# projectName_SOURCE_DIR and projectName_BINARY_DIR will be populated with the
# locations used whether you provide SOURCE_DIR/BINARY_DIR or not.
#
# The DOWNLOAD_DIR argument does not normally need to be set. It controls the
# location of the temporary CMake build used to perform the download.
#
# The PREFIX argument can be provided to change the base location of the default
# values of DOWNLOAD_DIR, SOURCE_DIR and BINARY_DIR. If all of those three arguments
# are provided, then PREFIX will have no effect. The default value for PREFIX is
# CMAKE_BINARY_DIR.
#
# The QUIET option can be given if you do not want to show the output associated
# with downloading the specified project.
#
# In addition to the above, any other options are passed through unmodified to
# ExternalProject_Add() to perform the actual download, patch and update steps.
# The following ExternalProject_Add() options are explicitly prohibited (they
# are reserved for use by the download_project() command):
#
# CONFIGURE_COMMAND
# BUILD_COMMAND
# INSTALL_COMMAND
# TEST_COMMAND
#
# Only those ExternalProject_Add() arguments which relate to downloading, patching
# and updating of the project sources are intended to be used. Also note that at
# least one set of download-related arguments are required.
#
# If using CMake 3.2 or later, the UPDATE_DISCONNECTED option can be used to
# prevent a check at the remote end for changes every time CMake is run
# after the first successful download. See the documentation of the ExternalProject
# module for more information. It is likely you will want to use this option if it
# is available to you. Note, however, that the ExternalProject implementation contains
# bugs which result in incorrect handling of the UPDATE_DISCONNECTED option when
# using the URL download method or when specifying a SOURCE_DIR with no download
# method. Fixes for these have been created, the last of which is scheduled for
# inclusion in CMake 3.8.0. Details can be found here:
#
# https://gitlab.kitware.com/cmake/cmake/commit/bdca68388bd57f8302d3c1d83d691034b7ffa70c
# https://gitlab.kitware.com/cmake/cmake/issues/16428
#
# If you experience build errors related to the update step, consider avoiding
# the use of UPDATE_DISCONNECTED.
#
# EXAMPLE USAGE:
#
# include(DownloadProject)
# download_project(PROJ googletest
# GIT_REPOSITORY https://github.com/google/googletest.git
# GIT_TAG master
# UPDATE_DISCONNECTED 1
# QUIET
# )
#
# add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
#
#========================================================================================
set(_DownloadProjectDir "${CMAKE_CURRENT_LIST_DIR}")
include(CMakeParseArguments)
function(download_project)
set(options QUIET)
set(oneValueArgs
PROJ
PREFIX
DOWNLOAD_DIR
SOURCE_DIR
BINARY_DIR
# Prevent the following from being passed through
CONFIGURE_COMMAND
BUILD_COMMAND
INSTALL_COMMAND
TEST_COMMAND
)
set(multiValueArgs "")
cmake_parse_arguments(DL_ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
# Hide output if requested
if (DL_ARGS_QUIET)
set(OUTPUT_QUIET "OUTPUT_QUIET")
else()
unset(OUTPUT_QUIET)
message(STATUS "Downloading/updating ${DL_ARGS_PROJ}")
endif()
# Set up where we will put our temporary CMakeLists.txt file and also
# the base point below which the default source and binary dirs will be.
# The prefix must always be an absolute path.
if (NOT DL_ARGS_PREFIX)
set(DL_ARGS_PREFIX "${CMAKE_BINARY_DIR}")
else()
get_filename_component(DL_ARGS_PREFIX "${DL_ARGS_PREFIX}" ABSOLUTE
BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
endif()
if (NOT DL_ARGS_DOWNLOAD_DIR)
set(DL_ARGS_DOWNLOAD_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-download")
endif()
# Ensure the caller can know where to find the source and build directories
if (NOT DL_ARGS_SOURCE_DIR)
set(DL_ARGS_SOURCE_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-src")
endif()
if (NOT DL_ARGS_BINARY_DIR)
set(DL_ARGS_BINARY_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-build")
endif()
set(${DL_ARGS_PROJ}_SOURCE_DIR "${DL_ARGS_SOURCE_DIR}" PARENT_SCOPE)
set(${DL_ARGS_PROJ}_BINARY_DIR "${DL_ARGS_BINARY_DIR}" PARENT_SCOPE)
# The way that CLion manages multiple configurations, it causes a copy of
# the CMakeCache.txt to be copied across due to it not expecting there to
# be a project within a project. This causes the hard-coded paths in the
# cache to be copied and builds to fail. To mitigate this, we simply
# remove the cache if it exists before we configure the new project. It
# is safe to do so because it will be re-generated. Since this is only
# executed at the configure step, it should not cause additional builds or
# downloads.
file(REMOVE "${DL_ARGS_DOWNLOAD_DIR}/CMakeCache.txt")
# Create and build a separate CMake project to carry out the download.
# If we've already previously done these steps, they will not cause
# anything to be updated, so extra rebuilds of the project won't occur.
# Make sure to pass through CMAKE_MAKE_PROGRAM in case the main project
# has this set to something not findable on the PATH.
configure_file("${_DownloadProjectDir}/DownloadProject.CMakeLists.cmake.in"
"${DL_ARGS_DOWNLOAD_DIR}/CMakeLists.txt")
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
-D "CMAKE_MAKE_PROGRAM:FILE=${CMAKE_MAKE_PROGRAM}"
.
RESULT_VARIABLE result
${OUTPUT_QUIET}
WORKING_DIRECTORY "${DL_ARGS_DOWNLOAD_DIR}"
)
if(result)
message(FATAL_ERROR "CMake step for ${DL_ARGS_PROJ} failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
${OUTPUT_QUIET}
WORKING_DIRECTORY "${DL_ARGS_DOWNLOAD_DIR}"
)
if(result)
message(FATAL_ERROR "Build step for ${DL_ARGS_PROJ} failed: ${result}")
endif()
endfunction()
#.rst:
# FindCheck
# -----------
#
# Find Check
#
# Find Check headers and libraries.
#
# ::
#
# CHECK_FOUND - True if Check found.
# CHECK_INCLUDE_DIRS - Where to find check.h.
# CHECK_LIBRARIES - List of libraries when using Check.
# CHECK_VERSION_STRING - The version of Check found.
#=============================================================================
# Copyright 2018 Silvio Clecio <silvioprog@gmail.com>
#
# This program 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;
# version 2.1 of the License.
#
# 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 GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
#=============================================================================
# Sat Jan 20 23:33:47 -03 2018
find_package(PkgConfig QUIET)
pkg_check_modules(PC_CHECK QUIET check)
find_path(CHECK_INCLUDE_DIR
NAMES check.h
HINTS ${PC_CHECK_INCLUDEDIR} ${PC_CHECK_INCLUDE_DIRS})
find_library(CHECK_LIBRARY
NAMES check libcheck
HINTS ${PC_CHECK_LIBDIR} ${PC_CHECK_LIBRARY_DIRS})
if