-
Notifications
You must be signed in to change notification settings - Fork 30
/
CMakeLists.txt
111 lines (101 loc) · 4.15 KB
/
CMakeLists.txt
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
cmake_minimum_required (VERSION 3.8)
project (main)
MESSAGE( STATUS "PROJECT_NAME: " ${PROJECT_NAME} )
find_package(OpenCV REQUIRED)
option(ARM32_BUILD "Build for ARM32" OFF)
# Check ../../../platforms
if (CMAKE_HOST_WIN32)
set(WINDOWS 1)
elseif(CMAKE_HOST_APPLE)
set(MACOS 1)
elseif(CMAKE_HOST_UNIX)
set(LINUX 1)
endif()
# Check compiler architecture
if(CMAKE_CL_64)
MESSAGE( STATUS ">>>>>>>> 64-bit")
else()
MESSAGE( STATUS ">>>>>>>> 32-bit")
endif()
# Check compilers
MESSAGE( STATUS ">>>>>>>> ${CMAKE_CXX_COMPILER_ID}")
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
MESSAGE( STATUS "Using Clang" )
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
MESSAGE( STATUS "Using GNU" )
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
MESSAGE( STATUS "Using Intel" )
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
MESSAGE( STATUS "Using MSVC" )
endif()
# Set RPATH
if(CMAKE_HOST_UNIX)
if(CMAKE_HOST_APPLE)
SET(CMAKE_CXX_FLAGS "-std=c++11 -O3 -Wl,-rpath,@loader_path")
SET(CMAKE_INSTALL_RPATH "@loader_path")
else()
SET(CMAKE_CXX_FLAGS "-std=c++11 -O3 -Wl,-rpath=$ORIGIN")
SET(CMAKE_INSTALL_RPATH "$ORIGIN")
endif()
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()
# Add search path for include and lib files
MESSAGE( STATUS "CPU architecture ${CMAKE_SYSTEM_PROCESSOR}" )
if(WINDOWS)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
link_directories("${PROJECT_SOURCE_DIR}/../../../platforms/win/bin/")
else()
link_directories("${PROJECT_SOURCE_DIR}/../../../platforms/win/lib/")
endif()
elseif(LINUX)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
MESSAGE( STATUS "Link directory: ${PROJECT_SOURCE_DIR}/../../../platforms/linux/" )
link_directories("${PROJECT_SOURCE_DIR}/../../../platforms/linux/")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l OR ARM32_BUILD)
MESSAGE( STATUS "Link directory: ${PROJECT_SOURCE_DIR}/../../../platforms/arm32/" )
link_directories("${PROJECT_SOURCE_DIR}/../../../platforms/arm32/")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
MESSAGE( STATUS "Link directory: ${PROJECT_SOURCE_DIR}/../../../platforms/aarch64/" )
link_directories("${PROJECT_SOURCE_DIR}/../../../platforms/aarch64/")
endif()
elseif(MACOS)
MESSAGE( STATUS "Link directory: ${PROJECT_SOURCE_DIR}/../../../platforms/macos/" )
link_directories("${PROJECT_SOURCE_DIR}/../../../platforms/macos/")
endif()
include_directories("${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/../../../include/")
# Add the executable
add_executable(${PROJECT_NAME} main.cxx)
if(WINDOWS)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_libraries (${PROJECT_NAME} "DynamsoftBarcodeReaderx64" ${OpenCV_LIBS})
else()
if(CMAKE_CL_64)
target_link_libraries (${PROJECT_NAME} "DBRx64" ${OpenCV_LIBS})
else()
target_link_libraries (${PROJECT_NAME} "DBRx86" ${OpenCV_LIBS})
endif()
endif()
else()
target_link_libraries (${PROJECT_NAME} "DynamsoftBarcodeReader" pthread ${OpenCV_LIBS})
endif()
if(WINDOWS)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${PROJECT_SOURCE_DIR}/../../../platforms/win/bin/"
$<TARGET_FILE_DIR:main>)
endif()
# Set installation directory
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${PROJECT_SOURCE_DIR}/dist)
if(WINDOWS)
install (DIRECTORY "${PROJECT_SOURCE_DIR}/../../../platforms/win/bin/" DESTINATION ${PROJECT_SOURCE_DIR}/dist)
elseif(LINUX)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
install (DIRECTORY "${PROJECT_SOURCE_DIR}/../../../platforms/linux/" DESTINATION ${PROJECT_SOURCE_DIR}/dist)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l OR ARM32_BUILD)
install (DIRECTORY "${PROJECT_SOURCE_DIR}/../../../platforms/arm32/" DESTINATION ${PROJECT_SOURCE_DIR}/dist)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
install (DIRECTORY "${PROJECT_SOURCE_DIR}/../../../platforms/aarch64/" DESTINATION ${PROJECT_SOURCE_DIR}/dist)
endif()
elseif(MACOS)
install (DIRECTORY "${PROJECT_SOURCE_DIR}/../../../platforms/macos/" DESTINATION ${PROJECT_SOURCE_DIR}/dist)
endif()