Skip to content

Commit f22c436

Browse files
committed
jdbc/test: Better detection whether stdc++fs is required
1 parent d4cb9ff commit f22c436

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

jdbc/test/CMakeLists.txt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,26 @@ INCLUDE_DIRECTORIES("${CMAKE_BINARY_DIR}/include/jdbc/cppconn")
4444
set(MY_TARGET_LINK_LIBRARIES connector-jdbc)
4545

4646

47-
if(DEFINED GCC AND GCC VERSION_LESS 9)
47+
# Note: Some unit tests use std::filesystem part of the standard C++ library
48+
# and for some versions of the standard library its implementation is in
49+
# additional library stdc++fs.
4850

49-
# Note: Some unit tests use std::filesystem part of the standard library
50-
# Before version 9 of gcc that requires linking with the additional library
51+
if(NOT WIN32)
5152

52-
list(APPEND MY_TARGET_LINK_LIBRARIES -lstdc++fs)
53-
# message(STATUS "Added libstdc++fs for GCC version ${GCC}: ${MY_TARGET_LINK_LIBRARIES}")
53+
set(check_src "${CMAKE_CURRENT_BINARY_DIR}/filesystem_chk.cc")
54+
file(WRITE "${check_src}"
55+
"#include <filesystem>\n"
56+
"int main() { (void)std::filesystem::current_path(); }"
57+
)
58+
59+
try_compile(COMPILE_RESULT
60+
${CMAKE_CURRENT_BINARY_DIR} "${check_src}"
61+
# OUTPUT_VARIABLE build_log
62+
)
63+
64+
if(NOT COMPILE_RESULT)
65+
list(APPEND MY_TARGET_LINK_LIBRARIES -lstdc++fs)
66+
endif()
5467

5568
endif()
5669

0 commit comments

Comments
 (0)