|
From: <kin...@us...> - 2025-09-04 19:11:51
|
Revision: 7355
http://sourceforge.net/p/teem/code/7355
Author: kindlmann
Date: 2025-09-04 19:11:50 +0000 (Thu, 04 Sep 2025)
Log Message:
-----------
preparing a better demo
Added Paths:
-----------
teem/trunk/UseTeemCMakeDemo/00-Readme.txt
teem/trunk/UseTeemCMakeDemo/CMakeLists-v2.txt
teem/trunk/UseTeemCMakeDemo/testio.c
Added: teem/trunk/UseTeemCMakeDemo/00-Readme.txt
===================================================================
--- teem/trunk/UseTeemCMakeDemo/00-Readme.txt (rev 0)
+++ teem/trunk/UseTeemCMakeDemo/00-Readme.txt 2025-09-04 19:11:50 UTC (rev 7355)
@@ -0,0 +1,39 @@
+This is a simple demo of how another C program can use CMake to link
+with a CMake-built Teem (it also reflects how I (GLK) am belatedly
+understanding how CMake works).
+
+Steps:
+
+1) Set TEEM_DIR to the path to where CMake installed Teem. There should be
+`bin`, `include`, `lib`, subdirectories, and the `lib/cmake` will record how
+CMake built Teem. Then:
+
+ ls $TEEM_DIR
+
+should show `bin`, `include`, `lib`.
+
+2) The following will create a `build` subdirectory right here where testio.c
+is, doing the configure and generate steps of CMake:
+
+ cmake -S . -B build \
+ -DCMAKE_PREFIX_PATH=$TEEM_DIR \
+ -DCMAKE_INSTALL_PREFIX=install
+
+The `.` argument to `cmake -S` is the path to the source directory, and the
+`build` argument to `cmake -B` is the path to the new testio build directory.
+After the `find_package` in ./CMakeLists.txt runs, CMake will set its own
+`Teem_DIR` variable to $TEEM_DIR. The `install` local (relative) path will be
+the subdirectory that CMake will install into later.
+
+3) To build in a way that is agnostic w.r.t. build system:
+
+ cmake --build build
+
+which means: run the "build" step (first "--build") in the local `build`
+subdirectory (second "build"). Or if you like running make:
+
+ (cd build; make)
+
+4) To install:
+
+ cmake --install build
Added: teem/trunk/UseTeemCMakeDemo/CMakeLists-v2.txt
===================================================================
--- teem/trunk/UseTeemCMakeDemo/CMakeLists-v2.txt (rev 0)
+++ teem/trunk/UseTeemCMakeDemo/CMakeLists-v2.txt 2025-09-04 19:11:50 UTC (rev 7355)
@@ -0,0 +1,24 @@
+
+# Shows how to use CMake to make an executable that depends on Teem
+
+# Actually this version requirement may be needlessly high; an earlier
+# CMake version may also work; probably anything above 3.0
+cmake_minimum_required(VERSION 3.14)
+
+# Set (demo) project name, initialize compiler detection and compiler flags
+project(TestNrrdIO LANGUAGES C)
+
+# Find Teem (must be installed in CMAKE_PREFIX_PATH or default system paths)
+find_package(Teem REQUIRED)
+
+# Associate one executable testio with project
+add_executable(testio testio.c)
+
+# Link testio against the imported target, which brings in include paths and
+# transitive dependencies automatically
+target_link_libraries(testio PRIVATE Teem::Teem)
+
+# Install the testio binary into ${CMAKE_INSTALL_PREFIX}/bin
+install(TARGETS testio
+ RUNTIME DESTINATION bin # for executables on all platforms
+)
Added: teem/trunk/UseTeemCMakeDemo/testio.c
===================================================================
--- teem/trunk/UseTeemCMakeDemo/testio.c (rev 0)
+++ teem/trunk/UseTeemCMakeDemo/testio.c 2025-09-04 19:11:50 UTC (rev 7355)
@@ -0,0 +1,88 @@
+/*
+ testio.c: demos nrrdSanity(), nrrdLoad(), nrrdSave from Teem
+ Copyright (C) 2025
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must
+ not claim that you wrote the original software. If you use this
+ software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and must
+ not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include <teem/nrrd.h>
+
+static void
+usage(const char *me) {
+ /* 0 1 2 (3) */
+ fprintf(stderr, "usage: %s [<input> [<output>]]\n", me);
+ fprintf(stderr, "<input> is file for nrrdLoad() to read (or - for stdin)\n");
+ fprintf(stderr, "<output> is where nrrdSave() writes to (or - for stout)\n");
+}
+
+int
+main(int argc, const char *argv[]) {
+ int ret;
+ const char *me;
+ char *err;
+
+ me = argv[0];
+ if (argc > 3 || (argc == 2 && !strcmp("--help", argv[1]))) {
+ usage(me);
+ return 1;
+ }
+
+ /* we start by running nrrdSanity in any case */
+ if (!nrrdSanity()) {
+ fprintf(stderr, "%s: nrrdSanity() failed:\n%s", me, err = biffGetDone(NRRD));
+ free(err);
+ return 1;
+ }
+ /* else */
+ fprintf(stderr, "%s: nrrdSanity() passed\n", me);
+ if (argc <= 1) {
+ /* we're done */
+ return 1;
+ }
+
+ const char *fin = argv[1];
+ Nrrd *nrrd = nrrdNew();
+ if (nrrdLoad(nrrd, fin, NULL)) {
+ fprintf(stderr, "%s: trouble loading \"%s\":\n%s", me, fin, err = biffGet(NRRD));
+ free(err);
+ return 1;
+ } else {
+ printf("%s: loaded array from \"%s\"\n", me, fin);
+ }
+
+ /* describe the nrrd just read in */
+ printf("%s: Describing array:\n", me);
+ nrrdDescribe(stdout, nrrd);
+ if (argc == 2) {
+ /* we're done */
+ return 1;
+ }
+
+ /* write out the array */
+ const char *fout = argv[2];
+ if (nrrdSave(fout, nrrd, NULL)) {
+ fprintf(stderr, "%s: trouble writing to\"%s\":\n%s", me, fout, err = biffGet(NRRD));
+ free(err);
+ return 1;
+ } else {
+ printf("%s: saved array to \"%s\"\n", me, fout);
+ }
+
+ return 0;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|