-
Notifications
You must be signed in to change notification settings - Fork 27
/
CMakeLists.txt
125 lines (102 loc) · 4.23 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
############################################################################
# Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht #
# #
# Distributed under the terms of the BSD 3-Clause License. #
# #
# The full license is in the file LICENSE, distributed with this software. #
############################################################################
cmake_minimum_required(VERSION 3.1)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
project(xtensor-io-test)
find_package(xtensor REQUIRED CONFIG)
set(XTENSOR_INCLUDE_DIR ${xtensor_INCLUDE_DIRS})
endif ()
message(STATUS "Forcing tests build type to Release")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
include(CheckCXXCompilerFlag)
string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion")
CHECK_CXX_COMPILER_FLAG("-std=c++14" HAS_CPP14_FLAG)
if (HAS_CPP14_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
else()
message(FATAL_ERROR "Unsupported compiler -- xtensor requires C++14 support!")
endif()
endif()
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /bigobj")
set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO)
endif()
if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
if(DOWNLOAD_GTEST)
# Download and unpack googletest at configure time
configure_file(downloadGTest.cmake.in googletest-download/CMakeLists.txt)
else()
# Copy local source of googletest at configure time
configure_file(copyGTest.cmake.in googletest-download/CMakeLists.txt)
endif()
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build)
set(GTEST_INCLUDE_DIRS "${gtest_SOURCE_DIR}/include")
set(GTEST_BOTH_LIBRARIES gtest_main gtest)
else()
find_package(GTest REQUIRED)
endif()
find_package(Threads)
find_package(OIIO REQUIRED)
find_package(ZLIB REQUIRED)
include_directories(${XTENSOR_INCLUDE_DIR})
include_directories(${XTENSOR_IO_INCLUDE_DIR})
include_directories(${OIIO_INCLUDE_DIRS})
include_directories(${ZLIB_INCLUDE_DIRS})
include_directories(${xtl_INCLUDE_DIRS})
include_directories(${GTEST_INCLUDE_DIRS})
set(XTENSOR_IO_TESTS
main.cpp
test_xnpz.cpp
test_ximageio.cpp
)
set(XTENSOR_IO_TARGET test_xtensor_io)
# Add files for npy tests
set(XTENSOR_IO_FILES
compressed.npz
uncompressed.npz
test.png
test.jpg
test.gif
big.jpg
)
foreach(filename IN LISTS XTENSOR_IO_FILES)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/files/${filename}
${CMAKE_CURRENT_BINARY_DIR}/files/${filename} COPYONLY)
endforeach()
add_executable(${XTENSOR_IO_TARGET} ${XTENSOR_IO_TESTS} ${XTENSOR_IO_HEADERS})
if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
add_dependencies(${XTENSOR_IO_TARGET} gtest_main)
endif()
message("OIIO_LIBRARIES: ${OIIO_LIBRARIES}")
target_link_libraries(${XTENSOR_IO_TARGET}
${ZLIB_LIBRARIES}
${OIIO_LIBRARIES}
${CMAKE_DL_LIBS}
${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
add_custom_target(xtest
COMMAND test_xtensor_io
DEPENDS ${XTENSOR_IO_TARGET})