ceb31e4b2e3d623e0a449775a6d9e5a040a4c7ea
[contrib/mraa.git] / src / CMakeLists.txt
1 set (mraa_LIB_INCLUDE_DIRS
2   ${PROJECT_SOURCE_DIR}/api
3   ${PROJECT_SOURCE_DIR}/api/mraa
4   ${PROJECT_SOURCE_DIR}/include
5 )
6
7 include_directories(
8   ${mraa_LIB_INCLUDE_DIRS}
9 )
10
11 set (mraa_LIB_SRCS_NOAUTO
12   ${PROJECT_SOURCE_DIR}/src/mraa.c
13   ${PROJECT_SOURCE_DIR}/src/gpio/gpio.c
14   ${PROJECT_SOURCE_DIR}/src/i2c/i2c.c
15   ${PROJECT_SOURCE_DIR}/src/pwm/pwm.c
16   ${PROJECT_SOURCE_DIR}/src/spi/spi.c
17   ${PROJECT_SOURCE_DIR}/src/aio/aio.c
18   ${PROJECT_SOURCE_DIR}/src/uart/uart.c
19   ${PROJECT_SOURCE_DIR}/src/iio/iio.c
20 )
21
22 set (mraa_LIB_X86_SRCS_NOAUTO
23   ${PROJECT_SOURCE_DIR}/src/x86/x86.c
24   ${PROJECT_SOURCE_DIR}/src/x86/intel_galileo_rev_d.c
25   ${PROJECT_SOURCE_DIR}/src/x86/intel_galileo_rev_g.c
26   ${PROJECT_SOURCE_DIR}/src/x86/intel_edison_fab_c.c
27   ${PROJECT_SOURCE_DIR}/src/x86/intel_de3815.c
28   ${PROJECT_SOURCE_DIR}/src/x86/intel_nuc5.c
29   ${PROJECT_SOURCE_DIR}/src/x86/intel_minnow_byt_compatible.c
30   ${PROJECT_SOURCE_DIR}/src/x86/intel_sofia_3gr.c
31 )
32
33 message (INFO " - Adding support for platform ${MRAAPLATFORMFORCE}")
34
35 #keywords in if statements are case sensitive
36 if (NOT ${MRAAPLATFORMFORCE} STREQUAL "ALL")
37   set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Dx${MRAAPLATFORMFORCE} -DMRAA_PLATFORM_FORCE=${MRAAPLATFORMFORCE}")
38   if (${MRAAPLATFORMFORCE} STREQUAL "MRAA_INTEL_GALILEO_GEN2")
39     set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/intel_galileo_rev_g.c)
40   elseif (${MRAAPLATFORMFORCE} STREQUAL "MRAA_INTEL_GALILEO_GEN1")
41     set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/intel_galileo_rev_d.c)
42   elseif (${MRAAPLATFORMFORCE} STREQUAL "MRAA_INTEL_DE3815")
43     set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/intel_de3815.c)
44   elseif (${MRAAPLATFORMFORCE} STREQUAL "MRAA_INTEL_EDISON_FAB_C")
45     set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/intel_edison_fab_c.c)
46   elseif (${MRAAPLATFORMFORCE} STREQUAL "MRAA_INTEL_MINNOWBOARD_MAX")
47     set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/intel_minnow_byt_compatible.c)
48   elseif (${MRAAPLATFORMFORCE} STREQUAL "MRAA_INTEL_NUC5")
49     set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/intel_nuc5.c)
50   elseif (${MRAAPLATFORMFORCE} STREQUAL "MRAA_INTEL_SOFIA_3GR")
51     set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/intel_sofia_3gr.c)
52   else ()
53     message (ERROR " - Unknown x86 platform enabled!")
54   endif ()
55 else ()
56     message (INFO " - Adding support for all platforms")
57 endif ()
58
59 set (mraa_LIB_ARM_SRCS_NOAUTO
60   ${PROJECT_SOURCE_DIR}/src/arm/arm.c
61   ${PROJECT_SOURCE_DIR}/src/arm/96boards.c
62   ${PROJECT_SOURCE_DIR}/src/arm/raspberry_pi.c
63   ${PROJECT_SOURCE_DIR}/src/arm/beaglebone.c
64   ${PROJECT_SOURCE_DIR}/src/arm/banana.c
65 )
66
67 set (mraa_LIBS ${CMAKE_THREAD_LIBS_INIT})
68
69 if (X86PLAT)
70   add_subdirectory(x86)
71   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DX86PLAT=1")
72 endif()
73
74 if (ARMPLAT)
75   add_subdirectory(arm)
76   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DARMPLAT=1")
77 endif()
78
79 if (USBPLAT)
80   message (INFO " - Adding USB platforms")
81   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSBPLAT=1")
82   if (FTDID2xx)
83     find_package (Ftd2xx)
84     if (${LIBFTD2XX_FOUND})
85       set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFTDID2XX=1")
86       set (mraa_LIBS ${mraa_LIBS} ${LIBFTD2XX_LIBRARIES})
87     else ()
88       message (WARNING " - Enabled FTDID2xx support but library not found")
89     endif ()
90   endif ()
91   if (FTDI4222)
92     find_package (Ftd4222)
93     if (${LIBFT4222_FOUND})
94       set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFTDI4222=1")
95       set (mraa_LIBS ${mraa_LIBS} ${LIBFT4222_LIBRARIES})
96     else ()
97       message (WARNING " - Enabled FTDI4222 support but library not found")
98     endif ()
99   endif ()
100   add_subdirectory(usb)
101 endif ()
102
103 set (mraa_LIB_SRCS
104   ${mraa_LIB_PLAT_SRCS_NOAUTO}
105 # autogenerated version file
106   ${CMAKE_CURRENT_BINARY_DIR}/version.c
107 )
108
109 set (mraa_LIB_GLOB_HEADERS
110   ${PROJECT_SOURCE_DIR}/api/mraa.h
111   ${PROJECT_SOURCE_DIR}/api/mraa.hpp
112 )
113
114 add_library (mraa SHARED ${mraa_LIB_SRCS})
115
116
117 target_link_libraries (mraa ${mraa_LIBS})
118
119 set_target_properties(
120    mraa
121    PROPERTIES
122    SOVERSION ${mraa_VERSION_MAJOR}
123    VERSION ${mraa_VERSION_STRING}
124 )
125 install (FILES ${mraa_LIB_GLOB_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
126 install (DIRECTORY ${PROJECT_SOURCE_DIR}/api/mraa/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mraa)
127
128 macro (mraa_CREATE_INSTALL_PKGCONFIG generated_file install_location)
129   configure_file (${generated_file}.cmake ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} @ONLY)
130   install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} DESTINATION ${install_location})
131 endmacro (mraa_CREATE_INSTALL_PKGCONFIG)
132 mraa_create_install_pkgconfig (mraa.pc ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
133
134 install(TARGETS mraa DESTINATION ${CMAKE_INSTALL_LIBDIR})
135
136 if (DOXYGEN_FOUND)
137   set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
138   set (DOCCLASSES aio gpio i2c pwm spi uart)
139   # CPP class headers
140   foreach (_file ${DOCCLASSES})
141     add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}_class_doc.i
142       COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doxy2swig.py -n
143         ${CMAKE_BINARY_DIR}/xml/classmraa_1_1_${_file}.xml
144         ${CMAKE_CURRENT_BINARY_DIR}/${_file}_class_doc.i
145       DEPENDS ${CMAKE_BINARY_DIR}/xml/classmraa_1_1_${_file}.xml
146     )
147     add_custom_target (${_file}class_doc_i DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_file}_class_doc.i)
148     add_dependencies (${_file}class_doc_i doc)
149   endforeach ()
150   # C header files
151   set (DOCFILES common ${DOCCLASSES})
152   foreach (_file ${DOCFILES})
153     add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}_doc.i
154       COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doxy2swig.py -n
155         ${CMAKE_BINARY_DIR}/xml/${_file}_8h.xml
156         ${CMAKE_CURRENT_BINARY_DIR}/${_file}_doc.i
157       DEPENDS ${CMAKE_BINARY_DIR}/xml/${_file}_8h.xml
158     )
159     add_custom_target (${_file}doc_i DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_file}_doc.i)
160     add_dependencies (${_file}doc_i doc)
161   endforeach ()
162   # CPP common header
163   add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/common_hpp_doc.i
164     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doxy2swig.py -n
165       ${CMAKE_BINARY_DIR}/xml/common_8hpp.xml
166       ${CMAKE_CURRENT_BINARY_DIR}//common_hpp_doc.i
167     DEPENDS ${CMAKE_BINARY_DIR}/xml/common_8hpp.xml
168   )
169   add_custom_target (common_hpp_doc_i DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/common_hpp_doc.i)
170   add_dependencies (common_hpp_doc_i doc)
171 endif ()
172
173 if (BUILDSWIG)
174   find_package (SWIG)
175   if (SWIG_FOUND)
176     include (${SWIG_USE_FILE})
177     set_source_files_properties (mraa.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
178
179     if (BUILDSWIGPYTHON)
180       add_subdirectory (python)
181     endif ()
182     if (BUILDSWIGJAVA)
183       add_subdirectory (java)
184     endif ()
185     if (BUILDSWIGNODE)
186       if (SWIG_VERSION VERSION_GREATER 3.0.4)
187         add_subdirectory (javascript)
188       else ()
189         message ("WARN - SWIG is ${SWIG_VERSION}. Please upgrade to 3.0.5+ to build nodejs addon")
190       endif ()
191     endif ()
192   endif ()
193 endif ()