Newer
Older

Sébastien Dinot
committed
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#
# Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
#
# This file is part of Orfeo Toolbox
#
# https://www.orfeo-toolbox.org/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set(OTB3P_INSTALL_EXPORT_NAME "${OTBSiftFast-targets}")
set(OTB3P_INSTALL_INCLUDE_DIR "${OTBSiftFast_INSTALL_INCLUDE_DIR}")
set(OTB3P_INSTALL_RUNTIME_DIR "${OTBSiftFast_INSTALL_RUNTIME_DIR}")
set(OTB3P_INSTALL_LIBRARY_DIR "${OTBSiftFast_INSTALL_LIBRARY_DIR}")
set(OTB3P_INSTALL_ARCHIVE_DIR "${OTBSiftFast_INSTALL_ARCHIVE_DIR}")
#set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}")
include(CheckCXXSourceRuns)
if( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
# TRY COMPILE libsiftfast.cpp (depend of gcc version)
set(IS_SIFTFAST_COMPILE 0)
try_compile(IS_SIFTFAST_COMPILE
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/test_try_compile_libsiftfast.cpp
OUTPUT_VARIABLE OUTPUT)
if(IS_SIFTFAST_COMPILE)
message(STATUS "Try to compile libsiftfast.cpp -- yes.")
else()
message(STATUS "Try to compile libsiftfast.cpp -- no. OUTPUT_VARIABLE has ${OUTPUT}")
try_compile(IS_SIFTFAST_COMPILE2
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/test_try_compile_libsiftfast.cpp
COMPILE_DEFINITIONS -DOTB_DISABLE_FAST_FUNCTIONS
OUTPUT_VARIABLE OUTPUT)
if(IS_SIFTFAST_COMPILE2)
message(STATUS "Try to compile libsiftfast.cpp with disabling fast functions (add CFLAGS -DOTB_DISABLE_FAST_FUNCTIONS) -- yes.")
else()
message(STATUS "Try to compile libsiftfast.cpp with disabling fast functions (add CFLAGS -DOTB_DISABLE_FAST_FUNCTIONS) -- no.")
message(FATAL_ERROR "Impossible to compile libsiftfast. Contact OTB development team")
endif()
set(OTB_DISABLE_FAST_FUNCTIONS_VALUE 1)
endif()
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -g")
add_definitions(" -Wall -fPIC ")
# check for x86-64 system
check_cxx_source_runs("
int main()
{
int a = 0;
int*pa = &a;
asm(\".intel_syntax\\\\n\"
\"mov %%rax, %0\\\\n\"
\"mov %%eax, [%%rax]\\\\n\"
\".att_syntax\\\\n\"
: : \"r\"(pa) : \"%rax\");
return 0;
}"
IS_X86_64)
if( IS_X86_64 )
add_definitions("-D__x86_64__")
endif()
else()
set(IS_X86_64 0)
endif()
if(OTB_DISABLE_FAST_FUNCTIONS_VALUE)
add_definitions(-DOTB_DISABLE_FAST_FUNCTIONS)
endif()
include(CheckIncludeFile)
include(CheckLibraryExists)
include(CheckCXXSourceRuns)
include(CheckCXXCompilerFlag)
# if( UNIX OR CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
# set(STDC_LIBRARY stdc++)
# else()
# set(STDC_LIBRARY)
# endif()
# check for SSE extensions
if( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
set(SSE_FLAGS)
set(CMAKE_REQUIRED_FLAGS "-msse2")
check_cxx_source_runs("
#include <emmintrin.h>
int main()
{
__m128d a, b;
double vals[2] = {0};
a = _mm_loadu_pd(vals);
b = _mm_add_pd(a,a);
_mm_storeu_pd(vals,b);
return 0;
}"
HAS_SSE2_EXTENSIONS)
set(CMAKE_REQUIRED_FLAGS "-msse")
check_cxx_source_runs("
#include <xmmintrin.h>
int main()
{
__m128 a, b;
float vals[4] = {0};
a = _mm_loadu_ps(vals);
b = a;
b = _mm_add_ps(a,b);
_mm_storeu_ps(vals,b);
return 0;
}"
HAS_SSE_EXTENSIONS)
set(CMAKE_REQUIRED_FLAGS)
if(HAS_SSE2_EXTENSIONS)
message(STATUS "Using SSE2 extensions")
set(SSE_FLAGS "-msse2 -mfpmath=sse")
elseif(HAS_SSE_EXTENSIONS)
message(STATUS "Using SSE extensions")
set(SSE_FLAGS "-msse -mfpmath=sse")
endif()
add_definitions(${SSE_FLAGS})
elseif(MSVC)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
message(STATUS "Not using SSE2 extensions on x64")
else()
check_cxx_source_runs("
#include <emmintrin.h>
int main()
{
__m128d a, b;
double vals[2] = {0};
a = _mm_loadu_pd(vals);
b = _mm_add_pd(a,a);
_mm_storeu_pd(vals,b);
return 0;
}"
HAS_SSE2_EXTENSIONS)
if( HAS_SSE2_EXTENSIONS )
message(STATUS "Using SSE2 extensions")
add_definitions( "/arch:SSE2 /fp:fast -D__SSE__ -D__SSE2__" )
endif()
endif()
endif()
#set(Boost_ADDITIONAL_VERSIONS "1.40" "1.39" "1.38" "1.37.0" "1.37" "1.35.0" "1.34.1" "1.34.0" "1.34" "1.33.1" "1.33.0" "1.33")
#if( NOT $ENV{BOOST_INCLUDEDIR} STREQUAL "" )
# set(Boost_INCLUDE_DIR $ENV{BOOST_INCLUDEDIR})
#endif()
#if( NOT $ENV{BOOST_LIBRARYDIR} STREQUAL "" )
# set(Boost_LIBRARY_DIRS $ENV{BOOST_LIBRARYDIR})
#endif()
#find_package(Boost COMPONENTS python)
#if( Boost_FOUND )
# message(STATUS "found boost version: ${Boost_VERSION}")
#else()
# message(STATUS "Could not find boost libraries!")
#endif()
add_library(otbsiftfast libsiftfast.cpp)
if( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
# target_link_libraries(otbsiftfast m stdc++)
target_link_libraries(otbsiftfast m)
endif()
#set_target_properties(otbsiftfast PROPERTIES OUTPUT_NAME siftfast CLEAN_DIRECT_OUTPUT 1)
# compile without depending on libsiftfast
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
#set_target_properties(siftfast PROPERTIES COMPILE_FLAGS "-DDVPROFILE")
#target_link_libraries(siftfast libsiftfast)
# check for OpenMP
find_package(OpenMP)
if(OPENMP_FOUND)
message(STATUS "Enabling OpenMP support")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
else()
message(STATUS "Disabling OpenMP support")
endif()
#Install TARGET & FILES for otb-lib
if(OTB_LIBRARY_PROPERTIES)
set_target_properties(otbsiftfast PROPERTIES ${OTB_LIBRARY_PROPERTIES})
endif()
install(TARGETS otbsiftfast
EXPORT ${OTB3P_INSTALL_EXPORT_NAME}
RUNTIME DESTINATION ${OTB3P_INSTALL_RUNTIME_DIR} COMPONENT RuntimeLibraries
LIBRARY DESTINATION ${OTB3P_INSTALL_LIBRARY_DIR} COMPONENT RuntimeLibraries
ARCHIVE DESTINATION ${OTB3P_INSTALL_ARCHIVE_DIR} COMPONENT Development
)
install(FILES siftfast.h
DESTINATION ${OTB3P_INSTALL_INCLUDE_DIR}/otbsiftfast
COMPONENT Development
)
install(FILES otb_siftfast.h
DESTINATION ${OTB3P_INSTALL_INCLUDE_DIR}
COMPONENT Development
)
otb_module_target( otbsiftfast NO_INSTALL )