This repository was archived by the owner on Feb 11, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
98 lines (81 loc) · 3.06 KB
/
Copy pathCMakeLists.txt
File metadata and controls
98 lines (81 loc) · 3.06 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
cmake_minimum_required(VERSION 3.16)
project("5_series_threading_example_cpp"
VERSION "1.0.0"
DESCRIPTION "Simple example for threading a 5-Series MIP device to acquire data using C++"
LANGUAGES C CXX
)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# TODO: Set MIP_SDK_ROOT_DIR if building as a standalone project
if(DEFINED MIP_SDK_ROOT_DIR OR DEFINED CACHE{MIP_SDK_ROOT_DIR})
set(_MIP_SDK_ROOT_DIR "${MIP_SDK_ROOT_DIR}")
elseif(DEFINED ENV{MIP_SDK_ROOT_DIR})
set(_MIP_SDK_ROOT_DIR "$ENV{MIP_SDK_ROOT_DIR}")
else()
set(_MIP_SDK_ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}")
endif()
# We need to find MicroStrain and MIP SDK in a standalone project
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_LIST_DIR})
list(APPEND CMAKE_PREFIX_PATH "${_MIP_SDK_ROOT_DIR}")
find_package(mip REQUIRED CONFIG)
# This example uses a serial connection and requires the microstrain_serial component
find_package(microstrain REQUIRED COMPONENTS microstrain_serial CONFIG)
elseif(NOT MICROSTRAIN_ENABLE_SERIAL)
# microstrain_serial library is needed for source built projects
message(FATAL_ERROR "The serial connections library is required for this example")
endif()
# Make sure the MIP libraries are found
if(NOT DEFINED CACHE{MIP_LIBRARIES} AND NOT DEFINED MIP_LIBRARIES)
message(FATAL_ERROR "Could not find the required MIP libraries.")
endif()
# Make sure the MicroStrain libraries are found
if(NOT DEFINED CACHE{MICROSTRAIN_LIBRARIES} AND NOT DEFINED MICROSTRAIN_LIBRARIES)
message(FATAL_ERROR "Could not find the required MicroStrain libraries.")
endif()
# Create the example
add_executable(${PROJECT_NAME}
"${CMAKE_CURRENT_LIST_DIR}/5_series_threading_example.cpp"
)
# Configure the project in a sub-folder for IDEs that support it
if(NOT ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_LIST_DIR})
file(RELATIVE_PATH PROJECT_RELATIVE_PATH "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_LIST_DIR}/..")
set_target_properties(${PROJECT_NAME} PROPERTIES
FOLDER "${PROJECT_RELATIVE_PATH}"
)
endif()
if(NOT MSVC)
find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE
"Threads::Threads"
)
endif()
target_link_libraries(${PROJECT_NAME} PRIVATE
${MIP_LIBRARIES}
${MICROSTRAIN_LIBRARIES}
)
target_include_directories(${PROJECT_NAME} PRIVATE
${MIP_INCLUDE_DIRS}
${MICROSTRAIN_INCLUDE_DIRS}
)
if(MSVC)
set(COMPILE_OPTIONS
"/W4" # Enable warnings
"/WX" # Warnings as errors
"/Zc:__cplusplus" # Enable updated __cplusplus value
"/MP" # Multi-process compilation
)
else()
set(COMPILE_OPTIONS
"-Wall" # Enable warnings
"-Wextra" # Enable extra warnings
"-Werror" # Warnings as errors
)
endif()
target_compile_options(${PROJECT_NAME} PRIVATE
"${COMPILE_OPTIONS}"
)
target_compile_definitions(${PROJECT_NAME} PRIVATE
"MICROSTRAIN_LOGGING_MAX_LEVEL=MICROSTRAIN_LOGGING_LEVEL_INFO_" # Info logging level is required at a minimum
)