InfiniTimeOrg / InfiniSim

Simulator for InfiniTime user interface without needing a PineTime
GNU General Public License v3.0
166 stars 67 forks source link

Add FindFilesystem.cmake helper for littlefs-do std::filesystem #58

Closed NeroBurner closed 2 years ago

NeroBurner commented 2 years ago

The new tool littlefs-do uses std::filesystem, which is available since C++17. But older compiler (like GCC-8) need an additional linkage -lstdc++fs to work properly.

The added module handles all those specifics.

The module was downloaded from https://github.com/lethal-guitar/RigelEngine/blob/master/cmake/Modules/FindFilesystem.cmake

Fixes: https://github.com/InfiniTimeOrg/InfiniSim/issues/57

NeroBurner commented 2 years ago

not tested, not needed, closing

devnoname120 commented 1 year ago

I had the following error when trying to compile InfiniSim:

parallels@debian-gnu-linux-10:~/InfiniSim$ cmake --build build -j 4
-- Using CMake version 3.13.4
-- InfiniTime PROJECT_VERSION extracted: 1.11.0
-- Using default C++ standard 17
-- Using MONITOR_ZOOM=1
-- add subdirectory /home/parallels/InfiniSim/InfiniTime/src/displayapp/fonts for 'infinitime_fonts' target
-- Using /home/parallels/InfiniSim/node_modules/.bin/lv_font_conv to generate font files
-- Symbol prefix: 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/parallels/InfiniSim/build
[  0%] Built target scripts_symbols_out
[  0%] Built target pngprefix_h
[  1%] Built target pnglibconf_c
[  2%] Built target scripts_pnglibconf_c
[  3%] Built target littlefs
[  3%] Built target infinitime_fonts_open_sans_light
[  4%] Built target QCBOR
[  4%] Built target infinitime_fonts_jetbrains_mono_extrabold_compressed
[  5%] Built target infinitime_fonts_lv_font_sys_48
[  5%] Built target infinitime_fonts_jetbrains_mono_42
[  5%] Built target infinitime_fonts_lv_font_navi_80
[ 47%] Built target sim-base
[ 48%] Built target infinitime_fonts_jetbrains_mono_76
[ 48%] Built target infinitime_fonts_jetbrains_mono_bold_20
[ 50%] Built target scripts_symbols_chk
[ 50%] Built target miniz
[ 51%] Built target pnglibconf_out
[ 55%] Built target infinitime_fonts
[ 55%] Built target scripts_prefix_out
[ 56%] Built target pnglibconf_h
[ 56%] Linking CXX executable littlefs-do
[ 57%] Built target scripts_sym_out
[ 58%] Built target scripts_intprefix_out
[ 60%] Built target scripts_vers_out
[ 61%] Built target gensym
[ 61%] Built target genvers
[ 64%] Built target genfiles
[ 71%] Built target png_static
/usr/bin/ld: CMakeFiles/littlefs-do.dir/littlefs-do-main.cpp.o: in function `command_cp(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool)':
littlefs-do-main.cpp:(.text+0x24d8): undefined reference to `std::filesystem::file_size(std::filesystem::__cxx11::path const&)'
/usr/bin/ld: CMakeFiles/littlefs-do.dir/littlefs-do-main.cpp.o: in function `mkdir_path(std::filesystem::__cxx11::path const&)':
littlefs-do-main.cpp:(.text+0x38b4): undefined reference to `std::filesystem::__cxx11::path::parent_path() const'
/usr/bin/ld: CMakeFiles/littlefs-do.dir/littlefs-do-main.cpp.o: in function `command_res(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool)':
littlefs-do-main.cpp:(.text+0x3d64): undefined reference to `std::filesystem::file_size(std::filesystem::__cxx11::path const&)'
/usr/bin/ld: littlefs-do-main.cpp:(.text+0x4130): undefined reference to `std::filesystem::__cxx11::path::parent_path() const'
/usr/bin/ld: CMakeFiles/littlefs-do.dir/littlefs-do-main.cpp.o: in function `std::filesystem::__cxx11::path::path(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, std::filesystem::__cxx11::path::format)':
littlefs-do-main.cpp:(.text._ZNSt10filesystem7__cxx114pathC2EONSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS1_6formatE[_ZNSt10filesystem7__cxx114pathC5EONSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS1_6formatE]+0x4c): undefined reference to `std::filesystem::__cxx11::path::_M_split_cmpts()'
/usr/bin/ld: CMakeFiles/littlefs-do.dir/littlefs-do-main.cpp.o: in function `std::filesystem::__cxx11::path::operator/=(std::filesystem::__cxx11::path const&)':
littlefs-do-main.cpp:(.text._ZNSt10filesystem7__cxx114pathdVERKS1_[_ZNSt10filesystem7__cxx114pathdVERKS1_]+0x38): undefined reference to `std::filesystem::__cxx11::path::has_filename() const'
/usr/bin/ld: littlefs-do-main.cpp:(.text._ZNSt10filesystem7__cxx114pathdVERKS1_[_ZNSt10filesystem7__cxx114pathdVERKS1_]+0x90): undefined reference to `std::filesystem::__cxx11::path::_M_split_cmpts()'
/usr/bin/ld: CMakeFiles/littlefs-do.dir/littlefs-do-main.cpp.o: in function `std::filesystem::__cxx11::path::is_absolute() const':
littlefs-do-main.cpp:(.text._ZNKSt10filesystem7__cxx114path11is_absoluteEv[_ZNKSt10filesystem7__cxx114path11is_absoluteEv]+0x10): undefined reference to `std::filesystem::__cxx11::path::has_root_directory() const'
/usr/bin/ld: CMakeFiles/littlefs-do.dir/littlefs-do-main.cpp.o: in function `std::filesystem::__cxx11::operator==(std::filesystem::__cxx11::path const&, std::filesystem::__cxx11::path const&)':
littlefs-do-main.cpp:(.text._ZNSt10filesystem7__cxx11eqERKNS0_4pathES3_[_ZNSt10filesystem7__cxx11eqERKNS0_4pathES3_]+0x18): undefined reference to `std::filesystem::__cxx11::path::compare(std::filesystem::__cxx11::path const&) const'
/usr/bin/ld: CMakeFiles/littlefs-do.dir/littlefs-do-main.cpp.o: in function `std::filesystem::__cxx11::path::extension() const':
littlefs-do-main.cpp:(.text._ZNKSt10filesystem7__cxx114path9extensionEv[_ZNKSt10filesystem7__cxx114path9extensionEv]+0x18): undefined reference to `std::filesystem::__cxx11::path::_M_find_extension() const'
/usr/bin/ld: CMakeFiles/littlefs-do.dir/littlefs-do-main.cpp.o: in function `std::filesystem::exists(std::filesystem::__cxx11::path const&)':
littlefs-do-main.cpp:(.text._ZNSt10filesystem6existsERKNS_7__cxx114pathE[_ZNSt10filesystem6existsERKNS_7__cxx114pathE]+0x10): undefined reference to `std::filesystem::status(std::filesystem::__cxx11::path const&)'
/usr/bin/ld: CMakeFiles/littlefs-do.dir/littlefs-do-main.cpp.o: in function `std::filesystem::is_directory(std::filesystem::__cxx11::path const&)':
littlefs-do-main.cpp:(.text._ZNSt10filesystem12is_directoryERKNS_7__cxx114pathE[_ZNSt10filesystem12is_directoryERKNS_7__cxx114pathE]+0x10): undefined reference to `std::filesystem::status(std::filesystem::__cxx11::path const&)'
/usr/bin/ld: CMakeFiles/littlefs-do.dir/littlefs-do-main.cpp.o: in function `std::filesystem::__cxx11::path::path<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::filesystem::__cxx11::path>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::filesystem::__cxx11::path::format)':
littlefs-do-main.cpp:(.text._ZNSt10filesystem7__cxx114pathC2INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES1_EERKT_NS1_6formatE[_ZNSt10filesystem7__cxx114pathC5INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES1_EERKT_NS1_6formatE]+0x5c): undefined reference to `std::filesystem::__cxx11::path::_M_split_cmpts()'
/usr/bin/ld: CMakeFiles/littlefs-do.dir/littlefs-do-main.cpp.o: in function `std::filesystem::__cxx11::path::path<char [2], std::filesystem::__cxx11::path>(char const (&) [2], std::filesystem::__cxx11::path::format)':
littlefs-do-main.cpp:(.text._ZNSt10filesystem7__cxx114pathC2IA2_cS1_EERKT_NS1_6formatE[_ZNSt10filesystem7__cxx114pathC5IA2_cS1_EERKT_NS1_6formatE]+0x5c): undefined reference to `std::filesystem::__cxx11::path::_M_split_cmpts()'
/usr/bin/ld: CMakeFiles/littlefs-do.dir/littlefs-do-main.cpp.o: in function `std::filesystem::__cxx11::path::path<char [5], std::filesystem::__cxx11::path>(char const (&) [5], std::filesystem::__cxx11::path::format)':
littlefs-do-main.cpp:(.text._ZNSt10filesystem7__cxx114pathC2IA5_cS1_EERKT_NS1_6formatE[_ZNSt10filesystem7__cxx114pathC5IA5_cS1_EERKT_NS1_6formatE]+0x5c): undefined reference to `std::filesystem::__cxx11::path::_M_split_cmpts()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/littlefs-do.dir/build.make:164: littlefs-do] Error 1
make[1]: *** [CMakeFiles/Makefile2:191: CMakeFiles/littlefs-do.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 71%] Linking CXX executable infinisim
[ 98%] Built target infinisim
make: *** [Makefile:130: all] Error 2

My configuration:

parallels@debian-gnu-linux-10:~/InfiniSim/build$ neofetch
       _,met$$$$$gg.          parallels@debian-gnu-linux-10 
    ,g$$$$$$$$$$$$$$$P.       ----------------------------- 
  ,g$$P"     """Y$$.".        OS: Debian GNU/Linux 10 (buster) aarch64 
 ,$$P'              `$$$.     Host: Parallels ARM Virtual Machine 0.1 
',$$P       ,ggs.     `$$b:   Kernel: 4.19.0-17-arm64 
`d$$'     ,$P"'   .    $$$    Uptime: 3 hours, 59 mins 
 $$P      d$'     ,    $$P    Packages: 1691 (dpkg) 
 $$:      $$.   -    ,d$$'    Shell: bash 5.0.3 
 $$;      Y$b._   _,d$P'      Resolution: 1864x966 
 Y$$.    `.`"Y$$$$P"'         DE: GNOME 3.30.2 
 `$$b      "-.__              WM: GNOME Shell 
  `Y$$                        WM Theme: Adwaita 
   `Y$$.                      Theme: Adwaita [GTK2/3] 
     `$$b.                    Icons: Adwaita [GTK2/3] 
       `Y$$b.                 Terminal: gnome-terminal 
          `"Y$b._             CPU: (2) 
              `"""            GPU: Red Hat, Inc Virtio GPU 
                              Memory: 973MiB / 1996MiB 

I can confirm that applying this PR on main + adding target_link_libraries(infinisim PRIVATE std::filesystem) in CMakeLists.txt fixed the issue entirely for me.

Here is the cmake generation output after the changes:

parallels@debian-gnu-linux-10:~/InfiniSim$ cmake -S . -B build
-- Using CMake version 3.13.4
-- InfiniTime PROJECT_VERSION extracted: 1.11.0
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using default C++ standard 17
-- Using MONITOR_ZOOM=1
-- add subdirectory /home/parallels/InfiniSim/InfiniTime/src/displayapp/fonts for 'infinitime_fonts' target
-- Using /home/parallels/InfiniSim/node_modules/.bin/lv_font_conv to generate font files
-- Found Python3: /usr/bin/python3.7 (found version "3.7.3") found components:  Interpreter 
-- add subdirectory /home/parallels/InfiniSim/InfiniTime/src/resources for 'GenerateResources' target
-- Using /home/parallels/InfiniSim/node_modules/.bin/lv_font_conv to generate font files
-- Using /home/parallels/InfiniSim/node_modules/.bin/lv_img_conv to generate font files
-- Found SDL2: /usr/lib/aarch64-linux-gnu/libSDL2-2.0.so  
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/cc
-- Found ZLIB: /usr/lib/aarch64-linux-gnu/libz.so (found version "1.2.11") 
-- Performing Test HAVE_LD_VERSION_SCRIPT
-- Performing Test HAVE_LD_VERSION_SCRIPT - Success
-- Symbol prefix: 
-- Looking for C++ include filesystem
-- Looking for C++ include filesystem - found
-- Performing Test CXX_FILESYSTEM_NO_LINK_NEEDED
-- Performing Test CXX_FILESYSTEM_NO_LINK_NEEDED - Failed
-- Performing Test CXX_FILESYSTEM_STDCPPFS_NEEDED
-- Performing Test CXX_FILESYSTEM_STDCPPFS_NEEDED - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/parallels/InfiniSim/build
NeroBurner commented 1 year ago

@devnoname120 could you reopen a new PR with your changes (this PR and your change combined)

devnoname120 commented 1 year ago

@NeroBurner Done. https://github.com/InfiniTimeOrg/InfiniSim/pull/83