75b7b7c7c3c434ce4a4ec62050884b0273c9034a
[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 0)
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 if (CMAKE_COMPILER_IS_GNUCC)
35   add_definitions(-Wall)
36
37   # let CFLAGS env override this
38   if(CMAKE_C_FLAGS STREQUAL "")
39     set(CMAKE_C_FLAGS "-std=c99 -pedantic -Wall -Wextra")
40   endif()
41
42   add_flags(CMAKE_C_FLAGS
43     -fno-common
44     -Wall
45     -Wextra
46     -Wformat=2
47     -Winit-self
48     -Winline
49     -Wpacked
50     -Wp,-D_FORTIFY_SOURCE=2
51     -Wpointer-arith
52     -Wlarger-than-65500
53     -Wmissing-declarations
54     -Wmissing-format-attribute
55     -Wmissing-noreturn
56     -Wmissing-prototypes
57     -Wnested-externs
58     -Wold-style-definition
59     -Wredundant-decls
60     -Wsign-compare
61     -Wstrict-aliasing=2
62     -Wstrict-prototypes
63     -Wswitch-enum
64     -Wundef
65     -Wunreachable-code
66     -Wunsafe-loop-optimizations
67     -Wwrite-strings
68     -fstack-protector
69     --param=ssp-buffer-size=4)
70
71   if (STRICT_COMPILATION_CHECKS)
72     add_flags(CMAKE_C_FLAGS
73       -Werror
74       # NOTE: Vanilla libusb-1.0.8 can't live with -pedantic-errors
75       -pedantic-errors
76       # NOTE: GCC >= 4.6 is needed for -Wunused-but-set-variable
77       -Wunused-but-set-variable)
78   endif()
79 endif()
80
81 set(CMAKE_C_FLAGS_DEBUG "-O0 -ggdb -DDEBUG=1")
82 set(CMAKE_C_FLAGS_RELEASE "-O2")
83 set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
84
85 # Add library project
86 add_subdirectory(src)
87 add_subdirectory(examples)
88 add_subdirectory(doc)