python/CMakeLists.txt: rework Python development files detection
[libftdi] / src / CMakeLists.txt
CommitLineData
0b2d00fc 1# Includes
a4eac204 2include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}
019f4846 3 ${CMAKE_CURRENT_SOURCE_DIR}
7828006e 4)
0b2d00fc 5
0220adfa
TJ
6# Version information
7set(SNAPSHOT_VERSION "unknown")
8execute_process(COMMAND git describe
019f4846
TJ
9 OUTPUT_VARIABLE GIT_DESCRIBE_OUTPUT
10 RESULT_VARIABLE GIT_DESCRIBE_RESULT
11 OUTPUT_STRIP_TRAILING_WHITESPACE
7828006e 12)
019f4846
TJ
13if (${GIT_DESCRIBE_RESULT} STREQUAL 0)
14 set(SNAPSHOT_VERSION ${GIT_DESCRIBE_OUTPUT})
6d4f7fba 15endif ()
0220adfa
TJ
16message(STATUS "Detected git snapshot version: ${SNAPSHOT_VERSION}")
17
18configure_file(ftdi_version_i.h.in "${CMAKE_CURRENT_BINARY_DIR}/ftdi_version_i.h" @ONLY)
19
019f4846
TJ
20if (MSVC)
21 # Disable some overly-verbose warnings activated by -Wall
2e714eec 22
019f4846
TJ
23 # '<name>': function not inlined
24 add_compile_options(/wd4710)
2e714eec 25
019f4846
TJ
26 # function '<name>' selected for automatic inline expansion
27 add_compile_options(/wd4711)
2e714eec 28
019f4846
TJ
29 # Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified
30 add_compile_options(/wd5045)
2e714eec 31
019f4846
TJ
32 # '<type>': '4' bytes padding added after data member '<name>'
33 add_compile_options(/wd4820)
2e714eec 34
019f4846
TJ
35 # conversion from '<type1>' to '<type2>', possible loss of data
36 add_compile_options(/wd4242 /wd4244 /wd4267)
2e714eec 37
019f4846
TJ
38 # Disable warning on unsafe string functions
39 add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
2e714eec 40
019f4846
TJ
41 if (MSVC_VERSION GREATER_EQUAL 1913)
42 # Disable warnings from system headers
43 add_compile_options(/external:anglebrackets /external:W0)
44 endif ()
45endif ()
2e714eec 46
0b2d00fc 47# Targets
019f4846
TJ
48set(c_sources ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.c ${CMAKE_CURRENT_SOURCE_DIR}/ftdi_stream.c CACHE INTERNAL "List of c sources")
49set(c_headers ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.h CACHE INTERNAL "List of c headers")
0b2d00fc 50
2a992306 51# Shared library
019f4846
TJ
52if (SHAREDLIBS)
53 add_library(ftdi1 SHARED ${c_sources})
54 math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatibility with previous releases
55 set_target_properties(ftdi1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 2)
56 # Prevent clobbering each other during the build
57 set_target_properties(ftdi1 PROPERTIES CLEAN_DIRECT_OUTPUT 1)
58 target_link_libraries(ftdi1 ${LIBUSB_LIBRARIES})
59 install(TARGETS ftdi1
60 RUNTIME DESTINATION bin
61 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
62 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
63 )
64endif ()
6d4f7fba 65
2a992306 66# Static library
019f4846
TJ
67if (STATICLIBS)
68 add_library(ftdi1-static STATIC ${c_sources})
69 target_link_libraries(ftdi1-static ${LIBUSB_LIBRARIES})
70 set_target_properties(ftdi1-static PROPERTIES OUTPUT_NAME "ftdi1")
71 set_target_properties(ftdi1-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
72 install(TARGETS ftdi1-static
73 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
74 COMPONENT staticlibs
75 )
76endif ()
6d4f7fba 77
2a992306
YY
78install(FILES ${c_headers}
79 DESTINATION include/${PROJECT_NAME}
80 COMPONENT headers
7828006e 81)