-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
109 lines (98 loc) · 3.92 KB
/
Copy pathCMakeLists.txt
File metadata and controls
109 lines (98 loc) · 3.92 KB
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
cmake_minimum_required(VERSION 3.15)
project(serial_module_project)
# === Sources ===
set(SOURCE_LIB_MODULE_FILES src/serialmodule.c)
set(SOURCE_TEST_MODULE_FILES tests/console/main.c)
set(SOURCE_MFC_MODULE_FILES
tests/testMFC/testSerialPort/testSerialPort/framework.h
tests/testMFC/testSerialPort/testSerialPort/pch.cpp
tests/testMFC/testSerialPort/testSerialPort/pch.h
tests/testMFC/testSerialPort/testSerialPort/resource.h
tests/testMFC/testSerialPort/testSerialPort/targetver.h
tests/testMFC/testSerialPort/testSerialPort/testSerialPort.cpp
tests/testMFC/testSerialPort/testSerialPort/testSerialPort.h
tests/testMFC/testSerialPort/testSerialPort/testSerialPort.rc
tests/testMFC/testSerialPort/testSerialPort/testSerialPortDlg.cpp
tests/testMFC/testSerialPort/testSerialPort/testSerialPortDlg.h
tests/testMFC/testSerialPort/testSerialPort/res/testSerialPort.ico
tests/testMFC/testSerialPort/testSerialPort/res/testSerialPort.rc2
)
# === Include main headers ===
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
# === Define shared library ===
add_library(serialmodule SHARED ${SOURCE_LIB_MODULE_FILES})
# === Platform-specific defines ===
if(DEFINED UNIX_LINUX)
target_compile_definitions(serialmodule PUBLIC UNIX_LINUX=1)
if(DEFINED MACOSX)
target_compile_definitions(serialmodule PUBLIC __MACH__=1)
else()
target_compile_definitions(serialmodule PUBLIC __SPSR_EPOLL__=1)
endif()
set_target_properties(serialmodule PROPERTIES VERSION 1.0.8 SOVERSION 1)
else()
target_compile_definitions(serialmodule PUBLIC EXPORT_DLL_API_SERIAL_MODULE=1)
target_compile_definitions(serialmodule PUBLIC _CRT_SECURE_NO_WARNINGS=1)
endif()
# === Link SimpleLog if not in embedded environment ===
if(NOT DEFINED META_OPENEMBEDDED)
if(DEFINED HEADER_SIMPLELOG)
message(STATUS "Using SimpleLog header at: ${HEADER_SIMPLELOG}")
target_include_directories(serialmodule PUBLIC "${HEADER_SIMPLELOG}")
else()
message(FATAL_ERROR
"\n[SimpleLog Missing]\n"
"HEADER_SIMPLELOG is not defined.\n"
"Please install SimpleLog-Topic from: https://github.com/thuanalg/simplelog-topic\n"
"Then pass the header path using:\n"
" -DHEADER_SIMPLELOG=/path/to/simplelog/include"
)
endif()
if(DEFINED LIB_PATH_SIMPLELOG)
message(STATUS "Using SimpleLog library path: ${LIB_PATH_SIMPLELOG}")
target_link_directories(serialmodule PUBLIC "${LIB_PATH_SIMPLELOG}")
else()
message(FATAL_ERROR
"\n[SimpleLog Missing]\n"
"LIB_PATH_SIMPLELOG is not defined.\n"
"Please install SimpleLog-Topic from: https://github.com/thuanalg/simplelog-topic\n"
"Then pass the library path using:\n"
" -DLIB_PATH_SIMPLELOG=/path/to/simplelog/lib"
)
endif()
endif()
# === Executable: test_serial_module (pure C) ===
add_executable(test_serial_module ${SOURCE_TEST_MODULE_FILES})
if(DEFINED UNIX_LINUX)
target_compile_definitions(test_serial_module PUBLIC UNIX_LINUX=1)
else()
target_compile_definitions(test_serial_module PUBLIC _CRT_SECURE_NO_WARNINGS=1 )
endif()
target_link_libraries(test_serial_module
simplelog
serialmodule
)
# === Visual Studio only: include existing .vcxproj ===
if(MSVC)
add_executable(testMFCSerialPort WIN32 ${SOURCE_MFC_MODULE_FILES})
target_compile_definitions(testMFCSerialPort PUBLIC _CRT_SECURE_NO_WARNINGS=1 _AFXDLL=1)
target_link_libraries(testMFCSerialPort
simplelog
serialmodule
)
# Enable MFC
set_target_properties(testMFCSerialPort PROPERTIES
USES_MFC 2
)
endif()
# === Installation section for Unix/Linux ===
if(DEFINED UNIX_LINUX)
install(TARGETS serialmodule LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS test_serial_module RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES include/serialmodule.h DESTINATION include)
endif()
# === Link for serialmodule ===
target_link_libraries(serialmodule
simplelog
)
##cmake .. -DUNIX_LINUX=1 -DHEADER_SIMPLELOG=/usr/local/include -DLIB_PATH_SIMPLELOG=/usr/local/lib -DHEADER_SERIALMODULE=/usr/local/include -DLIB_PATH_SERIALMODULE=/usr/local/lib