am7xxx: specify LIBUSB_CALL for send_data_async_complete_cb()
[libam7xxx.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.6)
2 project(libam7xxx C)
3
4 set(PROJECT_DESCRIPTION
5   "Communication library for Actions Micro AM7XXX based USB projectors and DPFs")
6
7 set(PROJECT_VER_MAJOR 0)
8 set(PROJECT_VER_MINOR 1)
9 set(PROJECT_VER_PATCH 5)
10 set(PROJECT_VER_EXTRA "")
11 set(PROJECT_VER
12   "${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}.${PROJECT_VER_PATCH}${PROJECT_VER_EXTRA}")
13 set(PROJECT_APIVER
14   "${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}")
15
16 set(CMAKE_MODULE_PATH
17   ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/")
18
19 OPTION(STRICT_COMPILATION_CHECKS "Enable stricter compilation checks" OFF)
20
21 include (MaintenanceTools)
22
23 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
24 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
25 set(DOC_OUTPUT_PATH ${CMAKE_BINARY_DIR}/doc)
26
27 # Because cmake cannot deal sanely with multiline strings. SRSLY?
28 # See http://www.vtkedge.org/Bug/view.php?id=8362&nbn=8
29 macro(add_flags var)
30   string(REPLACE ";" " " _flags "${ARGN}")
31   set(${var} "${${var}} ${_flags}")
32 endmacro(add_flags)
33
34 string(REGEX MATCH "clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER}")
35
36 if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
37   add_definitions(-Wall)
38
39   # let CFLAGS env override this
40   if(CMAKE_C_FLAGS STREQUAL "")
41     set(CMAKE_C_FLAGS "-std=c99 -pedantic -Wall -Wextra")
42   endif()
43
44   add_flags(CMAKE_C_FLAGS
45     -fvisibility=hidden
46     -fno-common
47     -Wall
48     -Wextra
49     -Wformat=2
50     -Winit-self
51     -Winline
52     -Wpacked
53     -Wpointer-arith
54     -Wlarger-than-65500
55     -Wmissing-declarations
56     -Wmissing-format-attribute
57     -Wmissing-noreturn
58     -Wmissing-prototypes
59     -Wnested-externs
60     -Wold-style-definition
61     -Wredundant-decls
62     -Wsign-compare
63     -Wstrict-aliasing=2
64     -Wstrict-prototypes
65     -Wswitch-enum
66     -Wundef
67     -Wunreachable-code
68     -Wwrite-strings
69     -fstack-protector)
70
71   add_flags(DEBUG_FLAGS
72     -ggdb)
73
74   add_flags(RELEASE_FLAGS
75     -Wp,-D_FORTIFY_SOURCE=2)
76
77   if (STRICT_COMPILATION_CHECKS)
78     add_flags(STRICT_FLAGS
79       -Werror
80       # sign conversion warnings can be very noisy for a very little gain
81       #-Wsign-conversion
82       # NOTE: Vanilla libusb-1.0.8 can't live with -pedantic-errors
83       -pedantic-errors)
84
85   endif()
86 endif()
87
88 if (CMAKE_COMPILER_IS_GNUCC)
89   add_flags(CMAKE_C_FLAGS
90     -Wunsafe-loop-optimizations
91     --param=ssp-buffer-size=4)
92
93   if (STRICT_COMPILATION_CHECKS)
94     add_flags(STRICT_FLAGS
95       # NOTE: GCC >= 4.6 is needed for -Wunused-but-set-variable
96       -Wunused-but-set-variable)
97   endif()
98 endif()
99
100 if (CMAKE_COMPILER_IS_CLANG)
101   if (STRICT_COMPILATION_CHECKS)
102     add_flags(STRICT_FLAGS
103       -Wshorten-64-to-32)
104   endif()
105 endif()
106
107 set(CMAKE_C_FLAGS_DEBUG "-O0 -DDEBUG=1 ${DEBUG_FLAGS} ${STRICT_FLAGS}")
108 set(CMAKE_C_FLAGS_RELEASE "-O2 ${RELEASE_FLAGS} ${STRICT_FLAGS}")
109 set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 ${RELEASE_FLAGS} ${DEBUG_FLAGS} ${STRICT_FLAGS}")
110
111 # Add library project
112 add_subdirectory(src)
113 add_subdirectory(examples)
114 add_subdirectory(doc)