Skip to content

Commit

Permalink
CMake: use GenerateExportHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj authored and mshabunin committed Dec 4, 2017
1 parent fc9e031 commit 6ead355
Show file tree
Hide file tree
Showing 25 changed files with 173 additions and 392 deletions.
19 changes: 19 additions & 0 deletions CMakeLists.txt
Expand Up @@ -798,6 +798,25 @@ endif()
# Finalization: generate configuration-based files
# ----------------------------------------------------------------------------

# generate export definintions file
include(GenerateExportHeader)
set(EXPORT_FILE_NAME "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/cv_exports.h")
set(EXPORT_TARGET_NAME opencv_core)
if(BUILD_opencv_world)
set(EXPORT_TARGET_NAME opencv_world)
endif()
generate_export_header(${EXPORT_TARGET_NAME}
BASE_NAME "CV"
EXPORT_FILE_NAME "${EXPORT_FILE_NAME}"
EXPORT_MACRO_NAME "CV_EXPORTS"
DEPRECATED_MACRO_NAME "CV_DEPRECATED"
NO_EXPORT_MACRO_NAME "CV_NO_EXPORTS"
NO_DEPRECATED_MACRO_NAME "CV_NO_DEPRECATED"
STATIC_DEFINE "CV_USE_STATIC"
)
install(FILES "${EXPORT_FILE_NAME}" DESTINATION "${OPENCV_INCLUDE_INSTALL_PATH}/opencv2" COMPONENT dev)


# Generate platform-dependent and configuration-dependent headers
include(cmake/OpenCVGenHeaders.cmake)

Expand Down
26 changes: 0 additions & 26 deletions apps/traincascade/old_ml.hpp
Expand Up @@ -1895,32 +1895,6 @@ class CvANN_MLP : public CvStatModel
cv::RNG* rng;
};

/****************************************************************************************\
* Auxilary functions declarations *
\****************************************************************************************/

/* Generates <sample> from multivariate normal distribution, where <mean> - is an
average row vector, <cov> - symmetric covariation matrix */
CVAPI(void) cvRandMVNormal( CvMat* mean, CvMat* cov, CvMat* sample,
CvRNG* rng CV_DEFAULT(0) );

/* Generates sample from gaussian mixture distribution */
CVAPI(void) cvRandGaussMixture( CvMat* means[],
CvMat* covs[],
float weights[],
int clsnum,
CvMat* sample,
CvMat* sampClasses CV_DEFAULT(0) );

#define CV_TS_CONCENTRIC_SPHERES 0

/* creates test set */
CVAPI(void) cvCreateTestSet( int type, CvMat** samples,
int num_samples,
int num_features,
CvMat** responses,
int num_classes, ... );

/****************************************************************************************\
* Data *
\****************************************************************************************/
Expand Down
191 changes: 0 additions & 191 deletions apps/traincascade/old_ml_inner_functions.cpp
Expand Up @@ -114,153 +114,11 @@ void CvStatModel::write( CvFileStorage*, const char* ) const
OPENCV_ERROR( CV_StsNotImplemented, "CvStatModel::write", "" );
}


void CvStatModel::read( CvFileStorage*, CvFileNode* )
{
OPENCV_ERROR( CV_StsNotImplemented, "CvStatModel::read", "" );
}


/* Calculates upper triangular matrix S, where A is a symmetrical matrix A=S'*S */
static void cvChol( CvMat* A, CvMat* S )
{
int dim = A->rows;

int i, j, k;
float sum;

for( i = 0; i < dim; i++ )
{
for( j = 0; j < i; j++ )
CV_MAT_ELEM(*S, float, i, j) = 0;

sum = 0;
for( k = 0; k < i; k++ )
sum += CV_MAT_ELEM(*S, float, k, i) * CV_MAT_ELEM(*S, float, k, i);

CV_MAT_ELEM(*S, float, i, i) = (float)sqrt(CV_MAT_ELEM(*A, float, i, i) - sum);

for( j = i + 1; j < dim; j++ )
{
sum = 0;
for( k = 0; k < i; k++ )
sum += CV_MAT_ELEM(*S, float, k, i) * CV_MAT_ELEM(*S, float, k, j);

CV_MAT_ELEM(*S, float, i, j) =
(CV_MAT_ELEM(*A, float, i, j) - sum) / CV_MAT_ELEM(*S, float, i, i);

}
}
}

/* Generates <sample> from multivariate normal distribution, where <mean> - is an
average row vector, <cov> - symmetric covariation matrix */
CV_IMPL void cvRandMVNormal( CvMat* mean, CvMat* cov, CvMat* sample, CvRNG* rng )
{
int dim = sample->cols;
int amount = sample->rows;

CvRNG state = rng ? *rng : cvRNG( cvGetTickCount() );
cvRandArr(&state, sample, CV_RAND_NORMAL, cvScalarAll(0), cvScalarAll(1) );

CvMat* utmat = cvCreateMat(dim, dim, sample->type);
CvMat* vect = cvCreateMatHeader(1, dim, sample->type);

cvChol(cov, utmat);

int i;
for( i = 0; i < amount; i++ )
{
cvGetRow(sample, vect, i);
cvMatMulAdd(vect, utmat, mean, vect);
}

cvReleaseMat(&vect);
cvReleaseMat(&utmat);
}


/* Generates <sample> of <amount> points from a discrete variate xi,
where Pr{xi = k} == probs[k], 0 < k < len - 1. */
static void cvRandSeries( float probs[], int len, int sample[], int amount )
{
CvMat* univals = cvCreateMat(1, amount, CV_32FC1);
float* knots = (float*)cvAlloc( len * sizeof(float) );

int i, j;

CvRNG state = cvRNG(-1);
cvRandArr(&state, univals, CV_RAND_UNI, cvScalarAll(0), cvScalarAll(1) );

knots[0] = probs[0];
for( i = 1; i < len; i++ )
knots[i] = knots[i - 1] + probs[i];

for( i = 0; i < amount; i++ )
for( j = 0; j < len; j++ )
{
if ( CV_MAT_ELEM(*univals, float, 0, i) <= knots[j] )
{
sample[i] = j;
break;
}
}

cvFree(&knots);
}

/* Generates <sample> from gaussian mixture distribution */
CV_IMPL void cvRandGaussMixture( CvMat* means[],
CvMat* covs[],
float weights[],
int clsnum,
CvMat* sample,
CvMat* sampClasses )
{
int dim = sample->cols;
int amount = sample->rows;

int i, clss;

int* sample_clsnum = (int*)cvAlloc( amount * sizeof(int) );
CvMat** utmats = (CvMat**)cvAlloc( clsnum * sizeof(CvMat*) );
CvMat* vect = cvCreateMatHeader(1, dim, CV_32FC1);

CvMat* classes;
if( sampClasses )
classes = sampClasses;
else
classes = cvCreateMat(1, amount, CV_32FC1);

CvRNG state = cvRNG(-1);
cvRandArr(&state, sample, CV_RAND_NORMAL, cvScalarAll(0), cvScalarAll(1));

cvRandSeries(weights, clsnum, sample_clsnum, amount);

for( i = 0; i < clsnum; i++ )
{
utmats[i] = cvCreateMat(dim, dim, CV_32FC1);
cvChol(covs[i], utmats[i]);
}

for( i = 0; i < amount; i++ )
{
CV_MAT_ELEM(*classes, float, 0, i) = (float)sample_clsnum[i];
cvGetRow(sample, vect, i);
clss = sample_clsnum[i];
cvMatMulAdd(vect, utmats[clss], means[clss], vect);
}

if( !sampClasses )
cvReleaseMat(&classes);
for( i = 0; i < clsnum; i++ )
cvReleaseMat(&utmats[i]);
cvFree(&utmats);
cvFree(&sample_clsnum);
cvReleaseMat(&vect);
}


CvMat* icvGenerateRandomClusterCenters ( int seed, const CvMat* data,
int num_of_clusters, CvMat* _centers )
{
Expand Down Expand Up @@ -317,55 +175,6 @@ CvMat* icvGenerateRandomClusterCenters ( int seed, const CvMat* data,
return _centers ? _centers : centers;
} // end of icvGenerateRandomClusterCenters

// By S. Dilman - begin -

#define ICV_RAND_MAX 4294967296 // == 2^32

// static void cvRandRoundUni (CvMat* center,
// float radius_small,
// float radius_large,
// CvMat* desired_matrix,
// CvRNG* rng_state_ptr)
// {
// float rad, norm, coefficient;
// int dim, size, i, j;
// CvMat *cov, sample;
// CvRNG rng_local;

// CV_FUNCNAME("cvRandRoundUni");
// __BEGIN__

// rng_local = *rng_state_ptr;

// CV_ASSERT ((radius_small >= 0) &&
// (radius_large > 0) &&
// (radius_small <= radius_large));
// CV_ASSERT (center && desired_matrix && rng_state_ptr);
// CV_ASSERT (center->rows == 1);
// CV_ASSERT (center->cols == desired_matrix->cols);

// dim = desired_matrix->cols;
// size = desired_matrix->rows;
// cov = cvCreateMat (dim, dim, CV_32FC1);
// cvSetIdentity (cov);
// cvRandMVNormal (center, cov, desired_matrix, &rng_local);

// for (i = 0; i < size; i++)
// {
// rad = (float)(cvRandReal(&rng_local)*(radius_large - radius_small) + radius_small);
// cvGetRow (desired_matrix, &sample, i);
// norm = (float) cvNorm (&sample, 0, CV_L2);
// coefficient = rad / norm;
// for (j = 0; j < dim; j++)
// CV_MAT_ELEM (sample, float, 0, j) *= coefficient;
// }

// __END__

// }

// By S. Dilman - end -

static int CV_CDECL
icvCmpIntegers( const void* a, const void* b )
{
Expand Down
2 changes: 1 addition & 1 deletion apps/traincascade/old_ml_tree.cpp
Expand Up @@ -1880,7 +1880,7 @@ double CvDTree::calc_node_dir( CvDTreeNode* node )
namespace cv
{

template<> CV_EXPORTS void DefaultDeleter<CvDTreeSplit>::operator ()(CvDTreeSplit* obj) const
template<> void DefaultDeleter<CvDTreeSplit>::operator ()(CvDTreeSplit* obj) const
{
fastFree(obj);
}
Expand Down
14 changes: 3 additions & 11 deletions cmake/OpenCVCompilerOptions.cmake
Expand Up @@ -33,8 +33,7 @@ if(MSVC)
string(STRIP "${CMAKE_CXX_FLAGS_INIT}" CMAKE_CXX_FLAGS_INIT)
if(CMAKE_CXX_FLAGS STREQUAL CMAKE_CXX_FLAGS_INIT)
# override cmake default exception handling option
string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHa")
string(REPLACE "/EHsc" "/EHa" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "Flags used by the compiler during all build types." FORCE)
endif()
endif()
Expand Down Expand Up @@ -178,10 +177,12 @@ if(CMAKE_COMPILER_IS_GNUCXX)
OPENCV_EXTRA_FLAGS_RELEASE OPENCV_EXTRA_FLAGS_DEBUG OPENCV_EXTRA_C_FLAGS OPENCV_EXTRA_CXX_FLAGS)
string(REPLACE "-fomit-frame-pointer" "" ${flags} "${${flags}}")
string(REPLACE "-ffunction-sections" "" ${flags} "${${flags}}")
string(REPLACE "-fdata-sections" "" ${flags} "${${flags}}")
endforeach()
elseif(NOT ((IOS OR ANDROID) AND NOT BUILD_SHARED_LIBS))
# Remove unreferenced functions: function level linking
add_extra_compiler_option(-ffunction-sections)
add_extra_compiler_option(-fdata-sections)
endif()

if(ENABLE_COVERAGE)
Expand Down Expand Up @@ -241,15 +242,6 @@ if(WINRT_PHONE AND WINRT_8_0)
set(OPENCV_EXTRA_CXX_FLAGS "${OPENCV_EXTRA_CXX_FLAGS} /AI\$(WindowsSDK_MetadataPath)")
endif()

# Extra link libs if the user selects building static libs:
if(NOT BUILD_SHARED_LIBS AND CMAKE_COMPILER_IS_GNUCXX AND NOT ANDROID)
# Android does not need these settings because they are already set by toolchain file
if(NOT MINGW)
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} stdc++)
endif()
set(OPENCV_EXTRA_FLAGS "-fPIC ${OPENCV_EXTRA_FLAGS}")
endif()

include(cmake/OpenCVCompilerOptimizations.cmake)

if(COMMAND ocv_compiler_optimization_options)
Expand Down
10 changes: 3 additions & 7 deletions cmake/OpenCVModule.cmake
Expand Up @@ -852,7 +852,6 @@ macro(_ocv_create_module)
${${the_module}_pch}
${_VS_VERSION_FILE}
)

set_target_properties(${the_module} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};Module")
set_source_files_properties(${OPENCV_MODULE_${the_module}_HEADERS} ${OPENCV_MODULE_${the_module}_SOURCES} ${${the_module}_pch}
PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};Module")
Expand All @@ -879,6 +878,8 @@ macro(_ocv_create_module)
COMPILE_PDB_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
DEFINE_SYMBOL CVAPI_EXPORTS
POSITION_INDEPENDENT_CODE TRUE
)

# For dynamic link numbering convenions
Expand All @@ -891,11 +892,6 @@ macro(_ocv_create_module)
)
endif()

if((NOT DEFINED OPENCV_MODULE_TYPE AND BUILD_SHARED_LIBS)
OR (DEFINED OPENCV_MODULE_TYPE AND OPENCV_MODULE_TYPE STREQUAL SHARED))
set_target_properties(${the_module} PROPERTIES DEFINE_SYMBOL CVAPI_EXPORTS)
endif()

if (ENABLE_GNU_STL_DEBUG)
target_compile_definitions(${the_module} PUBLIC _GLIBCXX_DEBUG)
endif()
Expand Down Expand Up @@ -925,7 +921,7 @@ macro(_ocv_create_module)
if(OPENCV_MODULE_${the_module}_HEADERS AND ";${OPENCV_MODULES_PUBLIC};" MATCHES ";${the_module};")
foreach(hdr ${OPENCV_MODULE_${the_module}_HEADERS})
string(REGEX REPLACE "^.*opencv2/" "opencv2/" hdr2 "${hdr}")
if(NOT hdr2 MATCHES "private" AND hdr2 MATCHES "^(opencv2/?.*)/[^/]+.h(..)?$" )
if(NOT hdr2 MATCHES "opencv2/${the_module}/private.*" AND hdr2 MATCHES "^(opencv2/?.*)/[^/]+.h(..)?$" )
install(FILES ${hdr} OPTIONAL DESTINATION "${OPENCV_INCLUDE_INSTALL_PATH}/${CMAKE_MATCH_1}" COMPONENT dev)
endif()
endforeach()
Expand Down
24 changes: 10 additions & 14 deletions modules/core/include/opencv2/core/cvdef.h
Expand Up @@ -248,22 +248,18 @@ Cv64suf;
# define DISABLE_OPENCV_24_COMPATIBILITY
#endif

#if (defined _WIN32 || defined WINCE || defined __CYGWIN__) && defined CVAPI_EXPORTS
# define CV_EXPORTS __declspec(dllexport)
#elif defined __GNUC__ && __GNUC__ >= 4
# define CV_EXPORTS __attribute__ ((visibility ("default")))
#else
# define CV_EXPORTS
#include "opencv2/cv_exports.h"

// fix for Android FAT_JAVA_LIB: symbols should have default visibility even in static libraries
#ifdef __ANDROID__
#undef CV_EXPORTS
#define CV_EXPORTS __attribute__ ((visibility ("default")))
#endif

#ifndef CV_DEPRECATED
# if defined(__GNUC__)
# define CV_DEPRECATED __attribute__ ((deprecated))
# elif defined(_MSC_VER)
# define CV_DEPRECATED __declspec(deprecated)
# else
# define CV_DEPRECATED
# endif
#ifdef _MSC_VER
#define CV_EXPORTS_TEMPLATE
#else
#define CV_EXPORTS_TEMPLATE CV_EXPORTS
#endif

#ifndef CV_EXTERN_C
Expand Down
1 change: 1 addition & 0 deletions modules/core/test/test_precomp.hpp
Expand Up @@ -11,6 +11,7 @@

#include <iostream>
#include "opencv2/ts.hpp"
#include "opencv2/ts/ocl_test.hpp"
#include "opencv2/core/core_c.h"

#include "opencv2/core/cvdef.h"
Expand Down

0 comments on commit 6ead355

Please sign in to comment.