NEWS: Release version 0.1.7
[libam7xxx.git] / src / CMakeLists.txt
1 add_definitions("-D_DEFAULT_SOURCE") # for htole32()
2 add_definitions("-D_POSIX_C_SOURCE=200112L") # for nanosleep() and lroundf()
3
4 # Express a preference for C99 format strings when using MinGW, see:
5 # https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/
6 add_definitions("-D__USE_MINGW_ANSI_STDIO=1")
7
8 # Find packages needed to build library
9 find_package(libusb-1.0 REQUIRED)
10 include_directories(${LIBUSB_1_INCLUDE_DIRS})
11
12 set(SRC am7xxx.c serialize.c tools.c)
13
14 # Build the library
15 add_library(am7xxx SHARED ${SRC})
16 set_target_properties(am7xxx PROPERTIES
17   VERSION ${PROJECT_VER}
18   SOVERSION ${PROJECT_APIVER})
19 install(TARGETS am7xxx
20   DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")
21
22 add_library(am7xxx-static STATIC ${SRC})
23 set_target_properties(am7xxx-static PROPERTIES OUTPUT_NAME am7xxx)
24 if(UNIX AND NOT APPLE)
25   set_target_properties(am7xxx-static PROPERTIES COMPILE_FLAGS "-fPIC")
26 endif()
27 install(TARGETS am7xxx-static
28    DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")
29
30 if(NOT WIN32)
31   find_library(MATH_LIB m)
32 else()
33   # not needed on windows
34   set(MATH_LIB "")
35 endif()
36
37 target_link_libraries(am7xxx ${MATH_LIB} ${LIBUSB_1_LIBRARIES})
38 target_link_libraries(am7xxx-static ${MATH_LIB} ${LIBUSB_1_LIBRARIES})
39
40 # Install the header files
41 install(FILES "am7xxx.h"
42   DESTINATION "${CMAKE_INSTALL_PREFIX}/include")
43
44 if(UNIX AND NOT APPLE)
45   # Produce a pkg-config file for linking against the shared lib
46   configure_file("libam7xxx.pc.in" "libam7xxx.pc" @ONLY)
47   install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libam7xxx.pc"
48     DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
49 endif()