From b1bdc747c42fad27911e39694f6208323f1e349a Mon Sep 17 00:00:00 2001 From: Martin Chang Date: Mon, 9 Aug 2021 22:37:23 +0800 Subject: [PATCH] Force using boost::filesystem when building for Android (#964) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: RafaƂ Bugajewski --- CMakeLists.txt | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0da378c0..821cf097 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,17 +129,16 @@ else (NOT WIN32) target_link_libraries(${PROJECT_NAME} PRIVATE shlwapi) endif (NOT WIN32) +set(NEED_BOOST_FS 0) if (DROGON_CXX_STANDARD EQUAL 14) # With C++14, use Boost to support any and string_view message(STATUS "use c++14") find_package(Boost 1.61.0 REQUIRED) - find_package(Boost 1.61.0 REQUIRED COMPONENTS filesystem) - message(STATUS "Using Boost filesytem, string_view and any") + message(STATUS "Using Boost filesystem, string_view and any") message(STATUS "Boost include dir: " ${Boost_INCLUDE_DIR}) target_link_libraries(${PROJECT_NAME} PUBLIC Boost::boost) - target_link_libraries(${PROJECT_NAME} PUBLIC Boost::filesystem) list(APPEND INCLUDE_DIRS_FOR_DYNAMIC_VIEW ${Boost_INCLUDE_DIR}) - option(HAS_STD_FILESYSTEM_PATH "use boost::filesystem" OFF) + set(NEED_BOOST_FS 1) elseif (DROGON_CXX_STANDARD EQUAL 17) # With C++17, use Boost if std::filesystem::path is missing message(STATUS "use c++17") @@ -149,27 +148,41 @@ elseif (DROGON_CXX_STANDARD EQUAL 17) ${PROJECT_SOURCE_DIR}/cmake/tests/check_has_std_filesystem_path.cc CXX_STANDARD 17) set(CMAKE_TRY_COMPILE_TARGET_TYPE) - if (check_filesystem_path) + # Workaround: 2021-08-09 Android NDK does not provide proper std::filesystem + # support. Force boost::filesystem instead. + if (check_filesystem_path AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Android") message(STATUS "Using c++17 filesytem::path") if (CMAKE_CXX_COMPILER_ID MATCHES GNU) target_link_libraries(${PROJECT_NAME} PUBLIC stdc++fs) endif() option(HAS_STD_FILESYSTEM_PATH "use std::filesystem" ON) else() - find_package(Boost 1.49.0 COMPONENTS filesystem system REQUIRED) - message(STATUS "Using Boost filesytem::path") - message(STATUS "Boost include dir: " ${Boost_INCLUDE_DIR}) - include_directories(${BOOST_INCLUDE_DIRS}) - message(STATUS "Boost libraries: " ${Boost_LIBRARIES}) - target_link_libraries(${PROJECT_NAME} PUBLIC Boost::filesystem Boost::system) - list(APPEND INCLUDE_DIRS_FOR_DYNAMIC_VIEW ${Boost_INCLUDE_DIR}) - option(HAS_STD_FILESYSTEM_PATH "use boost::filesystem" OFF) + message(STATUS "WORKAROUND: Forcing boost::filesystem on Android") + set(NEED_BOOST_FS 1) endif() else () message(STATUS "use c++20") - option(HAS_STD_FILESYSTEM_PATH "use std::filesystem" ON) + # Workaround: 2021-08-09 Android NDK does not provide proper std::filesystem + # support. Force boost::filesystem instead. + if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Android") + option(HAS_STD_FILESYSTEM_PATH "use std::filesystem" ON) + else () + message(STATUS "WORKAROUND: Forcing boost::filesystem on Android") + set(NEED_BOOST_FS 1) + endif () endif () +if(NEED_BOOST_FS) + find_package(Boost 1.49.0 COMPONENTS filesystem system REQUIRED) + message(STATUS "Using Boost filesytem::path") + message(STATUS "Boost include dir: " ${Boost_INCLUDE_DIR}) + include_directories(${BOOST_INCLUDE_DIRS}) + message(STATUS "Boost libraries: " ${Boost_LIBRARIES}) + target_link_libraries(${PROJECT_NAME} PUBLIC Boost::filesystem Boost::system) + list(APPEND INCLUDE_DIRS_FOR_DYNAMIC_VIEW ${Boost_INCLUDE_DIR}) + option(HAS_STD_FILESYSTEM_PATH "use boost::filesystem" OFF) +endif() + list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules/) # jsoncpp