aboutsummaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
blob: e25cc1f80ad09ce916eb10b2e7c256fa2931cb7d (plain)
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
#
# O-3000 driver
#

project(O-3000-Driver)

cmake_minimum_required(VERSION 3.0)

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
	set(CC_ARCH "64")
else(CMAKE_SIZEOF_VOID_P EQUAL 8)
	set(CC_ARCH "32")
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)

# library version definition
set(VERSION_MAJOR "2")
set(VERSION_MINOR "1")
set(VERSION_RELEASE "0")
set(VERSION_STR "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_RELEASE}")

# pass macros to preprocessor
add_definitions(-DO3000_VERSION="${VERSION_STR}")

# library name
set(LIB_NAME o3000)

# find libusb library (version 1.0.19 or higher is needed!)
find_package(LibUSB REQUIRED)

include_directories(.)
include_directories(${LIBUSB_INCLUDE_DIRS})

add_library(				${LIB_NAME} SHARED
							o3000.c
							o3000_private.h
							o3000_xfer_handler.c
							o3000_xfer_handler.h
							o3000_upgrade.c
							md5_helper.c
							md5.c
							)

set_target_properties	(	${LIB_NAME} PROPERTIES
							OUTPUT_NAME "${LIB_NAME}"
							VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_RELEASE}"
							SOVERSION ${VERSION_MAJOR}
							LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
						)

target_compile_options(${LIB_NAME} PRIVATE -Wall -g -ggdb -O3 -fPIC)
target_link_libraries(${LIB_NAME} pthread ${LIBUSB_LIBRARIES})

install(TARGETS ${LIB_NAME} DESTINATION lib)
install(FILES "o3000.h" "o3000_portable.h" "image_header.h" DESTINATION "include/o3000")

add_custom_target(release DEPENDS ${LIB_NAME})
add_custom_command(
	TARGET release
	COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/libo3000-${VERSION_STR}/include/o3000
	COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/libo3000-${VERSION_STR}/MinGW${CC_ARCH}
	COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/o3000.h ${CMAKE_CURRENT_BINARY_DIR}/libo3000-${VERSION_STR}/include/o3000
	COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/o3000_portable.h ${CMAKE_CURRENT_BINARY_DIR}/libo3000-${VERSION_STR}/include/o3000
	COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/image_header.h ${CMAKE_CURRENT_BINARY_DIR}/libo3000-${VERSION_STR}/include/o3000
	COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:${LIB_NAME}>* ${CMAKE_CURRENT_BINARY_DIR}/libo3000-${VERSION_STR}/MinGW${CC_ARCH}
	COMMAND ${CMAKE_COMMAND} -E tar "cfv" "libo3000-${VERSION_STR}-${CC_ARCH}bit.zip" --format=zip libo3000-${VERSION_STR}
	COMMAND ${CMAKE_COMMAND} -E remove_directory libo3000-${VERSION_STR}
)