-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
159 lines (131 loc) · 5.8 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
cmake_minimum_required(VERSION 3.11)
project(commlite LANGUAGES CXX)
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
option(COMMLITE_EXE_STATIC "Build static commlite" OFF)
# https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html
message(STATUS "CommLite CMake Info")
message(STATUS "=======================================================")
message(STATUS " Host Operation System : ${CMAKE_HOST_SYSTEM}")
message(STATUS " Host CPU Architecture : ${CMAKE_HOST_SYSTEM_PROCESSOR}")
message(STATUS " Target Operation System : ${CMAKE_SYSTEM}")
message(STATUS " Target CPU Architecture : ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS " Build Type : ${CMAKE_BUILD_TYPE}${CMAKE_CONFIGURATION_TYPES}")
message(STATUS " EXE Static : ${COMMLITE_EXE_STATIC}")
message(STATUS "=======================================================")
if (COMMLITE_EXE_STATIC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")
endif ()
include(FetchContent)
set(FETCHCONTENT_QUIET OFF CACHE INTERNAL "" FORCE)
FetchContent_Declare( # cmake 3.11 above
CSerialPort
GIT_REPOSITORY https://gitee.com/itas109/CSerialPort
GIT_TAG v4.1.1 # 2021-09-03
USES_TERMINAL_DOWNLOAD TRUE
)
#FetchContent_MakeAvailable(CSerialPort) # cmake 3.14 above
# FetchContent_MakeAvailable
#message(STATUS "CSerialPort_SOURCE_DIR : ${CSerialPort_SOURCE_DIR}")
#message(STATUS "CSerialPort_BINARY_DIR : ${CSerialPort_BINARY_DIR}")
# only download CSerialPort
# Check if population has already been performed
FetchContent_GetProperties(CSerialPort)
if(NOT cserialport_POPULATED)
# Fetch the content using previously declared details
FetchContent_Populate(CSerialPort)
endif()
# FetchContent_GetProperties and FetchContent_Populate
message(STATUS "CSerialPort_SOURCE_DIR : ${cserialport_SOURCE_DIR}")
message(STATUS "CSerialPort_BINARY_DIR : ${cserialport_BINARY_DIR}")
IF (WIN32)
FetchContent_Declare( # cmake 3.11 above
ncurses
GIT_REPOSITORY https://gitee.com/itas109/PDCurses
GIT_TAG 3.9 # 2019-09-05
USES_TERMINAL_DOWNLOAD TRUE
)
FetchContent_GetProperties(ncurses)
if(NOT ncurses_POPULATED)
# Fetch the content using previously declared details
FetchContent_Populate(ncurses)
endif()
add_custom_target(compile_ncurses
COMMAND mingw32-make -f Makefile WIDE=Y
COMMAND ${CMAKE_COMMAND} -E copy ${ncurses_SOURCE_DIR}/curses.h ${ncurses_BINARY_DIR}/include/curses.h
COMMAND ${CMAKE_COMMAND} -E copy ${ncurses_SOURCE_DIR}/wincon/pdcurses.a ${ncurses_BINARY_DIR}/lib/libpdcurses.a
COMMENT "compile and install pdcurses"
WORKING_DIRECTORY ${ncurses_SOURCE_DIR}/wincon
)
elseif(UNIX)
FetchContent_Declare( # cmake 3.11 above
ncurses
GIT_REPOSITORY https://gitee.com/itas109/ncurses
GIT_TAG v6.2 # 2020-02-12
USES_TERMINAL_DOWNLOAD TRUE
)
FetchContent_GetProperties(ncurses)
if(NOT ncurses_POPULATED)
# Fetch the content using previously declared details
FetchContent_Populate(ncurses)
endif()
# https://cmake.org/cmake/help/latest/variable/CMAKE_CROSSCOMPILING.html
if(CMAKE_CROSSCOMPILING)
# cpu arch
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm")
set(ncurses_host_option "--host=arm-linux-gnueabi")
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
set(ncurses_host_option "--host=aarch64-linux-gnu")
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "mips64el")
set(ncurses_host_option "--host=mips64el-linux-gnuabi64")
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "sw_64")
set(ncurses_host_option "--host=alpha-linux-gnu")
else()
set(ncurses_host_option "")
endif()
else()
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "sw_64")
set(ncurses_host_option "--build=alpha-linux-gnu")
else()
set(ncurses_host_option "")
endif()
endif()
add_custom_target(compile_ncurses
COMMAND ./configure --prefix=${ncurses_BINARY_DIR} ${ncurses_host_option} --enable-widec --with-terminfo-dirs="/etc/terminfo:/lib/terminfo:/usr/share/terminfo" CPPFLAGS="-P" --without-manpages --without-ada --disable-stripping --without-tack --without-tests
COMMAND make -j8
COMMAND make install
COMMENT "configure, compile and install ncurses"
WORKING_DIRECTORY ${ncurses_SOURCE_DIR}
)
ENDIF ()
if(APPLE)
find_library(IOKIT_LIBRARY IOKit)
find_library(FOUNDATION_LIBRARY Foundation)
endif()
include_directories(src) # tui.h
include_directories(${cserialport_SOURCE_DIR}/include) # CSerialPort headers
include_directories(${ncurses_BINARY_DIR}/include)
include_directories(${ncurses_BINARY_DIR}/include/ncursesw)# tui.h
link_directories(${ncurses_BINARY_DIR}/lib)
file(GLOB_RECURSE COMMON_SOURCES ${cserialport_SOURCE_DIR}/src/SerialPort.cpp ${cserialport_SOURCE_DIR}/src/SerialPortBase.cpp ${cserialport_SOURCE_DIR}/src/SerialPortInfo.cpp ${cserialport_SOURCE_DIR}/src/SerialPortInfoBase.cpp)
IF (WIN32)
file(GLOB_RECURSE OS_ABOUT_SOURCES ${cserialport_SOURCE_DIR}/src/SerialPortInfoWinBase.cpp ${cserialport_SOURCE_DIR}/src/SerialPortWinBase.cpp)
ELSEIF (UNIX)
file(GLOB_RECURSE OS_ABOUT_SOURCES ${cserialport_SOURCE_DIR}/src/SerialPortInfoUnixBase.cpp ${cserialport_SOURCE_DIR}/src/SerialPortUnixBase.cpp)
ENDIF ()
add_executable( ${PROJECT_NAME} src/CommLite.cpp src/tui.cpp ${COMMON_SOURCES} ${OS_ABOUT_SOURCES})
add_dependencies(${PROJECT_NAME} compile_ncurses)
IF (WIN32)
# for function availableFriendlyPorts
# PDCurses-3.9\wincon : make -f Makefile WIDE=Y
target_link_libraries( ${PROJECT_NAME} setupapi pdcurses libgcc.a libstdc++.a libpthread.a)
# target_link_libraries( ${PROJECT_NAME} setupapi pdcurses)
elseif(APPLE)
target_link_libraries( ${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY} ncursesw)
elseif(UNIX)
target_link_libraries( ${PROJECT_NAME} pthread ncursesw)
ENDIF ()
# package
include(cmake/commliteCPack.cmake)