Attention une mise à jour du service Gitlab va être effectuée le mardi 14 décembre entre 13h30 et 14h00. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes.

CMakeLists.txt 12 KB
Newer Older
1
cmake_minimum_required (VERSION 3.2)
2
project (alta CXX)
3

4 5 6 7
#############################
#      Preconfiguration     #
#############################

8 9 10
# Set Python version number
set(Python_ADDITIONAL_VERSIONS 2.7)

11 12 13 14 15 16 17 18 19
# Require C++11 options
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


#############################
#        Dependencies       #
#############################

20
# Find required packages
21
find_package(Eigen3)
22
find_package(OpenMP)
23 24
find_package(PythonLibs)
find_package(Boost COMPONENTS python)
25 26 27

add_definitions(-DALTA_PLUGIN_DIRECTORY="/usr/lib/alta_plugins")

28
# Add core and library include files
29
include_directories("external/build" "sources" ${EIGEN3_INCLUDE_DIR})
30
include_directories("external" "external/Catch/include" "external/quadprog++")
31

32
# Look for header only dependencies
33 34 35
find_file(EIGEN_FOUND "Eigen/Core"      HINTS ${EIGEN3_INCLUDE_DIR})
find_file(CATCH_FOUND "catch.hpp"       HINTS external/Catch/include)
find_file(FLANN_FOUND "flann/flann.hpp")
36 37 38 39 40

# Check if Eigen is found
if(NOT EIGEN_FOUND)
    message(FATAL_ERROR "Unable to find Eigen header")
endif()
41

42 43 44 45 46 47 48
# Update compilation option to include OpenMP if present
if(OPENMP_FOUND)
    set (CMAKE_CXX_FLAGS ${OpenMP_CXX_FLAGS})
endif(OPENMP_FOUND)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

49

50 51 52 53 54 55
#############################
#      Helper functions     #
#############################

function(alta_add_plugin name sources)
	add_library(${name} SHARED sources/plugins/${sources})
56
        target_link_libraries(${name} core)
57 58 59 60
endfunction(alta_add_plugin)

function(alta_add_soft name sources)
	add_executable(${name} sources/softs/${sources})
61
        target_link_libraries(${name} core)
62 63
endfunction(alta_add_soft)

64
function(alta_test_unit name sources)
65 66
        add_executable(${name} sources/tests/${sources})
        target_link_libraries(${name} core)
67 68
        add_test(NAME ${name} COMMAND ${CMAKE_BINARY_DIR}/tests/${name} WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
        set_tests_properties(${name} PROPERTIES ENVIRONMENT "TEST_DATA_DIRECTORY=${CMAKE_SOURCE_DIR}/sources/tests;ALTA_PLUGIN_PATH=${CMAKE_BINARY_DIR}/plugins")
69 70 71 72 73
endfunction(alta_test_unit)

function(alta_test_soft name)
        add_test(NAME ${name} COMMAND ${CMAKE_BINARY_DIR}/softs/${name} --help)
endfunction(alta_test_soft)
74

75
function(alta_download_merl name)
76
    find_file(${name}_FOUND "${name}.binary" PATHS "${CMAKE_BINARY_DIR}/tests/")
77 78 79 80 81
    if(NOT ${name}_FOUND)
        message("Dowloading ${name} from MERL database:")
        file(DOWNLOAD
             "http://people.csail.mit.edu/wojciech/BRDFDatabase/brdfs/${name}.binary"
             "${CMAKE_BINARY_DIR}/tests/${name}.binary" SHOW_PROGRESS)
82
         set(${name}_FOUND TRUE)
83
    endif()
84 85 86
    if(NOT ${name}_FOUND)
	    message("Error checking for ${name}.binary but not found")
    endif()
87 88
endfunction(alta_download_merl)

89 90 91 92 93 94

#############################
#         ALTA core         #
#############################

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
95

96 97 98 99
add_library(core STATIC
            sources/core/args.h
            sources/core/common.h
            sources/core/common.cpp
100 101 102 103 104 105
            sources/core/metrics.h
            sources/core/metrics.cpp
            sources/core/params.h
            sources/core/params.cpp
            sources/core/data.h
            sources/core/data.cpp
106
            sources/core/data_storage.h
107 108 109 110 111 112 113 114 115
            sources/core/data_storage.cpp
            sources/core/vertical_segment.h
            sources/core/vertical_segment.cpp
            sources/core/function.h
            sources/core/function.cpp
            sources/core/rational_function.h
            sources/core/rational_function.cpp
            sources/core/plugins_manager.h
            sources/core/plugins_manager.cpp)
116

117 118 119 120 121

add_library(quadprog STATIC
            external/quadprog++/QuadProg++.hh
            external/quadprog++/QuadProg++.cc)

122 123
target_link_libraries(core ${CMAKE_DL_LIBS})

124 125 126 127 128

#############################
#         Plugins           #
#############################

129
#    set(CMAKE_SHARED_LIBRARY_PREFIX "")
130 131 132
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins)

# Data
133 134 135 136
alta_add_plugin(data_astm       data_io/astm.cpp)
alta_add_plugin(data_merl       data_io/merl.cpp)
alta_add_plugin(data_utia       data_io/utia.cpp)
alta_add_plugin(data_brdf_slice data_io/slice.cpp)
137

138
alta_add_plugin(data_grid       data_interpolants/grid.cpp)
139 140 141 142
if(FLANN_FOUND)
    alta_add_plugin(data_rbf    data_interpolants/rbf.cpp)
endif()
#alta_add_plugin(data_matlab data_interpolants/matlab.cpp)
143 144

# Functions
145 146 147
alta_add_plugin(rational_function_legendre		rational_function_legendre/rational_function.cpp)
alta_add_plugin(rational_function_chebychev		rational_function_chebychev/rational_function.cpp)
alta_add_plugin(rational_function_cosine 		rational_function_cosine/rational_function.cpp)
148 149 150 151 152 153 154 155 156
alta_add_plugin(nonlinear_function_abc                  nonlinear_function_abc/function.cpp)
alta_add_plugin(nonlinear_function_beckmann             nonlinear_function_beckmann/function.cpp)
alta_add_plugin(nonlinear_function_blinn                nonlinear_function_blinn/function.cpp)
alta_add_plugin(nonlinear_function_diffuse              nonlinear_function_diffuse/function.cpp)
alta_add_plugin(nonlinear_function_lafortune            nonlinear_function_lafortune/function.cpp)
alta_add_plugin(nonlinear_function_sgd                  nonlinear_function_sgd/function.cpp)
alta_add_plugin(nonlinear_function_spherical_gaussian   nonlinear_function_spherical_gaussian/function.cpp)
alta_add_plugin(nonlinear_function_ward                 nonlinear_function_ward/function.cpp)

157 158 159 160
alta_add_plugin(nonlinear_function_retrobeckmann        nonlinear_function_retrobeckmann/function.cpp)
alta_add_plugin(nonlinear_function_retroblinn		nonlinear_function_retroblinn/function.cpp)
alta_add_plugin(nonlinear_function_retroyoo             nonlinear_function_retroyoo/function.cpp)
alta_add_plugin(nonlinear_fresnel_retroschlick		nonlinear_fresnel_retroschlick/function.cpp)
161 162

alta_add_plugin(nonlinear_fresnel_schlick               nonlinear_fresnel_schlick/function.cpp)
163
alta_add_plugin(nonlinear_fresnel_normalized_schlick    nonlinear_fresnel_normalized_schlick/function.cpp)
164 165 166 167

alta_add_plugin(nonlinear_shadowing_schlick             nonlinear_shadowing_schlick/function.cpp)
alta_add_plugin(nonlinear_shadowing_smith               nonlinear_shadowing_smith/function.cpp)
alta_add_plugin(nonlinear_shadowing_walter_smith        nonlinear_shadowing_walter_smith/function.cpp)
168

169
# Fitters
170 171 172 173
alta_add_plugin(rational_fitter_eigen 			rational_fitter_eigen/rational_fitter.cpp)
alta_add_plugin(rational_fitter_leastsquare		rational_fitter_leastsquare/rational_fitter.cpp)
alta_add_plugin(rational_fitter_quadprog		rational_fitter_quadprog/rational_fitter.cpp)
alta_add_plugin(rational_fitter_parallel		rational_fitter_parallel/rational_fitter.cpp)
174
alta_add_plugin(nonlinear_fitter_eigen                  nonlinear_fitter_eigen/fitter.cpp)
175 176
target_link_libraries(rational_fitter_quadprog quadprog)
target_link_libraries(rational_fitter_parallel quadprog)
177 178 179

# TODO: Add check before compiling CERES, NLOPT and IPOPT
alta_add_plugin(nonlinear_fitter_ceres                  nonlinear_fitter_ceres/fitter.cpp)
180
target_link_libraries(nonlinear_fitter_ceres ceres)
181
alta_add_plugin(nonlinear_fitter_nlopt                  nonlinear_fitter_nlopt/fitter.cpp)
182
target_link_libraries(nonlinear_fitter_nlopt nlopt)
183
#alta_add_plugin(nonlinear_fitter_ipopt                  nonlinear_fitter_ipopt/fitter.cpp)
184

185 186 187 188 189 190
# Python bindings
if(PYTHONLIBS_FOUND AND Boost_FOUND)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/python)
    include_directories(${PYTHON_INCLUDE_DIRS} ${Boost_INCLUDE_DIR})
    add_library(alta SHARED sources/python/alta.cpp)
    target_link_libraries(alta core ${PYTHON_LIBRARIES} ${Boost_LIBRARIES})
191
    set_target_properties(alta PROPERTIES PREFIX "")
192 193 194 195 196
    if(APPLE)
        set_target_properties(alta PROPERTIES SUFFIX ".so")
    endif()
endif()

197

198 199 200 201 202 203
#############################
#          Softs            #
#############################

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/softs)

204 205 206 207 208 209 210 211 212
alta_add_soft(brdf2brdf    brdf2brdf/main.cpp)
alta_add_soft(brdf2data    brdf2data/main.cpp)
alta_add_soft(brdf2gnuplot brdf2gnuplot/main.cpp)
#alta_add_soft(brdf2moments brdf2moments/main.cpp)
alta_add_soft(brdf2stats   fit2stat/fit2stat.cpp)
alta_add_soft(data2data    data2data/main.cpp)
alta_add_soft(data2brdf    data2brdf/main.cpp)
alta_add_soft(data2stats   data2stats/data2stats.cpp)
alta_add_soft(data2moments data2moments/main.cpp)
213

214

215 216 217 218
#############################
#          Tests            #
#############################

219
enable_testing()
220

221 222 223 224 225 226 227
# Test all softs with `--help` option
alta_test_soft(brdf2data)
alta_test_soft(data2data)
alta_test_soft(data2stats)
alta_test_soft(data2brdf)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
228
include_directories("sources/tests")
229

230 231 232 233 234 235 236 237 238
# Unit test
alta_test_unit(test_data_io  core/data-io.cpp)
alta_test_unit(half-test-1   core/half-test-1.cpp)
alta_test_unit(half-test-2   core/half-test-2.cpp)
alta_test_unit(half-test-3   core/half-test-3.cpp)
alta_test_unit(half-test-4   core/half-test-4.cpp)
alta_test_unit(nonlinear-fit core/nonlinear-fit.cpp)
alta_test_unit(params-test-1 core/params-test-1.cpp)
alta_test_unit(params-test-2 core/params-test-2.cpp)
239 240

if(CPPQUICKCHECK_FOUND)
241
    alta_test_unit(params-qc-1 core/params-qc-1.cpp)
242 243
endif()

244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
# Integration test for rational function fitting
foreach(fitter IN ITEMS eigen leastsquare quadprog parallel)
    add_test(NAME "data2dbrdf_kirby_${fitter}"
             COMMAND "data2brdf" "--input"   "${CMAKE_SOURCE_DIR}/sources/tests/Kirby2.dat"
                                 "--output"  "Kirby2.func"
                                 "--fitter"  "rational_fitter_${fitter}"
             WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests")

    set_tests_properties("data2dbrdf_kirby_${fitter}"
                         PROPERTIES ENVIRONMENT "ALTA_PLUGIN_PATH=${CMAKE_BINARY_DIR}/plugins")
endforeach()

add_test(NAME "brdf2data_kirby"
         COMMAND "brdf2data" "--input"     "Kirby2.func"
                             "--output"    "Kirby2.dat"
                             "--data-file" "${CMAKE_SOURCE_DIR}/sources/tests/Kirby2.dat"
         WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests")

add_test(NAME "data2stats_kirby"
         COMMAND "data2stats" "--input"     "Kirby2.dat"
                              "--ref"       "${CMAKE_SOURCE_DIR}/sources/tests/Kirby2.dat"
         WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests")



269 270
# Integration tests using MERL data
alta_download_merl("gold-metallic-paint")
271 272
if(gold-metallic-paint_FOUND)
    add_test(NAME "data2data_gold"
273 274
             COMMAND "data2data" "--input"   "gold-metallic-paint.binary"
                                 "--output"  "gold-metallic-paint.alta"
275 276
                                 "--in-data" "data_merl"
             WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
277 278 279 280 281 282 283

     add_test(NAME "data2data_gold_slice"
              COMMAND "data2data" "--input"    "gold-metallic-paint.binary"
                                  "--output"   "gold-metallic-paint.exr"
                                  "--in-data"  "data_merl"
                                  "--out-data" "data_brdf_slice"
              WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
284 285 286 287 288 289 290 291 292 293 294 295 296 297
      
      foreach(fitter IN ITEMS eigen ceres nlopt)
	      add_test(NAME "data2dbrdf_gold_${fitter}"
		      COMMAND "data2brdf" "--input"   "gold-metallic-paint.exr"
			                  "--output"  "gold-metallic-paint-${fitter}.func"
			                  "--data"    "data_brdf_slice"
			                  "--fitter"  "nonlinear_fitter_${fitter}"
			                  "--func"    "[nonlinear_function_diffuse, nonlinear_function_blinn]"
		      WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests")

	      set_tests_properties("data2dbrdf_gold_${fitter}"
		      PROPERTIES ENVIRONMENT "ALTA_PLUGIN_PATH=${CMAKE_BINARY_DIR}/plugins")
      endforeach()
     
298 299
    set_tests_properties("data2data_gold" "data2data_gold_slice"
                         PROPERTIES ENVIRONMENT "ALTA_PLUGIN_PATH=${CMAKE_BINARY_DIR}/plugins")
300
endif()
301

302
if(gold-metallic-paint_FOUND AND CATCH_FOUND)
303
    alta_test_unit(conversion-catch-1 core/conversion-catch-1.cpp )
304
endif()