|
| 1 | +# MIT License |
| 2 | +# |
| 3 | +# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved. |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in all |
| 13 | +# copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +# SOFTWARE. |
| 22 | + |
| 23 | +cmake_minimum_required(VERSION 3.21 FATAL_ERROR) |
| 24 | + |
| 25 | +include(CMakePushCheckState) |
| 26 | +include(CheckCXXSourceCompiles) |
| 27 | + |
| 28 | +set(CMAKE_CXX_STANDARD 17) |
| 29 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 30 | + |
| 31 | +cmake_push_check_state() |
| 32 | + |
| 33 | +set(test_code |
| 34 | +[[ |
| 35 | +#include <filesystem> |
| 36 | +#include <iostream> |
| 37 | + |
| 38 | +namespace fs = std::filesystem; |
| 39 | + |
| 40 | +int main() |
| 41 | +{ |
| 42 | + std::cout << fs::current_path() << std::endl; |
| 43 | + return 0; |
| 44 | +} |
| 45 | +]] |
| 46 | +) |
| 47 | +# Check if std::filesystem works without additional libraries |
| 48 | +check_cxx_source_compiles("${test_code}" CXX_FS_NO_LINK) |
| 49 | + |
| 50 | +if (CXX_FS_NO_LINK) |
| 51 | + message(STATUS "No extra linking required to use std::filesystem") |
| 52 | +else() |
| 53 | + # Check if we can link stdc++fs |
| 54 | + set(CMAKE_REQUIRED_LIBRARIES stdc++fs) |
| 55 | + check_cxx_source_compiles("${test_code}" CXX_FS_CAN_LINK) |
| 56 | + if (CXX_FS_CAN_LINK) |
| 57 | + set(CXX_FS_LIBRARY stdc++fs CACHE STRING "Additional library required to use std::filesystem" FORCE) |
| 58 | + message(STATUS "Need explicite linking to stdc++fs") |
| 59 | + endif() |
| 60 | +endif() |
| 61 | + |
| 62 | +unset(test_code) |
| 63 | +cmake_pop_check_state() |
| 64 | + |
| 65 | +if(NOT CXX_FS_NO_LINK AND NOT CXX_FS_CAN_LINK) |
| 66 | + message(FATAL_ERROR "Cannot run simple program using std::filesystem") |
| 67 | +endif() |
0 commit comments