star-camera

Camera models
git clone git://git.meso-star.fr/star-camera.git
Log | Files | Refs | README | LICENSE

commit 0522f8073184d9c58ae75c9d033767af73eaf165
parent 8e715192bd0f8817692a92ae79cc5dbc82bdd8e8
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 30 Oct 2023 11:02:45 +0100

Merge branch 'feature_posix_make' into develop

Diffstat:
M.gitignore | 14+++++++-------
AMakefile | 177+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MREADME.md | 35++++++++++++++++++-----------------
Dcmake/CMakeLists.txt | 108-------------------------------------------------------------------------------
Aconfig.mk | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amake.sh | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ascam.pc.in | 11+++++++++++
7 files changed, 373 insertions(+), 132 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,12 +1,12 @@ .gitignore -CMakeCache.txt -CMakeFiles -Makefile -tmp [Bb]uild* *.sw[po] -*.[ao] -*.orig +*.[aod] +*.so *~ +test* +!test*.[ch] +.config +.test tags - +*.pc diff --git a/Makefile b/Makefile @@ -0,0 +1,177 @@ +# Copyright (C) 2021-2023 |Méso|Star> (contact@meso-star.com) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 program. If not, see <http://www.gnu.org/licenses/>. + +.POSIX: +.SUFFIXES: # Clean up default inference rules + +include config.mk + +LIBNAME_STATIC = libscam.a +LIBNAME_SHARED = libscam.so +LIBNAME = $(LIBNAME_$(LIB_TYPE)) + +################################################################################ +# Library building +################################################################################ +SRC =\ + src/scam.c\ + src/scam_log.c\ + src/scam_orthographic.c\ + src/scam_perspective.c +OBJ = $(SRC:.c=.o) +DEP = $(SRC:.c=.d) + +build_library: .config $(DEP) + @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \ + $$(if [ -n "$(LIBNAME)" ]; then \ + echo "$(LIBNAME)"; \ + else \ + echo "$(LIBNAME_SHARED)"; \ + fi) + +$(DEP) $(OBJ): config.mk + +$(LIBNAME_SHARED): $(OBJ) + $(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(RSYS_LIBS) -lm + +$(LIBNAME_STATIC): libscam.o + $(AR) -rc $@ $? + $(RANLIB) $@ + +libscam.o: $(OBJ) + $(LD) -r $(OBJ) -o $@ + $(OBJCOPY) $(OCPFLAGS) $@ + +.config: config.mk + @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then\ + echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi + @echo "config done" > $@ + +.SUFFIXES: .c .d .o +.c.d: + @$(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ + +.c.o: + $(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -DSCAM_SHARED_BUILD -c $< -o $@ + +################################################################################ +# Installation +################################################################################ +pkg: + sed -e 's#@PREFIX@#$(PREFIX)#g'\ + -e 's#@VERSION@#$(VERSION)#g'\ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ + scam.pc.in > scam.pc + +scam-local.pc: scam.pc.in + sed -e '1d'\ + -e 's#^includedir=.*#includedir=./src/#'\ + -e 's#^libdir=.*#libdir=./#'\ + -e 's#@VERSION@#$(VERSION)#g'\ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ + scam.pc.in > $@ + +install: build_library pkg + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME) + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" scam.pc + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/scam.h + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/star-cam" COPYING README.md + +uninstall: + rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)" + rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/scam.pc" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-cam/COPYING" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-cam/README.md" + rm -f "$(DESTDIR)$(PREFIX)/include/star/scam.h" + +################################################################################ +# Miscellaneous targets +################################################################################ +all: build_library build_tests + +clean: clean_test + rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) + rm -f .config .test libscam.o scam.pc scam-local.pc + +distclean: clean + rm -f $(DEP) $(TEST_DEP) + +lint: + shellcheck -o all make.sh + +################################################################################ +# Tests +################################################################################ +TEST_SRC =\ + src/test_scam_orthographic.c\ + src/test_scam_perspective_pinhole.c\ + src/test_scam_perspective_thin_lens.c +TEST_OBJ = $(TEST_SRC:.c=.o) +TEST_DEP = $(TEST_SRC:.c=.d) + +S3D_FOUND = $(PKG_CONFIG) --atleast-version $(S3D_VERSION) s3d + +PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) +SCAM_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags scam-local.pc) +SCAM_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs scam-local.pc) + +build_tests: build_library $(TEST_DEP) .test + @$(MAKE) -fMakefile -f.test \ + $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \ + $$($(S3D_FOUND) && echo "-fsrc/test_scam_cbox.d") \ + test_bin + +test: build_tests + @$(SHELL) make.sh run_test $(TEST_SRC) + @if $(S3D_FOUND); then \ + $(SHELL) make.sh check test_scam_cbox_orthographic \ + test_scam_cbox orthographic pinhole; \ + $(SHELL) make.sh check test_scam_cbox_perspective_pinhole \ + test_scam_cbox perspective pinhole; \ + $(SHELL) make.sh check test_scam_cbox_perspective_thin_lens \ + test_scam_cbox perspective thin-lens; \ + fi + +.test: Makefile + @{ $(SHELL) make.sh config_test $(TEST_SRC); \ + if $(S3D_FOUND); then \ + $(SHELL) make.sh config_test src/test_scam_cbox.c; fi \ + } > $@ + +clean_test: + $(SHELL) make.sh clean_test $(TEST_SRC) src/test_scam_cbox.c + +$(TEST_DEP): config.mk scam-local.pc + @$(CC) $(CFLAGS_EXE) $(SCAM_CFLAGS) $(RSYS_CFLAGS) \ + -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +src/test_scam_cbox.d: config.mk scam-local.pc + @$(CC) $(CFLAGS_EXE) $(SCAM_CFLAGS) $(RSYS_CFLAGS) $(S3D_CFLAGS) \ + -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +$(TEST_OBJ): config.mk scam-local.pc + $(CC) $(CFLAGS_EXE) $(SCAM_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ + +src/test_scam_cbox.o: config.mk scam-local.pc + $(CC) $(CFLAGS_EXE) $(SCAM_CFLAGS) $(RSYS_CFLAGS) $(S3D_CFLAGS) -c $(@:.o=.c) -o $@ + +test_scam_orthographic \ +test_scam_perspective_pinhole \ +test_scam_perspective_thin_lens \ +: config.mk scam-local.pc $(LIBNAME) + $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(SCAM_LIBS) $(RSYS_LIBS) -lm + +test_scam_cbox: config.mk scam-local.pc $(LIBNAME) + $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(SCAM_LIBS) $(RSYS_LIBS) $(S3D_LIBS) -lm diff --git a/README.md b/README.md @@ -1,19 +1,20 @@ -# Star-Camera +# Star Camera -Star-Camera is C library whose purpose is to simulate camera model. +This C library implements camera models such as pinhole, thin lens and +orthographic projection. -## How to build +## Requirements -Star-Camera relies on the [CMake](http://www.cmake.org) and the -[RCMake](https://gitlab.com/vaplv/rcmake/) packages to build. It also depends -on the [RSys](https://gitlab.com/vaplv/rsys/) library. +- C compiler +- POSIX make +- pkg-config +- [RSys](https://gitlab.com/vaplv/rsys) -First ensure that CMake is installed on your system. Then install the RCMake -package and the RSys library. Finally generate the project from the -`cmake/CMakeLists.txt` file by appending to the `CMAKE_PREFIX_PATH` variable -the install directories of its dependencies. The resulting project can be -edited, built, tested and installed as any CMake project. Refer to the -[CMake](https://cmake.org/documentation) for further informations on CMake. +## Installation + +Edit config.mk as needed, then run: + + make clean install ## Release notes @@ -23,8 +24,8 @@ Add the `scam_perspective_get_solid_angle` function. ## License -Copyright (C) 2021-2023 [|Méso|Star>](https://www.meso-star.com) -(<contact@meso-star.com>). Star-Camera is free software -released under the GPL v3+ license: GNU GPL version 3 or later. You are welcome -to redistribute it under certain conditions; refer to the COPYING file for -details. +Copyright (C) 2021-2023 |Méso|Star> (contact@meso-star.com) + +Star-Cam is free software released under the GPL v3+ license: GNU GPL version 3 +or later. You are welcome to redistribute it under certain conditions; refer to +the COPYING file for details. diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -1,108 +0,0 @@ -# Copyright (C) 2021-2023 |Méso|Star> (contact@meso-star.com) -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program 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 program. If not, see <http://www.gnu.org/licenses/>. - -cmake_minimum_required(VERSION 3.1) -project(scam C) -enable_testing() - -set(SCAM_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src) -option(NO_TEST "Do not build tests" OFF) - -################################################################################ -# Check dependencies -################################################################################ -find_package(RCMake 0.4 REQUIRED) -find_package(RSys 0.9 REQUIRED) -find_package(Star3D 0.8 QUIET) - -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR}) -include(rcmake) -include(rcmake_runtime) - -include_directories(${RSys_INCLUDE_DIR}) - -################################################################################ -# Configure and define targets -################################################################################ -set(VERSION_MAJOR 0) -set(VERSION_MINOR 1) -set(VERSION_PATCH 0) -set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) - -set(SCAM_FILES_SRC - scam.c - scam_log.c - scam_orthographic.c - scam_perspective.c) -set(SCAM_FILES_INC - scam_c.h - scam_log.h) -set(SCAM_FILES_INC_API scam.h) -set(SCAM_FILES_DOC COPYING README.md) - -# Prepend each file in the `SCAM_FILES_<SRC|INC>' list by `SCAM_SOURCE_DIR' -rcmake_prepend_path(SCAM_FILES_SRC ${SCAM_SOURCE_DIR}) -rcmake_prepend_path(SCAM_FILES_INC ${SCAM_SOURCE_DIR}) -rcmake_prepend_path(SCAM_FILES_INC_API ${SCAM_SOURCE_DIR}) -rcmake_prepend_path(SCAM_FILES_DOC ${PROJECT_SOURCE_DIR}/../) - -add_library(scam SHARED ${SCAM_FILES_SRC} ${SCAM_FILES_INC} ${SCAM_FILES_INC_API}) -target_link_libraries(scam RSys m) - -set_target_properties(scam PROPERTIES - DEFINE_SYMBOL SCAM_SHARED_BUILD - VERSION ${VERSION} - SOVERSION ${VERSION_MAJOR}) - -rcmake_setup_devel(scam StarCamera ${VERSION} star/scam_version.h) - -################################################################################ -# Add tests -################################################################################ -if(NOT NO_TEST) - function(build_test _name) - add_executable(${_name} ${SCAM_SOURCE_DIR}/${_name}.c) - target_link_libraries(${_name} scam RSys) - endfunction() - - function(new_test _name) - build_test(${_name}) - add_test(${_name} ${_name}) - endfunction() - - new_test(test_scam_orthographic) - new_test(test_scam_perspective_pinhole) - new_test(test_scam_perspective_thin_lens) - - if(Star3D_FOUND) - build_test(test_scam_cbox) - target_link_libraries(test_scam_cbox Star3D) - - add_test(test_scam_cbox_orthographic test_scam_cbox orthographic pinhole) - add_test(test_scam_cbox_perspective_pinhole test_scam_cbox perspective pinhole) - add_test(test_scam_cbox_perspective_thin_lens test_scam_cbox perspective thin-lens) - endif() -endif() - -################################################################################ -# Define output & install directories -################################################################################ -install(TARGETS scam - ARCHIVE DESTINATION bin - LIBRARY DESTINATION lib - RUNTIME DESTINATION bin) -install(FILES ${SCAM_FILES_INC_API} DESTINATION include/star) -install(FILES ${SCAM_FILES_DOC} DESTINATION share/doc/star-camera) - diff --git a/config.mk b/config.mk @@ -0,0 +1,82 @@ +VERSION = 0.1.0 +PREFIX = /usr/local + +LIB_TYPE = SHARED +#LIB_TYPE = STATIC + +BUILD_TYPE = RELEASE +#BUILD_TYPE = DEBUG + +################################################################################ +# Tools +################################################################################ +AR = ar +CC = cc +LD = ld +OBJCOPY = objcopy +PKG_CONFIG = pkg-config +RANLIB = ranlib + +################################################################################ +# Dependencies +################################################################################ +PCFLAGS_SHARED = +PCFLAGS_STATIC = --static +PCFLAGS = $(PCFLAGS_$(LIB_TYPE)) + +RSYS_VERSION = 0.9 +RSYS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys) +RSYS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys) + +# Optional dependency (for tests) +S3D_VERSION = 0.8 +S3D_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags s3d) +S3D_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs s3d) + +################################################################################ +# Compilation options +################################################################################ +WFLAGS =\ + -Wall\ + -Wcast-align\ + -Wconversion\ + -Wextra\ + -Wmissing-declarations\ + -Wmissing-prototypes\ + -Wshadow + +CFLAGS_HARDENED =\ + -D_FORTIFY_SOURCES=2\ + -fcf-protection=full\ + -fstack-clash-protection\ + -fstack-protector-strong + +CFLAGS_COMMON =\ + -std=c89\ + -pedantic\ + -fvisibility=hidden\ + -fstrict-aliasing\ + $(CFLAGS_HARDENED)\ + $(WFLAGS) + +CFLAGS_DEBUG = -g $(CFLAGS_COMMON) +CFLAGS_RELEASE = -O2 -DNDEBUG $(CFLAGS_COMMON) +CFLAGS = $(CFLAGS_$(BUILD_TYPE)) + +CFLAGS_SO = $(CFLAGS) -fPIC +CFLAGS_EXE = $(CFLAGS) -fPIE + +################################################################################ +# Linker options +################################################################################ +LDFLAGS_HARDENED = -Wl,-z,relro,-z,now +LDFLAGS_DEBUG = $(LDFLAGS_HARDENED) +LDFLAGS_RELEASE = -s $(LDFLAGS_HARDENED) +LDFLAGS = $(LDFLAGS_$(BUILD_TYPE)) + +LDFLAGS_SO = $(LDFLAGS) -shared -Wl,--no-undefined +LDFLAGS_EXE = $(LDFLAGS) -pie + +OCPFLAGS_DEBUG = --localize-hidden +OCPFLAGS_RELEASE = --localize-hidden --strip-unneeded +OCPFLAGS = $(OCPFLAGS_$(BUILD_TYPE)) diff --git a/make.sh b/make.sh @@ -0,0 +1,78 @@ +#!/bin/sh + +# Copyright (C) 2021-2023 |Méso|Star> (contact@meso-star.com) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 program. If not, see <http://www.gnu.org/licenses/>. + +set -e + +config_test() +{ + for i in "$@"; do + test=$(basename "${i}" ".c") + test_list="${test_list} ${test}" + printf "%s: %s\n" "${test}" "src/${test}.o" + done + printf "test_bin: %s\n" "${test_list}" +} + +check() +{ + name="$1" + prog="$2" + shift 2 + + printf "%s " "${name}" + if ./"${prog}" "$@" > /dev/null 2>&1; then + printf "\033[1;32mOK\033[m\n" + else + printf "\033[1;31mError\033[m\n" + fi 2> /dev/null +} + +run_test() +{ + for i in "$@"; do + test=$(basename "${i}" ".c") + check "${test}" "${test}" + done 2> /dev/null +} + +clean_test() +{ + for i in "$@"; do + rm -f "$(basename "${i}" ".c")" + done +} + +install() +{ + prefix=$1 + shift 1 + + mkdir -p "${prefix}" + + for i in "$@"; do + dst="${prefix}/${i##*/}" + + if cmp -s "${i}" "${dst}"; then + printf "Up to date %s\n" "${dst}" + else + printf "Installing %s\n" "${dst}" + cp "${i}" "${prefix}" + fi + done +} + +"$@" diff --git a/scam.pc.in b/scam.pc.in @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +includedir=${prefix}/include +libdir=${prefix}/lib + +Requires: rsys >= @RSYS_VERSION@ +Name: Star-Cam +Description: Star Camera library +Version: @VERSION@ +Libs: -L${libdir} -lscam +Libs.private: -lm +CFlags: -I${includedir}