tools/travis-ci/install.sh: workaround issue with jpylyzer on Mac
[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 if($ENV{OPJ_BINARY_DIR})
11         set( CTEST_DASHBOARD_ROOT  "$ENV{OPJ_BINARY_DIR}" )
12 else()
13         set( CTEST_DASHBOARD_ROOT  "$ENV{PWD}/build" )
14 endif()
15
16 if("$ENV{OPJ_SHORT_OS_NAME}" STREQUAL "windows")
17         set( CTEST_CMAKE_GENERATOR "NMake Makefiles")
18         set( CTEST_BUILD_COMMAND   "nmake" )
19         set( JPYLYZER_EXT          "exe"  )
20 else()
21         set( CTEST_CMAKE_GENERATOR "Unix Makefiles")   # Always makefile in travis-ci environment
22         set( CCFLAGS_WARNING "-Wall -Wextra -Wconversion -Wno-unused-parameter -Wdeclaration-after-statement -Werror=declaration-after-statement")
23         set( JPYLYZER_EXT          "py"  )
24 endif()
25
26 if ("$ENV{OPJ_BUILD_CONFIGURATION}" STREQUAL "")
27   set( CTEST_BUILD_CONFIGURATION "Release")
28 else()
29         set( CTEST_BUILD_CONFIGURATION "$ENV{OPJ_BUILD_CONFIGURATION}")
30 endif()
31
32 if ("$ENV{OPJ_SITE}" STREQUAL "")
33   set( CTEST_SITE "Unknown")
34 else()
35         set( CTEST_SITE "$ENV{OPJ_SITE}")
36 endif()
37
38 if ("$ENV{OPJ_BUILDNAME}" STREQUAL "")
39   set( CTEST_BUILD_NAME "Unknown-${CTEST_BUILD_CONFIGURATION}")
40 else()
41         set( CTEST_BUILD_NAME "$ENV{OPJ_BUILDNAME}")
42 endif()
43
44 if (NOT "$ENV{OPJ_CI_ARCH}" STREQUAL "")
45         if (APPLE)
46           set(CCFLAGS_ARCH "-arch $ENV{OPJ_CI_ARCH}")
47         else()
48                 if ("$ENV{OPJ_CI_ARCH}" MATCHES "^i[3-6]86$")
49                         set(CCFLAGS_ARCH "-m32 -march=$ENV{OPJ_CI_ARCH}")
50                 elseif ("$ENV{OPJ_CI_ARCH}" STREQUAL "x86_64")
51                         set(CCFLAGS_ARCH "-m64")
52                 endif()
53         endif()
54 endif()
55
56 if (NOT "$ENV{OPJ_CI_INSTRUCTION_SETS}" STREQUAL "")
57         set(CCFLAGS_ARCH "${CCFLAGS_ARCH} $ENV{OPJ_CI_INSTRUCTION_SETS}")
58 endif()
59
60
61 if ("$ENV{OPJ_CI_ASAN}" STREQUAL "1")
62         set(OPJ_HAS_MEMCHECK TRUE)
63         set(CTEST_MEMORYCHECK_TYPE "AddressSanitizer")
64         set(CCFLAGS_ARCH "${CCFLAGS_ARCH} -O1 -g -fsanitize=address -fno-omit-frame-pointer")
65 endif()
66
67 if("$ENV{CC}" MATCHES ".*mingw.*")
68         # We are trying to use mingw
69         if ("$ENV{OPJ_CI_ARCH}" MATCHES "^i[3-6]86$")
70                 set(CTEST_CONFIGURE_OPTIONS "-DCMAKE_TOOLCHAIN_FILE=${CTEST_SCRIPT_DIRECTORY}/toolchain-mingw32.cmake")
71         else()
72                 set(CTEST_CONFIGURE_OPTIONS "-DCMAKE_TOOLCHAIN_FILE=${CTEST_SCRIPT_DIRECTORY}/toolchain-mingw64.cmake")
73         endif()
74 endif()
75
76 if(NOT "$ENV{OPJ_CI_SKIP_TESTS}" STREQUAL "1")
77         # To execute part of the encoding test suite, kakadu binaries are needed to decode encoded image and compare
78         # it to the baseline. Kakadu binaries are freely available for non-commercial purposes
79         # at http://www.kakadusoftware.com.
80         # Here's the copyright notice from kakadu:
81         # Copyright is owned by NewSouth Innovations Pty Limited, commercial arm of the UNSW Australia in Sydney.
82         # You are free to trial these executables and even to re-distribute them,
83         # so long as such use or re-distribution is accompanied with this copyright notice and is not for commercial gain.
84         # Note: Binaries can only be used for non-commercial purposes.
85         if ("$ENV{OPJ_NONCOMMERCIAL}" STREQUAL "1" )
86                 set(KDUPATH $ENV{PWD}/kdu)
87                 if("$ENV{OPJ_SHORT_OS_NAME}" STREQUAL "windows")
88                         set(ENV{PATH} "$ENV{PATH};${KDUPATH}")
89                 else()
90                         set(ENV{LD_LIBRARY_PATH} ${KDUPATH})
91                         set(ENV{PATH} $ENV{PATH}:${KDUPATH})
92                 endif()
93         endif()
94         set(BUILD_TESTING "TRUE")
95 else()
96         set(BUILD_TESTING "FALSE")
97 endif(NOT "$ENV{OPJ_CI_SKIP_TESTS}" STREQUAL "1")
98
99
100 if("$ENV{OPJ_CI_CHECK_STYLE}" STREQUAL "1")
101         set(BUILD_ASTYLE "TRUE")
102 else()
103         set(BUILD_ASTYLE "FALSE")
104 endif("$ENV{OPJ_CI_CHECK_STYLE}" STREQUAL "1")
105
106 # Options
107 set( CACHE_CONTENTS "
108
109 # Build kind
110 CMAKE_BUILD_TYPE:STRING=${CTEST_BUILD_CONFIGURATION}
111
112 # Warning level
113 CMAKE_C_FLAGS:STRING= ${CCFLAGS_ARCH} ${CCFLAGS_WARNING}
114
115 # For astyle
116 CMAKE_CXX_FLAGS:STRING= ${CCFLAGS_ARCH}
117
118 # Use to activate the test suite
119 BUILD_TESTING:BOOL=${BUILD_TESTING}
120
121 # Build Thirdparty, useful but not required for test suite
122 BUILD_THIRDPARTY:BOOL=TRUE
123
124 # Build unit tests that test subcomponents of libopenjp2 (e.g. DWT)
125 BUILD_UNIT_TESTS:BOOL=TRUE
126
127 # JPEG2000 test files are available with git clone https://github.com/uclouvain/openjpeg-data.git
128 OPJ_DATA_ROOT:PATH=$ENV{PWD}/data
129
130 # Enable astyle
131 WITH_ASTYLE:BOOL=${BUILD_ASTYLE}
132 " )
133
134 if(EXISTS "$ENV{PWD}/jpylyzer/jpylyzer.${JPYLYZER_EXT}")
135     set(CACHE_CONTENTS "
136 ${CACHE_CONTENTS}
137
138 # jpylyzer is available with on GitHub: https://github.com/openpreserve/jpylyzer
139 JPYLYZER_EXECUTABLE=$ENV{PWD}/jpylyzer/jpylyzer.${JPYLYZER_EXT}
140 ")
141 endif()
142
143 #---------------------
144 #1. openjpeg specific:
145 set( CTEST_PROJECT_NAME "OPENJPEG" )
146 if(NOT EXISTS $ENV{OPJ_SOURCE_DIR})
147         message(FATAL_ERROR "OPJ_SOURCE_DIR not defined or does not exist:$ENV{OPJ_SOURCE_DIR}")
148 endif()
149 set( CTEST_SOURCE_DIRECTORY     "$ENV{OPJ_SOURCE_DIR}")
150 set( CTEST_BINARY_DIRECTORY     "${CTEST_DASHBOARD_ROOT}")
151
152 #---------------------
153 # Files to submit to the dashboard
154 set (CTEST_NOTES_FILES
155 ${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}
156 ${CTEST_BINARY_DIRECTORY}/CMakeCache.txt )
157
158 ctest_empty_binary_directory( "${CTEST_BINARY_DIRECTORY}" )
159 file(WRITE "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt" "${CACHE_CONTENTS}")
160
161 # Perform a Experimental build
162 ctest_start(Experimental)
163 #ctest_update(SOURCE "${CTEST_SOURCE_DIRECTORY}")
164 ctest_configure(BUILD "${CTEST_BINARY_DIRECTORY}" OPTIONS "${CTEST_CONFIGURE_OPTIONS}")
165 ctest_read_custom_files(${CTEST_BINARY_DIRECTORY})
166 ctest_build(BUILD "${CTEST_BINARY_DIRECTORY}")
167 if(NOT "$ENV{OPJ_CI_SKIP_TESTS}" STREQUAL "1")
168         ctest_test(BUILD "${CTEST_BINARY_DIRECTORY}" PARALLEL_LEVEL 2)
169         if(OPJ_HAS_MEMCHECK)
170                 ctest_memcheck(BUILD "${CTEST_BINARY_DIRECTORY}" PARALLEL_LEVEL 2)
171         endif()
172 endif()
173 if ("$ENV{OPJ_DO_SUBMIT}" STREQUAL "1")
174         ctest_submit()
175 endif()
176 # Do not clean, we'll parse the log for known failure
177 #ctest_empty_binary_directory( "${CTEST_BINARY_DIRECTORY}" )