explicit fs tests, no c++ separate test

This commit is contained in:
qPCR4vir 2019-12-08 18:32:47 +01:00
parent 538c91ebcf
commit f0fa70d51c
2 changed files with 93 additions and 63 deletions

View File

@ -32,6 +32,7 @@ project(nana VERSION 1.7.2
add_library(nana) add_library(nana)
add_library(nana::nana ALIAS nana) add_library(nana::nana ALIAS nana)
target_compile_features(nana PUBLIC cxx_std_17) target_compile_features(nana PUBLIC cxx_std_17)
# set(CMAKE_CXX_STANDARD 17)
# need after cxx_std_14 or cxx_std_17 ?? # need after cxx_std_14 or cxx_std_17 ??
target_compile_features(nana target_compile_features(nana

View File

@ -55,8 +55,6 @@ else()
endif() endif()
check_include_file_cxx (filesystem NANA_HAVE_FILESYSTEM) check_include_file_cxx (filesystem NANA_HAVE_FILESYSTEM)
check_include_file_cxx (experimental/filesystem NANA_HAVE_EXP_FILESYSTEM)
if (NANA_HAVE_FILESYSTEM) if (NANA_HAVE_FILESYSTEM)
message (STATUS "C++ Filesystem header: <filesystem>") message (STATUS "C++ Filesystem header: <filesystem>")
set (TEST_FS_LIB ON) set (TEST_FS_LIB ON)
@ -67,21 +65,24 @@ else()
std::filesystem::path p{\"\tmp/\"}; std::filesystem::path p{\"\tmp/\"};
throw std::filesystem::filesystem_error(\"Empty file name!\", std::make_error_code(std::errc::invalid_argument)); throw std::filesystem::filesystem_error(\"Empty file name!\", std::make_error_code(std::errc::invalid_argument));
}") }")
elseif (NANA_HAVE_EXP_FILESYSTEM) else()
message (STATUS "C++ Filesystem header: <experimental/filesystem>") check_include_file_cxx (experimental/filesystem NANA_HAVE_EXP_FILESYSTEM)
set (TEST_FS_LIB ON) if (NANA_HAVE_EXP_FILESYSTEM)
set (CXXSTD_FS_TEST_SOURCE message (STATUS "C++ Filesystem header: <experimental/filesystem>")
"#include <experimental/filesystem> set (TEST_FS_LIB ON)
int main() set (CXXSTD_FS_TEST_SOURCE
{ "#include <experimental/filesystem>
std::experimental::filesystem::path p{\"/tmp/\"}; int main()
throw std::experimental::filesystem::filesystem_error(\"Empty file name!\", std::make_error_code(std::errc::invalid_argument)); {
}") std::experimental::filesystem::path p{\"/tmp/\"};
else () throw std::experimental::filesystem::filesystem_error(\"Empty file name!\", std::make_error_code(std::errc::invalid_argument));
message (WARNING "No std::filesystem include file found: nana::filesystem will be used. }")
Set NANA_CMAKE_NANA_FILESYSTEM_FORCE to ON to avoid this warning.") else ()
target_compile_definitions(nana PUBLIC STD_FILESYSTEM_NOT_SUPPORTED) message (WARNING "No std::filesystem include file found: nana::filesystem will be used.
set (TEST_FS_LIB OFF) Set NANA_CMAKE_NANA_FILESYSTEM_FORCE to ON to avoid this warning.")
target_compile_definitions(nana PUBLIC STD_FILESYSTEM_NOT_SUPPORTED)
set (TEST_FS_LIB OFF)
endif ()
endif () endif ()
if (TEST_FS_LIB) if (TEST_FS_LIB)
@ -94,56 +95,84 @@ else()
set (CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH}) set (CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH})
set (CMAKE_REQUIRED_FLAGS ${CMAKE_CXX_FLAGS}) set (CMAKE_REQUIRED_FLAGS ${CMAKE_CXX_FLAGS})
set (CMAKE_REQUIRED_FLAGS_ORIGINAL ${CMAKE_REQUIRED_FLAGS}) set (CMAKE_REQUIRED_FLAGS_ORIGINAL ${CMAKE_REQUIRED_FLAGS})
set (CXXSTD_TEST_SOURCE
"#if !defined (__cplusplus) || (__cplusplus < 201703L)
#error NOCXX17
#endif
int main() {}")
check_cxx_source_compiles ("${CXXSTD_TEST_SOURCE}" CXX17_BUILTIN)
if (CXX17_BUILTIN)
message (STATUS "C++ Standard-17 support: builtin")
else ()
set (CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS_ORIGINAL} -std=c++17")
check_cxx_source_compiles ("${CXXSTD_TEST_SOURCE}" CXX17_FLAG)
if (CXX17_FLAG)
message (STATUS "C++ Standard-17 support: via -std=c++17")
else ()
message (WARNING "nana requires C++17??, but your compiler does not support it.")
endif ()
endif ()
set (CMAKE_REQUIRED_LIBRARIES_ORIGINAL ${CMAKE_REQUIRED_LIBRARIES}) set (CMAKE_REQUIRED_LIBRARIES_ORIGINAL ${CMAKE_REQUIRED_LIBRARIES})
check_cxx_source_compiles ("${CXXSTD_TEST_SOURCE}" C++17FS_FLAG)
if (C++17FS_FLAG) # c++: builtin
set (CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS_ORIGINAL}")
set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_ORIGINAL})
check_cxx_source_compiles ("${CXXSTD_FS_TEST_SOURCE}" CXXBuiltIn_FS_BuiltIn)
if (CXXBuiltIn_FS_BuiltIn)
message (STATUS "C++ Filesystem library: builtin") message (STATUS "C++ Filesystem library: builtin")
else () else()
set (C++17FS_LIB "") set (CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES_ORIGINAL} stdc++fs")
foreach (_LIB stdc++fs) check_cxx_source_compiles ("${CXXSTD_FS_TEST_SOURCE}" CXXBuiltIn_FS_stdcppfs)
set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_ORIGINAL} ${_LIB}) if (CXXBuiltIn_FS_stdcppfs)
check_cxx_source_compiles ("${CXXSTD_FS_TEST_SOURCE}" C++17FS_LIB-l${_LIB}) message (STATUS "C++ Filesystem library: stdc++fs")
message (STATUS "C++ Filesystem library: testing -l${_LIB}") target_link_libraries (nana PUBLIC stdc++fs)
if (C++17FS_LIB-l${_LIB}) else()
target_link_libraries (nana PUBLIC ${_LIB}) set (CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES_ORIGINAL} c++fs")
message (STATUS "C++ Filesystem library: via -l${_LIB}") check_cxx_source_compiles ("${CXXSTD_FS_TEST_SOURCE}" CXXBuiltIn_FS_cppfs)
set (C++17FS_LIB ${_LIB}) if (CXXBuiltIn_FS_cppfs)
break () message (STATUS "C++ Filesystem library: c++fs")
endif () target_link_libraries (nana PUBLIC c++fs)
set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_ORIGINAL}) else()
endforeach ()
if (C++17FS_LIB) # c++: -std=c++17
message (STATUS "C++ Filesystem library: via -l${C++17FS_LIB}") set (CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS_ORIGINAL} -std=c++17")
else () set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_ORIGINAL})
message (WARNING "No std::filesystem library found: nana::filesystem will be used. check_cxx_source_compiles ("${CXXSTD_FS_TEST_SOURCE}" CXX_std__cpp17_FS_BuiltIn)
Set NANA_CMAKE_NANA_FILESYSTEM_FORCE to ON to avoid this warning.") if (CXX_std__cpp17_FS_BuiltIn)
target_compile_definitions(nana PUBLIC STD_FILESYSTEM_NOT_SUPPORTED) message (STATUS "C++: -std=c++17; Filesystem library: builtin")
endif () else()
set (CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES_ORIGINAL} stdc++fs")
check_cxx_source_compiles ("${CXXSTD_FS_TEST_SOURCE}" CXX_std__cpp17_FS_stdcppfs)
if (CXX_std__cpp17_FS_stdcppfs)
message (STATUS "C++: -std=c++17; Filesystem library: stdc++fs")
target_link_libraries (nana PUBLIC stdc++fs)
else()
set (CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES_ORIGINAL} c++fs")
check_cxx_source_compiles ("${CXXSTD_FS_TEST_SOURCE}" CXX_std__cpp17_FS_cppfs)
if (CXX_std__cpp17_FS_cppfs)
message (STATUS "C++: -std=c++17; Filesystem library: c++fs")
target_link_libraries (nana PUBLIC c++fs)
else()
# c++: /std:c++17
set (CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS_ORIGINAL} /std:c++17")
set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_ORIGINAL})
check_cxx_source_compiles ("${CXXSTD_FS_TEST_SOURCE}" CXX_std_cpp17_FS_BuiltIn)
if (CXX_std_cpp17_FS_BuiltIn)
message (STATUS "C++: /std:c++17; Filesystem library: builtin")
else()
set (CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES_ORIGINAL} stdc++fs")
check_cxx_source_compiles ("${CXXSTD_FS_TEST_SOURCE}" CXX_std_cpp17_FS_stdcppfs)
if (CXX_std_cpp17_FS_stdcppfs)
message (STATUS "C++: /std:c++17; Filesystem library: stdc++fs")
target_link_libraries (nana PUBLIC stdc++fs)
else()
set (CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES_ORIGINAL} c++fs")
check_cxx_source_compiles ("${CXXSTD_FS_TEST_SOURCE}" CXX_std_cpp17_FS_cppfs)
if (CXX_std_cpp17_FS_cppfs)
message (STATUS "C++: /std:c++17; Filesystem library: c++fs")
target_link_libraries (nana PUBLIC c++fs)
else ()
message (WARNING "No std::filesystem library found: nana::filesystem will be used.
Set NANA_CMAKE_NANA_FILESYSTEM_FORCE to ON to avoid this warning.")
target_compile_definitions(nana PUBLIC STD_FILESYSTEM_NOT_SUPPORTED)
set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_ORIGINAL})
endif () endif ()
endif () endif ()
endif() endif ()
endif ()
endif ()
endif ()
endif ()
endif ()
endif ()
endif (TEST_FS_LIB)
endif ()