36596a09c45b318cc2ac7b64d706c3d2457f533e
[openjpeg.git] / tools / ctest_scripts / travis-ci.cmake
1 # -----------------------------------------------------------------------------
2 # Travis-ci ctest script for OpenJPEG project
3 # This will compile/run tests/upload to cdash OpenJPEG
4 # Results will be available at: http://my.cdash.org/index.php?project=OPENJPEG
5 # -----------------------------------------------------------------------------
6
7 cmake_minimum_required(VERSION 2.8)
8
9 set( ENV{LANG} en_US.UTF-8)
10 set( CTEST_DASHBOARD_ROOT  "$ENV{PWD}/build" )
11 set( CTEST_CMAKE_GENERATOR "Unix Makefiles")   # Always makefile in travis-ci environment
12
13 if ("$ENV{OPJ_BUILD_CONFIGURATION}" STREQUAL "")
14   set( CTEST_BUILD_CONFIGURATION "Release")
15 else()
16         set( CTEST_BUILD_CONFIGURATION "$ENV{OPJ_BUILD_CONFIGURATION}")
17 endif()
18
19 if ("$ENV{OPJ_SITE}" STREQUAL "")
20   set( CTEST_SITE "Unknown")
21 else()
22         set( CTEST_SITE "$ENV{OPJ_SITE}")
23 endif()
24
25 if ("$ENV{OPJ_BUILDNAME}" STREQUAL "")
26   set( CTEST_BUILD_NAME "Unknown-${CTEST_BUILD_CONFIGURATION}")
27 else()
28         set( CTEST_BUILD_NAME "$ENV{OPJ_BUILDNAME}")
29 endif()
30
31 if (NOT "$ENV{OPJ_CI_ARCH}" STREQUAL "")
32         if (APPLE)
33           set(CCFLAGS_ARCH "-arch $ENV{OPJ_CI_ARCH}")
34         else()
35                 if ("$ENV{OPJ_CI_ARCH}" MATCHES "^i[3-6]86$")
36                         set(CCFLAGS_ARCH "-m32 -march=$ENV{OPJ_CI_ARCH}")
37                 elseif ("$ENV{OPJ_CI_ARCH}" STREQUAL "x86_64")
38                         set(CCFLAGS_ARCH "-m64")
39                 endif()
40         endif()
41 endif()
42
43 if ("$ENV{OPJ_CI_ASAN}" STREQUAL "1")
44         set(OPJ_HAS_MEMCHECK TRUE)
45         set(CTEST_MEMORYCHECK_TYPE "AddressSanitizer")
46         set(CCFLAGS_ARCH "${CCFLAGS_ARCH} -g -fsanitize=address -fno-omit-frame-pointer")
47         
48 endif()
49
50 if(NOT "$ENV{OPJ_CI_SKIP_TESTS}" STREQUAL "1")
51         # To execute part of the encoding test suite, kakadu binaries are needed to decode encoded image and compare 
52         # it to the baseline. Kakadu binaries are freely available for non-commercial purposes 
53         # at http://www.kakadusoftware.com.
54         # Here's the copyright notice from kakadu:
55         # Copyright is owned by NewSouth Innovations Pty Limited, commercial arm of the UNSW Australia in Sydney.
56         # You are free to trial these executables and even to re-distribute them,
57         # so long as such use or re-distribution is accompanied with this copyright notice and is not for commercial gain.
58         # Note: Binaries can only be used for non-commercial purposes.
59         if ("$ENV{OPJ_NONCOMMERCIAL}" STREQUAL "1" )
60                 set(KDUPATH $ENV{PWD}/kdu)
61                 set(ENV{LD_LIBRARY_PATH} ${KDUPATH})
62                 set(ENV{PATH} $ENV{PATH}:${KDUPATH})
63         endif()
64         set(BUILD_TESTING "TRUE")
65 else()
66         set(BUILD_TESTING "FALSE")
67 endif(NOT "$ENV{OPJ_CI_SKIP_TESTS}" STREQUAL "1")
68
69 # Options 
70 set( CACHE_CONTENTS "
71
72 # Build kind
73 CMAKE_BUILD_TYPE:STRING=${CTEST_BUILD_CONFIGURATION}
74
75 # Warning level
76 CMAKE_C_FLAGS:STRING= ${CCFLAGS_ARCH} -Wall -Wextra -Wconversion -Wno-unused-parameter -Wdeclaration-after-statement
77
78 # Use to activate the test suite
79 BUILD_TESTING:BOOL=${BUILD_TESTING}
80
81 # Build Thirdparty, useful but not required for test suite 
82 BUILD_THIRDPARTY:BOOL=TRUE
83
84 # JPEG2000 test files are available with git clone https://github.com/uclouvain/openjpeg-data.git
85 OPJ_DATA_ROOT:PATH=$ENV{PWD}/data
86
87 # jpylyzer is available with on GitHub: https://github.com/openpreserve/jpylyzer  
88 JPYLYZER_EXECUTABLE=$ENV{PWD}/jpylyzer/jpylyzer/jpylyzer.py
89
90 " )
91
92 #---------------------
93 #1. openjpeg specific: 
94 set( CTEST_PROJECT_NAME "OPENJPEG" )
95 if(NOT EXISTS $ENV{OPJ_SOURCE_DIR})
96         message(FATAL_ERROR "OPJ_SOURCE_DIR not defined or does not exist:$ENV{OPJ_SOURCE_DIR}")
97 endif()
98 set( CTEST_SOURCE_DIRECTORY     "$ENV{OPJ_SOURCE_DIR}")
99 set( CTEST_BINARY_DIRECTORY     "${CTEST_DASHBOARD_ROOT}")
100
101 #---------------------
102 # Files to submit to the dashboard
103 set (CTEST_NOTES_FILES
104 ${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}
105 ${CTEST_BINARY_DIRECTORY}/CMakeCache.txt )
106
107 ctest_empty_binary_directory( "${CTEST_BINARY_DIRECTORY}" )
108 file(WRITE "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt" "${CACHE_CONTENTS}")
109
110 # Perform a Experimental build
111 ctest_start(Experimental)
112 #ctest_update(SOURCE "${CTEST_SOURCE_DIRECTORY}")
113 ctest_configure(BUILD "${CTEST_BINARY_DIRECTORY}")
114 ctest_read_custom_files(${CTEST_BINARY_DIRECTORY})
115 ctest_build(BUILD "${CTEST_BINARY_DIRECTORY}")
116 if(NOT "$ENV{OPJ_CI_SKIP_TESTS}" STREQUAL "1")
117         ctest_test(BUILD "${CTEST_BINARY_DIRECTORY}" PARALLEL_LEVEL 2)
118         if(OPJ_HAS_MEMCHECK)
119                 ctest_memcheck(BUILD "${CTEST_BINARY_DIRECTORY}" PARALLEL_LEVEL 2)
120         endif()
121 endif()
122 if ("$ENV{OPJ_DO_SUBMIT}" STREQUAL "1")
123         ctest_submit()
124 endif()
125 ctest_empty_binary_directory( "${CTEST_BINARY_DIRECTORY}" )