be8e4e778c714f705c9aad066dba2cc3e203b362
[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 0)
9 set(PROJECT_VER_PATCH 1)
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 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
20 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
21 set(DOC_OUTPUT_PATH ${CMAKE_BINARY_DIR}/doc)
22
23 # Because cmake cannot deal sanely with multiline strings. SRSLY?
24 # See http://www.vtkedge.org/Bug/view.php?id=8362&nbn=8
25 macro(add_flags var)
26   string(REPLACE ";" " " _flags "${ARGN}")
27   set(${var} "${${var}} ${_flags}")
28 endmacro(add_flags)
29
30 if (CMAKE_COMPILER_IS_GNUCC)
31   add_definitions(-Wall)
32
33   # let CFLAGS env override this
34   if(CMAKE_C_FLAGS STREQUAL "")
35     set(CMAKE_C_FLAGS "-std=c99 -pedantic -Wall -Wextra -O2")
36   endif()
37
38   # Don't make pedantic checks errors,
39   # as vanilla libusb-1.0.8 can't live with that
40   #add_flags(CMAKE_C_FLAGS -pedantic-errors)
41
42   # GCC >= 4.6
43   #add_flags(CMAKE_C_FLAGS -Wunused-but-set-variable)
44
45   add_flags(CMAKE_C_FLAGS
46     -fno-common
47     -Wall
48     -Wextra
49     -Wformat=2
50     -Winit-self
51     -Winline
52     -Wpacked
53     -Wp,-D_FORTIFY_SOURCE=2
54     -Wpointer-arith
55     -Wlarger-than-65500
56     -Wmissing-declarations
57     -Wmissing-format-attribute
58     -Wmissing-noreturn
59     -Wmissing-prototypes
60     -Wnested-externs
61     -Wold-style-definition
62     -Wredundant-decls
63     -Wsign-compare
64     -Wstrict-aliasing=2
65     -Wstrict-prototypes
66     -Wswitch-enum
67     -Wundef
68     -Wunreachable-code
69     -Wunsafe-loop-optimizations
70     -Wwrite-strings
71     )
72 endif()
73
74 set(CMAKE_C_FLAGS_DEBUG "-g -DDEBUG=1 -Werror")
75 set(CMAKE_C_FLAGS_RELEASE "-O2")
76 set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
77
78 # Use git for some maintainance tasks
79 find_package(Git)
80 if(GIT_FOUND)
81   set(ARCHIVE_PREFIX ${CMAKE_PROJECT_NAME}-${PROJECT_VER})
82   find_program(DATE_EXECUTABLE date DOC "date command line program")
83   if (DATE_EXECUTABLE)
84     message(STATUS "Found date: " ${DATE_EXECUTABLE})
85     message(STATUS "Generator is: " ${CMAKE_GENERATOR})
86
87     # XXX: using $(shell CMD) works only with Unix Makefile
88     if (CMAKE_GENERATOR STREQUAL "Unix Makefiles")
89       message(STATUS " - \"git archive\" will use the date too!")
90       set(ARCHIVE_PREFIX ${ARCHIVE_PREFIX}-$\(shell ${DATE_EXECUTABLE} +%Y%m%d%H%M\))
91     endif()
92   endif()
93   add_custom_target(archive
94     COMMAND ${GIT_EXECUTABLE} archive -o \"${ARCHIVE_PREFIX}.tar.gz\" --prefix=\"${ARCHIVE_PREFIX}/\" HEAD
95     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
96
97   add_custom_target(changelog
98     COMMAND ${GIT_EXECUTABLE} log --pretty=\"format:%ai  %aN  <%aE>%n%n%x09* %s%d%n\" > ChangeLog
99     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
100 endif(GIT_FOUND)
101
102 # Add library project
103 add_subdirectory(src)