#                                               -*- cmake -*-
#
#  CMakeLists.txt
#
#  Copyright 2005-2017 Airbus-EDF-IMACS-Phimeca
#
#  This library is free software: you can redistribute it and/or modify
#  it under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This library is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  along with this library.  If not, see <http://www.gnu.org/licenses/>.
#
#

set (NEW_PATH "${INSTALL_DESTDIR}${EXAMPLE_PATH}${PATH_SEP}$ENV{PATH}")

set (ADAPT_CHECK_TESTS_EXPONENT)
set (REPLACE_EOL " | cat ")
if (WIN32)
  # replace dos eols
  set (REPLACE_EOL " | tr -d '\\\\015' ")

  if (MINGW AND CMAKE_SIZEOF_VOID_P EQUAL 4)
    add_library (CRT_fp8 STATIC EXCLUDE_FROM_ALL CRT_fp8.c)
  endif ()
endif ()

set (CHECK_ENVIRONMENT "OPENTURNS_CONFIG_PATH=${CMAKE_BINARY_DIR}/lib/etc")

# This macro compiles on the fly and run the corresponding pre-installation test
# It can have two optional arguments PRE and POST followed by some shell command to be run
# before or after the test if needed
# PRE and POST options cn be repeated many times: the arguments will be run one after the other
# in the order of appearence. If one fails, the whole command fails.
set (CHECK_TO_BE_RUN)
macro (ot_check_test TESTNAME)
  set (TESTNAME_TGT t_${TESTNAME})
  set (TESTNAME_SRC ${TESTNAME_TGT}.cxx)
  set (TESTNAME_SRCS ${TESTNAME_SRC})
  add_executable (${TESTNAME_TGT} EXCLUDE_FROM_ALL ${TESTNAME_SRCS})
  add_dependencies(tests ${TESTNAME_TGT}) 
  target_link_libraries (${TESTNAME_TGT} OT)
  if (MINGW AND CMAKE_SIZEOF_VOID_P EQUAL 4)
    target_link_libraries (${TESTNAME_TGT} CRT_fp8)
  endif ()
  set_target_properties (${TESTNAME_TGT} PROPERTIES
                                          INSTALL_RPATH "${CMAKE_BINARY_DIR}/lib/src;${CMAKE_INSTALL_RPATH}")
  set (TESTNAME_LOC ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME_TGT}${CMAKE_EXECUTABLE_SUFFIX})

  set (_CMD)
  set (_PRE)
  set (_POST)
  set (_PARAMS)
  set (_IGNOREOUT OFF)
  foreach (_ARG ${ARGN})
    string (TOUPPER ${_ARG} ARG)
    if (${ARG} MATCHES PRE)
      set (_CMD PRE)
    elseif (${ARG} MATCHES POST)
      set (_CMD POST)
    elseif (${ARG} MATCHES PARAMS)
      set (_CMD PARAMS)
    elseif (${ARG} MATCHES IGNOREOUT)
      set (_IGNOREOUT ON)
    else (${ARG} MATCHES PRE)
      if (${_CMD} MATCHES PRE)
        set (_PRE "${_PRE} ${_ARG} && ")
      elseif (${_CMD} MATCHES POST)
        set (_POST "${_POST} && ${_ARG}")
      elseif (${_CMD} MATCHES PARAMS)
        set (_PARAMS "${_PARAMS} ${_ARG}")
      endif  (${_CMD} MATCHES PRE)
      set (_CMD)
    endif (${ARG} MATCHES PRE)
  endforeach (_ARG)

  if (_IGNOREOUT)
    set (COMMAND "(${TESTNAME_LOC} ${_PARAMS} > /dev/null)")
  else (_IGNOREOUT)
    set (TESTNAME_OUT ${TESTNAME_TGT}.expout)
    set (OUTFILE_LOC ${CMAKE_CURRENT_SOURCE_DIR}/${TESTNAME_OUT})
    set (COMMAND "(${TESTNAME_LOC} ${_PARAMS} ${REPLACE_EOL} > ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME_TGT}.out) && diff -u ${OUTFILE_LOC} ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME_TGT}.out")
  endif (_IGNOREOUT)

  if (_PRE OR _POST)
    set (COMMAND "${_PRE}${COMMAND}${_POST}")
  endif (_PRE OR _POST)

  add_test (cppcheck_${TESTNAME} "sh" "-c" "${COMMAND}")
  set_tests_properties (cppcheck_${TESTNAME} PROPERTIES ENVIRONMENT "${CHECK_ENVIRONMENT}")
  list (APPEND CHECK_TO_BE_RUN ${TESTNAME_TGT})
  install (FILES ${TESTNAME_SRC}
            DESTINATION ${EXAMPLE_PATH}
         )

endmacro (ot_check_test)


include_directories (${INTERNAL_INCLUDE_DIRS})

## Pre-installation tests

# Common
ot_check_test (Object_std)
ot_check_test (OStream_std)
ot_check_test (PersistentObject_std)
ot_check_test (Pointer_std)
ot_check_test (Pointer_cast)
ot_check_test (Exception_std)
ot_check_test (Log_std)
ot_check_test (IdFactory_std IGNOREOUT)
ot_check_test (ComparisonOperator_std)
if (LIBXML2_FOUND)
ot_check_test (Study_saveload )
endif ()
ot_check_test (ResourceMap_std IGNOREOUT)
ot_check_test (Catalog_std IGNOREOUT)
ot_check_test (AtomicFunctions_std IGNOREOUT)

# Type
ot_check_test (Collection_std)
ot_check_test (Indices_std)
ot_check_test (Description_std)
ot_check_test (Point_std)
ot_check_test (Point_description)
ot_check_test (Matrix_std)
ot_check_test (IdentityMatrix_std)
ot_check_test (Tensor_std)
ot_check_test (ComplexTensor_std)
ot_check_test (SymmetricTensor_std)
ot_check_test (SquareMatrix_std)
ot_check_test (TriangularMatrix_std)
ot_check_test (SymmetricMatrix_std)
ot_check_test (Matrix_solve)
ot_check_test (Matrix_decomposition)
ot_check_test (SquareMatrix_lapack)
ot_check_test (SymmetricMatrix_lapack)
ot_check_test (Cache_std)
ot_check_test (ComplexMatrix_std)
ot_check_test (SquareComplexMatrix_std)
ot_check_test (HermitianMatrix_std)
ot_check_test (TriangularComplexMatrix_std)

# Func
ot_check_test (LinearEvaluation_std)
ot_check_test (ConstantGradient_std)
ot_check_test (AggregatedEvaluation_std)
ot_check_test (PiecewiseLinearEvaluation_std)
ot_check_test (PiecewiseHermiteEvaluation_std)
ot_check_test (P1LagrangeEvaluation_std)
if (OPENTURNS_HAVE_MUPARSER)
ot_check_test (SymbolicEvaluation_std)
ot_check_test (SymbolicGradient_std)
ot_check_test (SymbolicHessian_std)
endif ()
ot_check_test (LinearFunction_std)
ot_check_test (LinearCombinationEvaluation_std)
ot_check_test (LinearCombinationGradient_std)
ot_check_test (LinearCombinationHessian_std)
ot_check_test (QuadraticEvaluation_std)
ot_check_test (LinearGradient_std)
ot_check_test (ConstantHessian_std)
ot_check_test (MethodBoundEvaluation_std)
ot_check_test (SymbolicFunction_std)
ot_check_test (IndicatorFunction_std)
ot_check_test (AggregatedFunction_std)
ot_check_test (DualLinearCombinationFunction_std)
ot_check_test (LinearCombinationFunction_std)
ot_check_test (Function_operations)
ot_check_test (ParametricFunction_std)
ot_check_test (DatabaseFunction_std)
ot_check_test (Function_history)

if (R_base_FOUND)
ot_check_test (Function_draw)
endif ()
ot_check_test (MonomialFunction_std)
ot_check_test (MonomialFunctionFactory_std)
ot_check_test (TensorizedUniVariateFunctionFactory_std)

ot_check_test (UniVariatePolynomial_std)
ot_check_test (Basis_std)
ot_check_test (BasisSequence_std)
ot_check_test (LARS_std)
ot_check_test (FieldFunction_std)
ot_check_test (FieldToPointFunction_std)
ot_check_test (PointToFieldFunction_std)
ot_check_test (ValueFunction_std)
ot_check_test (VertexValueFunction_std)
ot_check_test (VertexFunction_std)
ot_check_test (PointToPointEvaluation_std)
ot_check_test (PointToPointConnection_std)
ot_check_test (PointToFieldConnection_std)
ot_check_test (FieldToPointConnection_std)
ot_check_test (FieldToFieldConnection_std)
ot_check_test (BoxCoxEvaluation_std)
ot_check_test (BoxCoxTransform_std)
ot_check_test (InverseBoxCoxEvaluation_std)
ot_check_test (InverseBoxCoxTransform_std)
ot_check_test (TrendEvaluation_std)
ot_check_test (TrendTransform_std)
ot_check_test (InverseTrendEvaluation_std)
ot_check_test (InverseTrendTransform_std)
ot_check_test (ExpertMixture_std)
ot_check_test (BasisFactory_std)

# Optim
ot_check_test (AbdoRackwitz_std)
ot_check_test (Cobyla_std)
ot_check_test (SQP_std)
ot_check_test (TNC_std)
ot_check_test (NearestPointChecker_std)
if (NLOPT_FOUND)
ot_check_test (NLopt_std)
endif ()
ot_check_test (MultiStart_std)

# Solver
ot_check_test (Bisection_std)
ot_check_test (Brent_std)
ot_check_test (Secant_std)
ot_check_test (RungeKutta_std)

# Stat
ot_check_test (Sample_std)
ot_check_test (Sample_split)
ot_check_test (Sample_large)
ot_check_test (Sample_computation)
ot_check_test (Sample_operators)
ot_check_test (HistoryStrategy_std)
ot_check_test (CovarianceMatrixLapack_std)
ot_check_test (CorrelationMatrix_std)
ot_check_test (TestResult_std)
if (R_rot_FOUND)
ot_check_test (LinearModelFactory_std)
ot_check_test (LinearModel_std)
endif ()
ot_check_test (Field_draw)
ot_check_test (ProcessSample_std)
ot_check_test (RandomGenerator_std)
ot_check_test (SobolSequence_std)
ot_check_test (FaureSequence_std)
ot_check_test (HaltonSequence_std)
ot_check_test (HaselgroveSequence_std)
ot_check_test (ReverseHaltonSequence_std)
ot_check_test (CorrelationAnalysis_std)
ot_check_test (TimeSeries_std)
ot_check_test (ExponentialCauchy_std)
ot_check_test (FilteringWindows_std)
ot_check_test (WelchFactory_std)
ot_check_test (ExponentialModel_std)
ot_check_test (CovarianceModel_std)
ot_check_test (DiracCovarianceModel_std)
ot_check_test (ExponentiallyDampedCosineModel_std)
ot_check_test (CauchyModel_std)
ot_check_test (SecondOrderModel_std)
ot_check_test (UserDefinedSpectralModel_std)
ot_check_test (UserDefinedCovarianceModel_std)
ot_check_test (UserDefinedStationaryCovarianceModel_std)
ot_check_test (StationaryCovarianceModelFactory_std)
ot_check_test (NonStationaryCovarianceModelFactory_std)
if (HMAT_FOUND)
ot_check_test (HMatrix_LDLt)
ot_check_test (HMatrix_LLt)
ot_check_test (HMatrix_LU)
ot_check_test (HMatrix_block_LLt)
ot_check_test (HMatrix_block_LU)
ot_check_test (DiracCovarianceModel_hmat)
endif ()

# Diff
ot_check_test (FiniteDifferenceStep_std)

# Geom
ot_check_test (Domain_std)
ot_check_test (Interval_std)
ot_check_test (IntervalMesher_std)
ot_check_test (LevelSet_std)
ot_check_test (LevelSetMesher_std)
ot_check_test (Mesh_std)
if (R_base_FOUND)
ot_check_test (Mesh_draw)
endif ()
ot_check_test (RegularGrid_std)

# Graph
if (R_base_FOUND)
ot_check_test (BarPlot_std)
ot_check_test (Cloud_std)
ot_check_test (Contour_std)
ot_check_test (Curve_std)
ot_check_test (Drawable_std)
ot_check_test (Graph_mix)
ot_check_test (Graph_export)
ot_check_test (Pairs_std)
ot_check_test (Pie_std)
ot_check_test (Polygon_std)
ot_check_test (PolygonArray_std)
ot_check_test (Staircase_std)
ot_check_test (Text_std)
endif ()

# Algo
ot_check_test (PenalizedLeastSquaresAlgorithm_std)
ot_check_test (CorrectedLeaveOneOut_std)
ot_check_test (KDTree_std)
ot_check_test (KFold_std)
ot_check_test (LeastSquaresMetaModelSelectionFactory_std)
ot_check_test (KissFFT_std)
ot_check_test (GaussKronrod_std)
ot_check_test (GaussLegendre_std)
ot_check_test (IteratedQuadrature_std)
ot_check_test (KarhunenLoeveP1Algorithm_std)
ot_check_test (LeastSquaresMethod_std)
ot_check_test (LeastSquaresMethod_weighted)
ot_check_test (KarhunenLoeveSVDAlgorithm_std)
ot_check_test (KarhunenLoeveLifting_std)
ot_check_test (KarhunenLoeveProjection_std)

# Analytical
ot_check_test (Analytical_std)
ot_check_test (AnalyticalResult_std)
ot_check_test (FORM_std)
ot_check_test (FORM_AbdoRackwitz)
ot_check_test (FORM_SQP)
ot_check_test (FORM_sensitivity)
if (R_base_FOUND)
ot_check_test (FORM_draw)
endif ()
ot_check_test (SORM_std)
ot_check_test (StrongMaximumTest_std)
ot_check_test (StrongMaximumTest_tabulatedValues)
ot_check_test (StrongMaximumTest_other)

# Distribution
ot_check_test (Arcsine_std)
ot_check_test (ArcsineFactory_std)
ot_check_test (Bernoulli_std)
ot_check_test (BernoulliFactory_std)
ot_check_test (BernsteinCopulaFactory_std)
ot_check_test (Beta_std)
ot_check_test (BetaFactory_std)
ot_check_test (Binomial_std)
ot_check_test (BinomialFactory_std)
ot_check_test (Burr_std)
ot_check_test (BurrFactory_std)
ot_check_test (Chi_std)
ot_check_test (ChiFactory_std)
ot_check_test (ChiSquare_std)
ot_check_test (ChiSquareFactory_std)
ot_check_test (ComposedCopula_std)
ot_check_test (ComposedDistribution_std)
ot_check_test (ComposedDistribution_large)
ot_check_test (CompositeDistribution_std)
ot_check_test (ConditionalDistribution_std)
ot_check_test (CumulativeDistributionNetwork_std)
ot_check_test (Dirac_std)
ot_check_test (DiracFactory_std)
ot_check_test (Dirichlet_std)
ot_check_test (DirichletFactory_std)
ot_check_test (Epanechnikov_std)
ot_check_test (Exponential_std)
ot_check_test (ExponentialFactory_std)
ot_check_test (FisherSnedecor_std)
ot_check_test (FisherSnedecorFactory_std)
ot_check_test (Frechet_std)
ot_check_test (Gamma_std)
ot_check_test (GammaFactory_std)
ot_check_test (GeneralizedExtremeValue_std)
ot_check_test (GeneralizedPareto_std)
ot_check_test (GeneralizedParetoFactory_std)
ot_check_test (Geometric_std)
ot_check_test (GeometricFactory_std)
ot_check_test (Gumbel_std)
ot_check_test (GumbelFactory_std)
ot_check_test (Histogram_std)
ot_check_test (HistogramFactory_std)
ot_check_test (InverseChiSquare_std)
ot_check_test (InverseGamma_std)
ot_check_test (InverseNormal_std)
ot_check_test (InverseNormalFactory_std)
ot_check_test (InverseWishart_std)
ot_check_test (KPermutationsDistribution_std)
ot_check_test (KernelMixture_std)
ot_check_test (KernelSmoothing_std)
ot_check_test (Laplace_std)
ot_check_test (LaplaceFactory_std)
ot_check_test (Logistic_std)
ot_check_test (LogisticFactory_std)
ot_check_test (LogNormal_std)
ot_check_test (LogNormalFactory_std)
ot_check_test (LogUniform_std)
ot_check_test (LogUniformFactory_std)
ot_check_test (OrderStatisticsMarginalChecker_std)
# ot_check_test (MarginalDistribution_std)
ot_check_test (MaximumEntropyOrderStatisticsDistribution_std)
ot_check_test (MaximumEntropyOrderStatisticsCopula_std)
ot_check_test (MaximumLikelihoodFactory_std)
ot_check_test (Mixture_std)
ot_check_test (Multinomial_std)
ot_check_test (MultinomialFactory_std)
ot_check_test (NegativeBinomial_std)
ot_check_test (NegativeBinomialFactory_std)
ot_check_test (NonCentralChiSquare_std)
ot_check_test (NonCentralStudent_std)
ot_check_test (Normal_std)
ot_check_test (NormalFactory_std)
ot_check_test (Normal_large)
ot_check_test (Normal_wrongarg)
ot_check_test (NormalGamma_std)
ot_check_test (Poisson_std)
ot_check_test (PoissonFactory_std)
ot_check_test (PosteriorDistribution_std)
ot_check_test (ProductDistribution_std)
ot_check_test (RandomMixture_std)
ot_check_test (RandomMixture_grid3d)
ot_check_test (RandomMixture_grid2d)
ot_check_test (RandomMixture_grid1d)
ot_check_test (SphereUnitNorm_std)
ot_check_test (Rayleigh_std)
ot_check_test (RayleighFactory_std)
ot_check_test (Rice_std)
ot_check_test (RiceFactory_std)
ot_check_test (SklarCopula_std)
ot_check_test (Skellam_std)
ot_check_test (SkellamFactory_std)
ot_check_test (Student_std)
ot_check_test (StudentFactory_std)
ot_check_test (Trapezoidal_std)
ot_check_test (TrapezoidalFactory_std)
ot_check_test (Triangular_std)
ot_check_test (TriangularFactory_std)
ot_check_test (TruncatedDistribution_std)
ot_check_test (TruncatedNormal_std)
ot_check_test (TruncatedNormalFactory_std)
ot_check_test (Uniform_std)
ot_check_test (UniformFactory_std)
ot_check_test (UserDefined_std)
ot_check_test (UserDefinedFactory_std)
ot_check_test (VonMises_std)
ot_check_test (Weibull_std)
ot_check_test (WeibullFactory_std)
ot_check_test (Wishart_std)
ot_check_test (ZipfMandelbrot_std)
ot_check_test (IndependentCopula_std)
ot_check_test (MeixnerDistribution_std)
ot_check_test (MeixnerDistributionFactory_std)
ot_check_test (MinCopula_std)
ot_check_test (NormalCopula_std)
ot_check_test (NormalCopulaFactory_std)
ot_check_test (FarlieGumbelMorgensternCopula_std)
ot_check_test (FarlieGumbelMorgensternCopulaFactory_std)
ot_check_test (AliMikhailHaqCopula_std)
ot_check_test (AliMikhailHaqCopulaFactory_std)
ot_check_test (FrankCopula_std)
ot_check_test (FrankCopulaFactory_std)
ot_check_test (ClaytonCopula_std)
ot_check_test (ClaytonCopulaFactory_std)
ot_check_test (GumbelCopula_std)
ot_check_test (GumbelCopulaFactory_std)
ot_check_test (OrdinalSumCopula_std)
ot_check_test (DistFunc_beta)
ot_check_test (DistFunc_gamma)
ot_check_test (DistFunc_kfactor)
ot_check_test (DistFunc_kolmogorov)
ot_check_test (DistFunc_noncentralchisquare)
ot_check_test (DistFunc_noncentralstudent)
ot_check_test (DistFunc_normal)
ot_check_test (DistFunc_poisson)
ot_check_test (DistFunc_student)

# Model
ot_check_test (DistributionFactory_std)
ot_check_test (Distribution_arithmetic)
if (R_base_FOUND)
ot_check_test (Distribution_draw)
endif ()
ot_check_test (Event_std)
ot_check_test (Event_domain)
ot_check_test (RandomVector_constant)
ot_check_test (RandomVector_conditional)
ot_check_test (RandomVector_distribution)
ot_check_test (RandomVector_composite)
ot_check_test (StandardEvent_std)

# Process
ot_check_test (AggregatedProcess_std)
ot_check_test (ARMACoefficients_std)
ot_check_test (ARMAState_std)
ot_check_test (ARMA_std)
ot_check_test (CompositeProcess_std )
ot_check_test (FunctionalBasisProcess_std )
ot_check_test (RandomWalk_std)
ot_check_test (SpectralGaussianProcess_std)
ot_check_test (GaussianProcess_std)
ot_check_test (WhiteNoise_std)
ot_check_test (WhittleFactory_std)
ot_check_test (ConditionedGaussianProcess_std)
ot_check_test (ARMALikelihoodFactory_std)
ot_check_test (KarhunenLoeveQuadratureAlgorithm_std)

# Transformation
ot_check_test (MarginalTransformationEvaluation_std)
ot_check_test (MarginalTransformationGradient_std)
ot_check_test (MarginalTransformationHessian_std)
ot_check_test (InverseNatafIndependentCopulaEvaluation_std)
ot_check_test (InverseNatafIndependentCopulaGradient_std)
ot_check_test (InverseNatafIndependentCopulaHessian_std)
ot_check_test (NatafIndependentCopulaEvaluation_std)
ot_check_test (NatafIndependentCopulaGradient_std)
ot_check_test (NatafIndependentCopulaHessian_std)
ot_check_test (IsoProbabilisticTransformation_IndependentCopula)
ot_check_test (IsoProbabilisticTransformation_EllipticalCopula)
ot_check_test (IsoProbabilisticTransformation_EllipticalDistribution)
ot_check_test (BoxCoxFactory_std)
ot_check_test (BoxCoxFactory_glm)
ot_check_test (TrendFactory_std)

# Bayesian
ot_check_test (CalibrationStrategy_std)
ot_check_test (RandomWalkMetropolisHastings_std)
ot_check_test (RandomWalkMetropolisHastings_regression)

# Classification
ot_check_test (MixtureClassifier_std)

# Experiments
ot_check_test (MinMax_computation)
ot_check_test (Axial_std)
ot_check_test (Box_std)
ot_check_test (Composite_std)
ot_check_test (Factorial_std)
ot_check_test (Combinations_std)
ot_check_test (KPermutations_std)
ot_check_test (Tuples_std)
ot_check_test (BootstrapExperiment_std)
ot_check_test (FixedExperiment_std)
ot_check_test (SpaceFilling_std)
ot_check_test (MonteCarloLHS_std)
ot_check_test (SimulatedAnnealingLHS_std)
ot_check_test (GaussProductExperiment_std)
ot_check_test (ImportanceSamplingExperiment_std)
ot_check_test (LHSExperiment_std)
ot_check_test (LowDiscrepancyExperiment_std)
ot_check_test (MonteCarloExperiment_std)

# OrthogonalBasis
ot_check_test (LinearEnumerateFunction_std)
ot_check_test (HyperbolicAnisotropicEnumerateFunction_std)
ot_check_test (OrthogonalUniVariatePolynomial_std)
ot_check_test (CharlierFactory_std)
ot_check_test (ChebychevFactory_std)
ot_check_test (HermiteFactory_std)
ot_check_test (HistogramPolynomialFactory_std)
ot_check_test (JacobiFactory_std)
ot_check_test (KrawtchoukFactory_std)
ot_check_test (LaguerreFactory_std)
ot_check_test (LegendreFactory_std)
ot_check_test (MeixnerFactory_std)
ot_check_test (SoizeGhanemFactory_std)
ot_check_test (OrthonormalizationAlgorithm_std)
ot_check_test (AdaptiveStieltjesAlgorithm_std)
ot_check_test (StandardDistributionPolynomialFactory_std)
ot_check_test (OrthogonalBasis_std)

# MetaModel
ot_check_test (FunctionalChaosRandomVector_std)
ot_check_test (FunctionalChaos_gsobol)
ot_check_test (FunctionalChaos_ishigami)
ot_check_test (FunctionalChaos_gsobol_sparse)
ot_check_test (FunctionalChaos_ishigami_sparse)
ot_check_test (FunctionalChaos_ishigami_database)
ot_check_test (FunctionalChaos_nd)
ot_check_test (KrigingAlgorithm_std)
ot_check_test (KrigingRandomVector_std)
ot_check_test (MetaModelValidation_std)
ot_check_test (GeneralLinearModelAlgorithm_std)
ot_check_test (TensorApproximationAlgorithm_std)

if (HMAT_FOUND)
ot_check_test (KrigingAlgorithm_std_hmat)
ot_check_test (GeneralLinearModelAlgorithm_std_hmat)
endif ()

if (NLOPT_FOUND)
ot_check_test (GeneralLinearModelAlgorithm_nlopt)
endif ()

# Sensitivity
ot_check_test (ANCOVA_std)
ot_check_test (FAST_std)
ot_check_test (SobolIndicesAlgorithm_std)

# Simulation
ot_check_test (DirectionalSampling_std)
ot_check_test (LHS_std)
ot_check_test (ProbabilitySimulationAlgorithm_std)
if (R_base_FOUND)
ot_check_test (ProbabilitySimulationAlgorithm_draw)
endif ()
ot_check_test (ProbabilitySimulationAlgorithm_sensitivity)
ot_check_test (PostAnalyticalControlledImportanceSampling_std)
ot_check_test (PostAnalyticalImportanceSampling_std)
ot_check_test (Wilks_std)
ot_check_test (SimulationSensitivityAnalysis_std)
ot_check_test (QuadrantSampling_std)
ot_check_test (AdaptiveDirectionalSampling_std)

# StatTests
if (R_rot_FOUND)
ot_check_test (VisualTest_std)
ot_check_test (FittingTest_std)
ot_check_test (HypothesisTest_std)
ot_check_test (HypothesisTest_correlation)
ot_check_test (LinearModelTest_std)
ot_check_test (NormalityTest_std)
endif ()
ot_check_test (DickeyFullerTest_std)
ot_check_test (TaylorExpansionMoments_std)

## Post-installation tests

# Common
ot_check_test (Path_std IGNOREOUT)

# Func
ot_check_test (Function_std)
ot_check_test (ComposedFunction_std)

# Stat
ot_check_test (Sample_csv)

# Diff
ot_check_test (NonCenteredFiniteDifferenceGradient_std)
ot_check_test (CenteredFiniteDifferenceGradient_std)
ot_check_test (CenteredFiniteDifferenceHessian_std)

# Experiments
ot_check_test (LinearTaylor_std)
ot_check_test (QuadraticLeastSquares_std)
ot_check_test (LinearLeastSquares_std)


# Waarts tests
# ot_check_test (Waarts_25_quadratic_terms)
# ot_check_test (Waarts_concave)
# ot_check_test (Waarts_convex)
# ot_check_test (Waarts_discontinuous_lsf)
# ot_check_test (Waarts_noisy_lsf)
# ot_check_test (Waarts_oblate)
# ot_check_test (Waarts_RS2)
# ot_check_test (Waarts_saddle)
# ot_check_test (Waarts_system_series)


add_custom_target (cppcheck COMMAND ${CMAKE_CTEST_COMMAND} -R "^cppcheck_"
                    DEPENDS ${CHECK_TO_BE_RUN}
                    COMMENT "Run C++ pre-installation tests")
add_dependencies (check cppcheck)


