-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathCMakeLists.txt
174 lines (148 loc) · 6.58 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
cmake_minimum_required(VERSION 3.16)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
project(glscopeclient)
include(CTest)
# Configuration settings
set(BUILD_DOCS CACHE BOOL "Build the documentation")
set(ANALYZE CACHE BOOL "Run static analysis on the code, requires cppcheck and clang-analyzer to be installed")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) # error if compiler doesn't support c++17
set(CMAKE_CXX_EXTENSIONS OFF) # use c++17 instead of gnu++17
# Compiler flags
set(WARNINGS "-Wall -Wextra -Wuninitialized ")
set(WARNINGS "${WARNINGS} -Wshadow -Wpedantic -Wcast-align -Wwrite-strings")
set(WARNINGS "${WARNINGS} -Wmissing-declarations -Wvla")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(WARNINGS "${WARNINGS} ")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
set(WARNINGS "${WARNINGS} -Wno-gnu-zero-variadic-macro-arguments -Wno-unknown-warning-option")
endif()
set(CMAKE_CXX_FLAGS "-g ${WARNINGS} -mtune=native -fsigned-char")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif(NOT CMAKE_BUILD_TYPE)
if(SANITIZE)
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -fsanitize=address -D_DEBUG")
else()
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -D_DEBUG")
endif()
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_USE_MATH_DEFINES -D_POSIX_THREAD_SAFE_FUNCTIONS")
endif()
if(APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_APPLE_SILICON")
set(APPLE_SILICON TRUE)
endif()
# Package detection
find_package(PkgConfig)
pkg_check_modules(GTKMM REQUIRED gtkmm-3.0)
pkg_check_modules(SIGCXX REQUIRED sigc++-2.0)
if(NOT APPLE_SILICON)
find_package(FFTS)
endif()
include(FindOpenMP)
find_package(glfw3 3.2 REQUIRED)
# Use the local FindVulkan script until we can rely on all users having CMake 3.24 available, at which point we can remove it
set(Vulkan_FIND_COMPONENTS glslang shaderc_combined)
include(FindVulkan)
if(NOT Vulkan_FOUND)
message(FATAL_ERROR "No Vulkan SDK found.")
endif()
if(NOT Vulkan_glslc_FOUND)
message(FATAL_ERROR "No Vulkan glslc found. This is needed to compile shaders.")
endif()
# Add specific VulkanSDK Lib & Include for glslang (tested on Linux Ubuntu 22.04 LTS)
if(NOT WIN32)
include_directories($ENV{VULKAN_SDK}/include/glslang/Include)
link_directories($ENV{VULKAN_SDK}/lib)
endif()
# Includes are incomplete in VulkanSDK 1.3.224.1 so we use the include path from MINGW64 mingw-w64-x86_64-glslang
if(WIN32)
find_path(Glslang_BUILD_INCLUDE_DIR
NAMES include/glslang/Include/glslang_c_interface.h
HINTS
$ENV{GLSLANG_BUILD_PATH}
)
mark_as_advanced(Glslang_BUILD_INCLUDE_DIR)
if(Glslang_BUILD_INCLUDE_DIR)
include_directories($ENV{GLSLANG_BUILD_PATH}/include/glslang/Include)
else()
message(FATAL_ERROR "Glslang_BUILD_INCLUDE_DIR Not found")
endif()
link_directories($ENV{GLSLANG_BUILD_PATH}/lib)
link_directories($ENV{GLSLANG_BUILD_PATH}/lib/glslang)
endif()
if(NOT WIN32)
include(GNUInstallDirs)
endif()
# Configure and enable OpenMP
if(NOT OpenMP_CXX_FOUND)
message(FATAL_ERROR "glscopeclient requires OpenMP but your C++ compiler does not appear to support it.")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
# Documentation
if(BUILD_DOCS)
add_subdirectory("${PROJECT_SOURCE_DIR}/doc")
endif()
# Static analysis
if(ANALYZE)
find_program(CPPCHECK_PATH cppcheck DOC "Path to cppcheck when ANALYZE is enabled")
if(CPPCHECK_PATH)
execute_process(COMMAND ${CPPCHECK_PATH} "--version" OUTPUT_VARIABLE CPPCHECK_VER_STR ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE "Cppcheck " "" CPPCHECK_VERSION ${CPPCHECK_VER_STR})
if(CPPCHECK_VERSION VERSION_GREATER_EQUAL "2")
set(CMAKE_CXX_CPPCHECK "${CPPCHECK_PATH};-DFT_USE_AUTOCONF_SIZEOF_TYPES;-D__GNUC__;--enable=warning,performance,portability;--suppress=*:*sigc*;--suppress=*:*glibmm*;--suppress=*:*gtkmm*;--inline-suppr;-q;--std=c++11")
message(STATUS "Found CPPCheck: ${CPPCHECK_PATH} (found version \"${CPPCHECK_VERSION}\")")
else()
message(STATUS "Found CPPCheck: ${CPPCHECK_PATH} but ignored it as it was ${CPPCHECK_VERSION} < 2")
endif()
else()
message(STATUS "CPPCheck not found")
endif()
# The actual clang-analyzer compiler wrapper doesn't get installed on $PATH, only scan-build which is useless to us
find_program(CLANGANALYZER_SCANBUILD_PATH scan-build DOC "Path to clang-analyzer's scan-build tool, used as a hint to find the rest of the clang-analyzer")
get_filename_component(CLANGANALYZER_SCANBUILD_BIN ${CLANGANALYZER_SCANBUILD_PATH} REALPATH)
get_filename_component(CLANGANALYZER_BIN_PATH ${CLANGANALYZER_SCANBUILD_BIN} DIRECTORY)
find_program(CLANGANALYZER_CXXANALYZER_PATH "c++-analyzer" HINTS "${CLANGANALYZER_BIN_PATH}/../libexec" DOC "Path to clang-analyzer's c++-analyzer")
if(CLANGANALYZER_CXXANALYZER_PATH)
set(CMAKE_CXX_COMPILER_LAUNCHER "${CLANGANALYZER_CXXANALYZER_PATH}")
message(STATUS "Found clang-analyzer: ${CLANGANALYZER_CXXANALYZER_PATH}")
else()
message(STATUS "clang-analyzer not found")
endif()
endif()
# Main project code
add_subdirectory("${PROJECT_SOURCE_DIR}/lib/graphwidget")
add_subdirectory("${PROJECT_SOURCE_DIR}/lib/scopeexports")
add_subdirectory("${PROJECT_SOURCE_DIR}/lib/scopehal")
add_subdirectory("${PROJECT_SOURCE_DIR}/lib/scopeprotocols")
add_subdirectory("${PROJECT_SOURCE_DIR}/lib/xptools")
add_subdirectory("${PROJECT_SOURCE_DIR}/lib/log")
add_subdirectory("${PROJECT_SOURCE_DIR}/src/glscopeclient")
add_subdirectory("${PROJECT_SOURCE_DIR}/src/ngscopeclient")
add_subdirectory("${PROJECT_SOURCE_DIR}/src/nativefiledialog-extended")
# Unit tests
if(BUILD_TESTING)
find_package(Catch2 REQUIRED)
include(Catch)
#Catch2 v3.x.y have a breaking change:
# Must include catch2/catch_all.hpp instead of catch2/catch.hpp
# So we set a compile flag to let the code know.
if(NOT Catch2_VERSION MATCHES "^[0-2]\\.")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CATCH2_V3")
endif()
add_subdirectory("${PROJECT_SOURCE_DIR}/tests")
endif()
# Example code and other utilities, don't build on non-POSIX yet
if(NOT WIN32)
add_subdirectory("${PROJECT_SOURCE_DIR}/src/examples/curvetrace")
add_subdirectory("${PROJECT_SOURCE_DIR}/src/examples/scopevna")
#add_subdirectory("${PROJECT_SOURCE_DIR}/src/examples/usbcsv")
endif()
# Make sure all of our shared libraries are built relocatable
set_property(TARGET scopehal PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET log PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET xptools PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET scopeprotocols PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET scopeexports PROPERTY POSITION_INDEPENDENT_CODE ON)