-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
165 lines (165 loc) · 6.7 KB
/
Copy pathCMakeLists.txt
File metadata and controls
165 lines (165 loc) · 6.7 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
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
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_BINARY_DIR})
get_cmake_property(pros VARIABLES)
# xp_ variables from pros.cmake, included by xproinc.cmake
list(FILTER pros INCLUDE REGEX "^xp_")
list(SORT pros)
list(REMOVE_ITEM pros xp_googletest)
list(PREPEND pros xp_googletest) # make googletest first
list(REMOVE_ITEM pros xp_azmq) # TODO: azmq has issues with boost 1.91.0
find_program(XVFB_RUN_EXEC xvfb-run)
if(XVFB_RUN_EXEC)
set(xvfb_cmd ${XVFB_RUN_EXEC})
endif()
# NOTE: set ${pro}_libs if ${PRJ}_LIBRARIES isn't sufficient
set(boost_libs Boost::filesystem Boost::program_options Boost::regex)
set(hdf5_libs xpro::hdf5_cpp-static)
set(libgeotiff_libs xpro::libgeotiff Boost::filesystem)
set(libgit2_libs xpro::git2 Boost::filesystem)
set(libiconv_libs xpro::libiconv)
set(libzmq_compile_features cxx_std_17)
set(nlohmann_json_compile_features cxx_std_17)
set(shapelib_libs shapelib Boost::filesystem)
set(spdlog_compile_features cxx_std_17)
set(wxWidgets_libs wx::base wx::core)
set(wxx_xvfb ${xvfb_cmd})
# Build lists of all files and subdirectories to track unprocessed items
file(GLOB all_cpp_files "*.cpp")
file(GLOB all_cmake_files "*.cmake")
file(GLOB all_subdirs LIST_DIRECTORIES true "*")
set(subdirs_with_cmake "")
foreach(dir ${all_subdirs})
if(IS_DIRECTORY "${dir}" AND EXISTS "${dir}/CMakeLists.txt")
list(APPEND subdirs_with_cmake "${dir}")
endif()
endforeach()
foreach(pro ${pros})
string(REGEX REPLACE "^xp_" "" pro ${pro})
find_package(${pro})
if(pro STREQUAL "ceres-solver" AND CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT DEFINED ENV{CI})
# local (non-CI) Linux builds can fail to link ceres-solver tests with:
# collect2: fatal error: ld terminated with signal 9 [Killed]
# compilation terminated.
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${pro}.cpp)
list(REMOVE_ITEM all_cpp_files "${CMAKE_CURRENT_SOURCE_DIR}/${pro}.cpp")
endif()
continue()
endif()
if(pro STREQUAL FFmpeg)
xpGetPkgVar(FFmpeg DLLS) # sets FFmpeg_DLLS
if(DEFINED FFmpeg_DLLS)
set(FFmpeg_postBuildCopy ${FFmpeg_DLLS})
endif()
endif()
if(pro STREQUAL geotranz)
xpGetPkgVar(geotranz DATA_DIR) # sets GEOTRANZ_DATA_DIR
set(geotranz_compile_definitions "GEOTRANS_DATA=\"${GEOTRANZ_DATA_DIR}\"")
endif()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${pro}.cpp)
add_executable(${pro}_test "${pro}.cpp")
list(APPEND all_srcs "${pro}.cpp")
string(TOUPPER ${pro} PRJ)
if(DEFINED ${pro}_libs)
target_link_libraries(${pro}_test PRIVATE ${${pro}_libs} googletest)
list(APPEND all_libs ${${pro}_libs})
elseif(TARGET ${pro})
target_link_libraries(${pro}_test PRIVATE ${pro} googletest)
list(APPEND all_libs ${pro})
elseif(TARGET ${pro}::${pro})
target_link_libraries(${pro}_test PRIVATE ${pro}::${pro} googletest)
list(APPEND all_libs ${pro}::${pro})
elseif(DEFINED ${PRJ}_LIBRARIES)
target_link_libraries(${pro}_test PRIVATE ${${PRJ}_LIBRARIES} googletest)
list(APPEND all_libs ${${PRJ}_LIBRARIES})
endif()
if(DEFINED ${pro}_compile_features)
target_compile_features(${pro}_test PRIVATE ${${pro}_compile_features})
list(APPEND all_compile_features ${${pro}_compile_features})
endif()
if(DEFINED ${pro}_compile_definitions)
target_compile_definitions(${pro}_test PRIVATE ${${pro}_compile_definitions})
list(APPEND all_compile_definitions ${${pro}_compile_definitions})
endif()
if(pro STREQUAL "wxx" AND MSVC_VERSION VERSION_GREATER_EQUAL 1950)
message(STATUS "Skipping wxx_test on VS2026 (MSVC_VERSION 1950) due to known hang issue")
elseif(pro STREQUAL "wxx" AND XVFB_RUN_EXEC)
add_test(NAME ${pro}_test COMMAND ${XVFB_RUN_EXEC} -a
--server-args=-screen\ 0\ 1920x1080x24\ -nolisten\ tcp
$<TARGET_FILE:${pro}_test>
)
set_tests_properties(${pro}_test PROPERTIES
ENVIRONMENT "GDK_BACKEND=x11;GTK_A11Y=none;NO_AT_BRIDGE=1;LIBGL_ALWAYS_SOFTWARE=1"
)
else()
add_test(NAME ${pro}_test COMMAND ${${pro}_xvfb} $<TARGET_FILE:${pro}_test>)
endif()
if(DEFINED ${pro}_postBuildCopy)
xpPostBuildCopy(${pro}_test "${${pro}_postBuildCopy}" .)
endif()
# Remove processed .cpp file from tracking list
list(REMOVE_ITEM all_cpp_files "${CMAKE_CURRENT_SOURCE_DIR}/${pro}.cpp")
endif()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${pro}.cmake)
xpGetPkgVar(${pro} VER)
xpGetPkgVar(${pro} EXE)
if(TARGET ${${pro}_EXE})
set(${pro}_EXE_PATH $<TARGET_FILE:${${pro}_EXE}>)
elseif(pro STREQUAL "protobuf")
xpGetPkgVar(${pro} PROTOC_EXECUTABLE)
if(TARGET ${${pro}_PROTOC_EXECUTABLE})
set(${pro}_EXE_PATH $<TARGET_FILE:${${pro}_PROTOC_EXECUTABLE}>)
endif()
else()
set(${pro}_EXE_PATH ${${pro}_EXE})
endif()
add_test(NAME ${pro}_exe_test COMMAND ${CMAKE_COMMAND}
-D${pro}_VER='${${pro}_VER}' -D${pro}_EXE='${${pro}_EXE_PATH}'
-P ${CMAKE_CURRENT_SOURCE_DIR}/${pro}.cmake
)
# Remove processed .cmake file from tracking list
list(REMOVE_ITEM all_cmake_files "${CMAKE_CURRENT_SOURCE_DIR}/${pro}.cmake")
endif()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${pro}/CMakeLists.txt)
add_subdirectory(${pro})
# Remove processed subdirectory from tracking list
list(REMOVE_ITEM subdirs_with_cmake "${CMAKE_CURRENT_SOURCE_DIR}/${pro}")
endif()
endforeach()
# Report unprocessed items (potential orphans)
set(unprocessed_report "")
if(all_cpp_files)
list(JOIN all_cpp_files "\n " cpp_report)
string(APPEND unprocessed_report "Unprocessed .cpp files:\n ${cpp_report}\n")
endif()
if(all_cmake_files)
list(JOIN all_cmake_files "\n " cmake_report)
string(APPEND unprocessed_report "Unprocessed .cmake files:\n ${cmake_report}\n")
endif()
if(subdirs_with_cmake)
list(JOIN subdirs_with_cmake "\n " subdir_report)
string(APPEND unprocessed_report "Unprocessed subdirectories with CMakeLists.txt:\n ${subdir_report}\n")
endif()
if(unprocessed_report)
message(STATUS "=== UNPROCESSED FILES/DIRECTORIES DETECTED ===")
message(STATUS "${unprocessed_report}")
message(STATUS "These may be orphaned files or case mismatches")
endif()
list(REMOVE_DUPLICATES all_libs)
list(REMOVE_DUPLICATES all_compile_features)
list(REMOVE_DUPLICATES all_compile_definitions)
# TRICKY: libsodium includes argon2, so we need to remove it
# from the lists to avoid duplicate symbols at link-time
list(REMOVE_ITEM all_srcs argon2.cpp)
list(REMOVE_ITEM all_libs argon2)
if(all_srcs)
add_executable(toda ${all_srcs})
if(all_libs)
target_link_libraries(toda PRIVATE ${all_libs})
endif()
if(all_compile_features)
target_compile_features(toda PRIVATE ${all_compile_features})
endif()
if(all_compile_definitions)
target_compile_definitions(toda PRIVATE ${all_compile_definitions})
endif()
endif()
xpSourceListAppend()