[segyio] 29/376: Build and test on macOS

Jørgen Kvalsvik jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:02 UTC 2017


This is an automated email from the git hooks/post-receive script.

jokva-guest pushed a commit to branch debian
in repository segyio.

commit 5103b5077123def9229154651de184a6e8477295
Author: Jean-Paul Balabanian <jepebe at users.noreply.github.com>
Date:   Mon Oct 10 10:46:24 2016 +0200

    Build and test on macOS
---
 .travis.yml           | 58 ++++++++++++++++++++++++++++++++++--------------
 CMakeLists.txt        | 61 +++++++++++++++++++++++----------------------------
 README.md             |  2 +-
 cmake/python.cmake    | 11 ++++++----
 python/CMakeLists.txt | 21 ++++++++++++++++++
 tests/test_utils.c    |  2 +-
 tests/unittest.h      |  6 ++---
 7 files changed, 102 insertions(+), 59 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 9411129..64b69ae 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,20 +1,46 @@
-language: c
+language: generic
+
+env:
+  - BUILD_TYPE=RELEASE
+  - BUILD_TYPE=DEBUG
+
+os:
+  - linux
+  - osx
+
+compiler:
+  - gcc
+  - clang
 
 matrix:
-  include:
-    - os: linux
-      compiler: gcc
+    exclude:
+        - os: osx
+          compiler: gcc
+        - os: linux
+          compiler: clang
 
 addons:
-  apt:
-    packages:
-      - valgrind
-      - python-numpy
-
-script:
-    - mkdir build
-    - cd build
-    - cmake ..
-    - make -j2
-    - export LD_LIBRARY_PATH=$PWD
-    - ctest -j2 --output-on-failure
\ No newline at end of file
+    apt:
+      sources:
+        - george-edison55-precise-backports
+      packages:
+        - cmake
+        - cmake-data
+        - valgrind
+        - python-numpy
+
+before_script:
+  # Valgrind is experimental(ish) on MacOS with false positives on among others printf
+  #- if [[ "$TRAVIS_OS_NAME" == "osx" && "$BUILD_TYPE" == "DEBUG" ]]; then
+  #    brew update;
+  #    brew install --HEAD valgrind;
+  #  fi
+
+  - cmake --version
+  - mkdir build
+  - cd build
+  - cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..
+  - make
+  - export LD_LIBRARY_PATH=$PWD
+
+script: make && ctest --output-on-failure
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a3e37e2..a6a53e7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,9 +1,18 @@
-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 2.8.8)
 project(segyio)
 
-if(POLICY CMP0042)
+if (POLICY CMP0042)
     cmake_policy(SET CMP0042 NEW)
-endif()
+endif ()
+
+if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+    set(MAC_OS TRUE)
+elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+    set(LINUX TRUE)
+    set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}")
+elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
+    set(WINDOWS TRUE)
+endif ()
 
 option(BUILD_MEX    "Build Matlab mex files"    OFF)
 option(BUILD_PYTHON "Build Python wrappers"     ON)
@@ -14,10 +23,12 @@ enable_testing()
 set(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}")
 
 if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
-    set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Default install path" FORCE )
-endif()
+    set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Default install path" FORCE)
+endif ()
 
-#set(CMAKE_BUILD_TYPE RELEASE)
+if(NOT CMAKE_BUILD_TYPE)
+    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
+endif(NOT CMAKE_BUILD_TYPE)
 
 include_directories(src)
 
@@ -25,38 +36,16 @@ set(SOURCE_FILES src/segyio/segy.c src/spec/segyspec.c)
 
 install(FILES src/segyio/segy.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/segyio)
 
-add_library(segyio-static STATIC ${SOURCE_FILES})
+# The object library type is a reusable component for later builds: shared, static and python
+add_library(segyio-object OBJECT ${SOURCE_FILES})
+
+add_library(segyio-static STATIC $<TARGET_OBJECTS:segyio-object>)
 set_target_properties(segyio-static PROPERTIES OUTPUT_NAME segyio CLEAN_DIRECT_OUTPUT 1)
 set_target_properties(segyio-static PROPERTIES COMPILE_FLAGS "-fPIC")
 
-add_library(segyio-shared SHARED ${SOURCE_FILES})
+add_library(segyio-shared SHARED $<TARGET_OBJECTS:segyio-object>)
 set_target_properties(segyio-shared PROPERTIES OUTPUT_NAME segyio CLEAN_DIRECT_OUTPUT 1)
 
-
-if(BUILD_PYTHON)
-    find_package(PythonInterp)
-    find_package(PythonLibs REQUIRED)
-
-    if (PYTHONLIBS_FOUND)
-        include_directories(${PYTHON_INCLUDE_DIRS})
-        add_library(_segyio SHARED python/segyio/_segyio.c ${SOURCE_FILES})
-
-        if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
-            set_target_properties(_segyio PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
-        else()
-            set_target_properties(_segyio PROPERTIES LINK_FLAGS "-Xlinker -export-dynamic")
-        endif()
-
-        set_target_properties(_segyio PROPERTIES PREFIX "" SUFFIX ".so")
-        install(TARGETS _segyio DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/python2.7/site-packages/segyio)
-
-        add_custom_command(TARGET _segyio POST_BUILD
-                COMMAND ${CMAKE_COMMAND} -E copy
-                ${CMAKE_BINARY_DIR}/_segyio.so ${CMAKE_BINARY_DIR}/python/segyio/_segyio.so)
-    endif()
-    add_subdirectory(python)
-endif()
-
 install(TARGETS segyio-static segyio-shared DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
 
 add_executable(segyinfo src/applications/segyinfo.c)
@@ -79,7 +68,11 @@ else (BUILD_MEX)
     unset(MATLAB_MEXEXT CACHE)
     unset(MATLAB_ROOT CACHE)
     unset(BUILD_MEX_TESTS CACHE)
-endif()
+endif ()
+
+if (BUILD_PYTHON)
+    add_subdirectory(python)
+endif ()
 
 add_subdirectory(tests)
 add_subdirectory(examples)
diff --git a/README.md b/README.md
index 7fcb781..bdc6c87 100644
--- a/README.md
+++ b/README.md
@@ -44,7 +44,7 @@ interpreter and type `help(segyio)` to get started.
 
 To build and use Segyio you need:
  * A C99 compatible C compiler (tested mostly on gcc and clang)
- * [CMake](https://cmake.org/) version 2.8 or greater
+ * [CMake](https://cmake.org/) version 2.8.8 or greater
  * [Python](https://www.python.org/) 2.7. We're working on 3.x support, help
    appreciated!
 
diff --git a/cmake/python.cmake b/cmake/python.cmake
index 56fead3..42dcf0f 100644
--- a/cmake/python.cmake
+++ b/cmake/python.cmake
@@ -1,15 +1,18 @@
 configure_file(cmake/test_runner.py tests/test_runner.py COPYONLY)
 
-if("${CMAKE_HOST_SYSTEM}" MATCHES ".*Windows.*")
+if(WINDOWS)
     set(SEP "\\;")
 else() # e.g. Linux
     set(SEP ":")
 endif()
 
 function(add_memcheck_test NAME BINARY)
-    set(memcheck_command "valgrind --trace-children=yes --leak-check=full --error-exitcode=31415")
-    separate_arguments(memcheck_command)
-    add_test(memcheck_${NAME} ${memcheck_command} ./${BINARY})
+    # Valgrind on MacOS is experimental
+    if(LINUX AND (${CMAKE_BUILD_TYPE} MATCHES "DEBUG"))
+        set(memcheck_command "valgrind --trace-children=yes --leak-check=full --error-exitcode=31415")
+        separate_arguments(memcheck_command)
+        add_test(memcheck_${NAME} ${memcheck_command} ./${BINARY})
+    endif()
 endfunction(add_memcheck_test)
 
 function(add_python_package PACKAGE_NAME PACKAGE_PATH PYTHON_FILES)
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index 69dade6..fa50f0a 100644
--- a/python/CMakeLists.txt
+++ b/python/CMakeLists.txt
@@ -1 +1,22 @@
+find_package(PythonInterp)
+find_package(PythonLibs REQUIRED)
+
+if (PYTHONLIBS_FOUND)
+    include_directories(${PYTHON_INCLUDE_DIRS})
+    add_library(_segyio SHARED segyio/_segyio.c $<TARGET_OBJECTS:segyio-object>)
+
+    if (MAC_OS)
+        set_target_properties(_segyio PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
+    else ()
+        set_target_properties(_segyio PROPERTIES LINK_FLAGS "-Xlinker -export-dynamic")
+    endif ()
+
+    set_target_properties(_segyio PROPERTIES PREFIX "" SUFFIX ".so")
+    install(TARGETS _segyio DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/python2.7/site-packages/segyio)
+
+    add_custom_command(TARGET _segyio POST_BUILD
+            COMMAND ${CMAKE_COMMAND} -E copy
+            $<TARGET_FILE:_segyio> ${CMAKE_BINARY_DIR}/python/segyio/_segyio.so)
+endif ()
+
 add_subdirectory(segyio)
\ No newline at end of file
diff --git a/tests/test_utils.c b/tests/test_utils.c
index a88164d..f4e9c63 100644
--- a/tests/test_utils.c
+++ b/tests/test_utils.c
@@ -88,7 +88,7 @@ void testIBMFloat() {
         check(f1, &epsm);
         check(-f1, &epsm);
     }
-    printf("Max eps: %g\n", epsm);
+    assertClose(4.17233e-07, epsm, 1e-06);
 }
 
 int to_int16( const char* );
diff --git a/tests/unittest.h b/tests/unittest.h
index 72afdcd..b4af6ad 100644
--- a/tests/unittest.h
+++ b/tests/unittest.h
@@ -29,9 +29,9 @@ void _testAssertTrue(bool value, const char *message, const char *file, int line
 
 #define assertClose(expected, actual, eps) _testAssertClose((expected), (actual), (eps), __FILE__, __LINE__)
 
-void _testAssertClose(float expected, float actual, float eps, const char *file, int line) {
-    float diff = fabsf(expected-actual);
-    if (!(diff <= eps)) {
+void _testAssertClose(double expected, double actual, double eps, const char *file, int line) {
+    double diff = fabs(expected-actual);
+    if (diff > eps) {
         char message[1000];
         sprintf(message, "Expected: %f, Actual: %f, diff: %f, eps: %f\n", expected, actual, diff, eps);
         testAssertionFailed(message, file, line);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/segyio.git



More information about the debian-science-commits mailing list