217b0f19979b5eb46aab4e6e3515eabc8b4ad2f8
[libam7xxx.git] / src / CMakeLists.txt
1 add_definitions("-D_BSD_SOURCE") # for htole32()
2 add_definitions("-D_POSIX_C_SOURCE=2") # for getopt()
3
4 # Find packages needed to build library
5 find_package(libusb-1.0 REQUIRED)
6 include_directories(${LIBUSB_1_INCLUDE_DIRS})
7
8 set(SRC am7xxx.c serialize.c)
9
10 # Build the library
11 add_library(am7xxx SHARED ${SRC})
12 set_target_properties(am7xxx PROPERTIES
13   VERSION ${PROJECT_VER}
14   SOVERSION ${PROJECT_APIVER})
15 install(TARGETS am7xxx
16   DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")
17
18 add_library(am7xxx-static STATIC ${SRC})
19 set_target_properties(am7xxx-static PROPERTIES OUTPUT_NAME am7xxx)
20 if(UNIX AND NOT APPLE)
21   set_target_properties(am7xxx-static PROPERTIES COMPILE_FLAGS "-fPIC")
22 endif()
23 install(TARGETS am7xxx-static
24    DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")
25
26 target_link_libraries(am7xxx ${LIBUSB_1_LIBRARIES})
27 target_link_libraries(am7xxx-static ${LIBUSB_1_LIBRARIES})
28
29 # Install the header files
30 install(FILES "am7xxx.h"
31   DESTINATION "${CMAKE_INSTALL_PREFIX}/include")
32
33 if(UNIX AND NOT APPLE)
34   # Produce a pkg-config file for linking against the shared lib
35   configure_file("libam7xxx.pc.in" "libam7xxx.pc" @ONLY)
36   install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libam7xxx.pc"
37     DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
38 endif()
39
40 # Build the test app
41 add_executable(picoproj picoproj.c)
42 target_link_libraries(picoproj am7xxx)
43 install(TARGETS picoproj
44   DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")