Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[*] repository merging #11

Closed
wants to merge 10 commits into from
765 changes: 760 additions & 5 deletions .gitignore

Large diffs are not rendered by default.

199 changes: 199 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
#
# Orcania Framework
#
# CMake file used to build all programs
#
# Copyright 2017 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
#
# 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.
#

# Written by Silvio Clecio <silvioprog@gmail.com>
# Fri Jan 19 20:01:43 -03 2018

cmake_minimum_required(VERSION 3.5)

project(orcania C)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")

# library info

set(PROJECT_DESCRIPTION "Potluck with different functions for different purposes that can be shared among programs")
set(PROJECT_BUGREPORT_PATH "https://github.com/babelouest/orcania/issues")

set(LIBRARY_VERSION_MAJOR "1")
set(LIBRARY_VERSION_MINOR "1")
set(LIBRARY_VERSION_PATCH "1")
set(LIBRARY_VERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}")
set(LIBRARY_SOVERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}")

add_definitions(-DLIBRARY_VERSION=\"${LIBRARY_VERSION}\")

# 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}/orcania.h # allow many IDEs to find and edit it
${SRC_DIR}/base64.c
${SRC_DIR}/memory.c
${SRC_DIR}/orcania.c)

# static library

add_library(orcania_static STATIC ${LIB_SRC})
target_compile_definitions(orcania_static PUBLIC -DO_STATIC_LIBRARY)
set_target_properties(orcania_static PROPERTIES
OUTPUT_NAME orcania)

# shared library

option(WITH_JANSSON "Use jansson library" ON)

if (WITH_JANSSON)
include(FindJansson)
find_package(Jansson)
set(WITH_JANSSON ${JANSSON_FOUND})
if (WITH_JANSSON)
set(LIBS ${JANSSON_LIBRARIES})
add_definitions(-DUSE_JANSSON=1)
endif ()
endif ()

add_library(orcania SHARED ${LIB_SRC})
set_target_properties(orcania PROPERTIES
COMPILE_OPTIONS -Wextra
PUBLIC_HEADER ${INC_DIR}/orcania.h
VERSION "${LIBRARY_VERSION}"
SOVERSION "${LIBRARY_SOVERSION}")
if (WIN32)
set_target_properties(orcania PROPERTIES SUFFIX "-${LIBRARY_VERSION_MAJOR}.dll")
endif ()
target_link_libraries(orcania ${LIBS})

# 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)
include(FindSubunit)
find_package(Subunit REQUIRED)

enable_testing()

set(CMAKE_CTEST_COMMAND ctest -V)

set(TST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test)
set(LIBS orcania ${LIBS} ${CHECK_LIBRARIES} ${SUBUNIT_LIBRARIES})
if (NOT WIN32)
find_package(Threads REQUIRED)
set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
endif ()
set(LIBS ${LIBS} m rt)

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

configure_file(liborcania.pc.in liborcania.pc @ONLY)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/liborcania.pc
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)

install(TARGETS orcania orcania_static
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

# 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})

set(PACKAGE_FILE_NAME
"${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(PACKAGE_IGNORED_FILES
"${CMAKE_CURRENT_BINARY_DIR}/;/.git/;.gitignore;/.idea/;~$;${CPACK_SOURCE_IGNORE_FILES}")

#set(CPACK_GENERATOR "TGZ;DEB;RPM")
#set(CPACK_DEBIAN_PACKAGE_MAINTAINER "silvioprog") # required
#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
COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
21 changes: 21 additions & 0 deletions cmake-modules/CMakeUninstall.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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)
2 changes: 2 additions & 0 deletions cmake-modules/CTestCustom.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
string(REPLACE ";" " " TESTS "@TESTS@")
set(CTEST_CUSTOM_PRE_TEST "@CMAKE_MAKE_PROGRAM@ ${TESTS}")
73 changes: 73 additions & 0 deletions cmake-modules/FindCheck.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#.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 (PC_CHECK_VERSION)
set(CHECK_VERSION_STRING ${PC_CHECK_VERSION})
elseif (CHECK_INCLUDE_DIR AND EXISTS "${CHECK_INCLUDE_DIR}/check.h")
set(check_version_list MAJOR MINOR MICRO)
foreach (v ${check_version_list})
set(regex_check_version "^#define CHECK_${v}_VERSION +\\(?([0-9]+)\\)?$")
file(STRINGS "${CHECK_INCLUDE_DIR}/check.h" check_version_${v} REGEX "${regex_check_version}")
string(REGEX REPLACE "${regex_check_version}" "\\1" check_version_${v} "${check_version_${v}}")
unset(regex_check_version)
endforeach ()
set(CHECK_VERSION_STRING "${check_version_MAJOR}.${check_version_MINOR}.${check_version_MICRO}")
foreach (v check_version_list)
unset(check_version_${v})
endforeach ()
unset(check_version_list)
endif ()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Check
REQUIRED_VARS CHECK_LIBRARY CHECK_INCLUDE_DIR
VERSION_VAR CHECK_VERSION_STRING)

if (CHECK_FOUND)
set(CHECK_LIBRARIES ${CHECK_LIBRARY})
set(CHECK_INCLUDE_DIRS ${CHECK_INCLUDE_DIR})
endif ()

mark_as_advanced(CHECK_INCLUDE_DIR CHECK_LIBRARY)
66 changes: 66 additions & 0 deletions cmake-modules/FindJansson.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#.rst:
# FindJansson
# -----------
#
# Find Jansson
#
# Find Jansson headers and libraries.
#
# ::
#
# JANSSON_FOUND - True if Jansson found.
# JANSSON_INCLUDE_DIRS - Where to find jansson.h.
# JANSSON_LIBRARIES - List of libraries when using Jansson.
# JANSSON_VERSION_STRING - The version of Jansson 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 12:32:26 -03 2018

find_package(PkgConfig QUIET)
pkg_check_modules(PC_JANSSON QUIET jansson)

find_path(JANSSON_INCLUDE_DIR
NAMES jansson.h
HINTS ${PC_JANSSON_INCLUDEDIR} ${PC_JANSSON_INCLUDE_DIRS})

find_library(JANSSON_LIBRARY
NAMES jansson libjansson
HINTS ${PC_JANSSON_LIBDIR} ${PC_JANSSON_LIBRARY_DIRS})

if (PC_JANSSON_VERSION)
set(JANSSON_VERSION_STRING ${PC_JANSSON_VERSION})
elseif (JANSSON_INCLUDE_DIR AND EXISTS "${JANSSON_INCLUDE_DIR}/jansson.h")
set(regex_jansson_version "^#define[ \t]+JANSSON_VERSION[ \t]+\"([^\"]+)\".*")
file(STRINGS "${JANSSON_INCLUDE_DIR}/jansson.h" jansson_version REGEX "${regex_jansson_version}")
string(REGEX REPLACE "${regex_jansson_version}" "\\1" JANSSON_VERSION_STRING "${jansson_version}")
unset(regex_jansson_version)
unset(jansson_version)
endif ()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Jansson
REQUIRED_VARS JANSSON_LIBRARY JANSSON_INCLUDE_DIR
VERSION_VAR JANSSON_VERSION_STRING)

if (JANSSON_FOUND)
set(JANSSON_LIBRARIES ${JANSSON_LIBRARY})
set(JANSSON_INCLUDE_DIRS ${JANSSON_INCLUDE_DIR})
endif ()

mark_as_advanced(JANSSON_INCLUDE_DIR JANSSON_LIBRARY)
Loading