Skip to content

Commit

Permalink
CMake for Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
yushulx committed Aug 28, 2019
1 parent 14de9de commit c1752b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
23 changes: 8 additions & 15 deletions BarcodeReader.cxx
Expand Up @@ -10,19 +10,12 @@
#include <sys/time.h>
#endif


using namespace cv;
using namespace std;
using std::cout;
using std::cerr;
using std::endl;

// #ifdef _WIN64
// #pragma comment(lib, "Lib/DBRx64.lib")
// #else
// #pragma comment(lib, "Lib/DBRx86.lib")
// #endif

void ToHexString(unsigned char* pSrc, int iLen, char* pDest)
{
const char HEXCHARS[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
Expand All @@ -32,7 +25,7 @@ void ToHexString(unsigned char* pSrc, int iLen, char* pDest)

for (i = 0; i < iLen; ++i)
{
sprintf_s(ptr, 4, "%c%c ", HEXCHARS[(pSrc[i] & 0xF0) >> 4], HEXCHARS[(pSrc[i] & 0x0F) >> 0]);
snprintf(ptr, 4, "%c%c ", HEXCHARS[(pSrc[i] & 0xF0) >> 4], HEXCHARS[(pSrc[i] & 0x0F) >> 0]);
ptr += 3;
}
}
Expand All @@ -47,28 +40,28 @@ void textResultcallback(int frameId, TextResultArray *pResults, void * pUser)

if (pResults->resultsCount == 0)
{
sprintf_s(pszTemp, 4096, "No barcode found.\r\n\r\n");
snprintf(pszTemp, 4096, "No barcode found.\r\n\r\n");
printf(pszTemp);
free(pszTemp);
CBarcodeReader::FreeTextResults(&pResults);
return;
}

sprintf_s(pszTemp, 4096, "\r\n\r\nframe = %d,Total barcode(s) found: %d.\n", frameId, pResults->resultsCount);
snprintf(pszTemp, 4096, "\r\n\r\nframe = %d,Total barcode(s) found: %d.\n", frameId, pResults->resultsCount);
printf(pszTemp);
for (int iIndex = 0; iIndex < pResults->resultsCount; iIndex++)
{
sprintf_s(pszTemp, 4096, "Barcode %d:\r\n", iIndex + 1);
snprintf(pszTemp, 4096, "Barcode %d:\r\n", iIndex + 1);
printf(pszTemp);
sprintf_s(pszTemp, 4096, " Type: %s\r\n", pResults->results[iIndex]->barcodeFormatString);
snprintf(pszTemp, 4096, " Type: %s\r\n", pResults->results[iIndex]->barcodeFormatString);
printf(pszTemp);
sprintf_s(pszTemp, 4096, " Value: %s\r\n", pResults->results[iIndex]->barcodeText);
snprintf(pszTemp, 4096, " Value: %s\r\n", pResults->results[iIndex]->barcodeText);
printf(pszTemp);

pszTemp1 = (char*)malloc(pResults->results[iIndex]->barcodeBytesLength * 3 + 1);
pszTemp2 = (char*)malloc(pResults->results[iIndex]->barcodeBytesLength*3 + 100);
ToHexString(pResults->results[iIndex]->barcodeBytes, pResults->results[iIndex]->barcodeBytesLength, pszTemp1);
sprintf_s(pszTemp2, pResults->results[iIndex]->barcodeBytesLength*3 + 100, " Hex Data: %s\r\n", pszTemp1);
snprintf(pszTemp2, pResults->results[iIndex]->barcodeBytesLength*3 + 100, " Hex Data: %s\r\n", pszTemp1);
printf(pszTemp2);
free(pszTemp1);
free(pszTemp2);
Expand All @@ -86,7 +79,7 @@ void errorcb(int frameId, int errorCode, void * pUser)
if (errorCode != DBR_OK && errorCode != DBRERR_LICENSE_EXPIRED && errorCode != DBRERR_QR_LICENSE_INVALID &&
errorCode != DBRERR_1D_LICENSE_INVALID && errorCode != DBRERR_PDF417_LICENSE_INVALID && errorCode != DBRERR_DATAMATRIX_LICENSE_INVALID)
{
sprintf_s(pszTemp, 4096, "Failed to read barcode: %s\r\n", CBarcodeReader::GetErrorString(errorCode));
snprintf(pszTemp, 4096, "Failed to read barcode: %s\r\n", CBarcodeReader::GetErrorString(errorCode));
printf(pszTemp);
free(pszTemp);
return;
Expand Down
9 changes: 7 additions & 2 deletions CMakeLists.txt
Expand Up @@ -35,6 +35,7 @@ if(WINDOWS)
link_directories("${PROJECT_SOURCE_DIR}/platforms/win/lib/")
elseif(LINUX)
link_directories("${PROJECT_SOURCE_DIR}/platforms/linux/")
find_package(OpenCV REQUIRED)
elseif(MACOS)
link_directories("${PROJECT_SOURCE_DIR}/platforms/macos/")
endif()
Expand All @@ -49,15 +50,19 @@ if(WINDOWS)
target_link_libraries (BarcodeReader "DBRx86" "opencv_core347d.lib" "opencv_highgui347d.lib" "opencv_videoio347d.lib")
endif()
else()
target_link_libraries (BarcodeReader "DynamsoftBarcodeReader")
target_link_libraries (BarcodeReader "DynamsoftBarcodeReader" ${OpenCV_LIBS})
endif()

if(WINDOWS)
add_custom_command(TARGET BarcodeReader POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${PROJECT_SOURCE_DIR}/platforms/win/bin/"
$<TARGET_FILE_DIR:BarcodeReader>)

elseif(LINUX)
add_custom_command(TARGET BarcodeReader POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${PROJECT_SOURCE_DIR}/platforms/linux/"
$<TARGET_FILE_DIR:BarcodeReader>)
endif()

# Set installation directory
Expand Down

0 comments on commit c1752b4

Please sign in to comment.