Skip to content

Commit

Permalink
[FIX] : fix compiler warnings by disabling what is coming for unmaint…
Browse files Browse the repository at this point in the history
…ained libs
  • Loading branch information
aiekick committed Jul 6, 2024
1 parent 16738f8 commit a5eb548
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 70 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ build
/cmake-build-debug
/cmake-build-minsizerel
/cmake-build-release
/bin
/.PVS-Studio
66 changes: 33 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,23 @@ if (USE_BOOST_FILESYSTEM)
add_definitions(-DCUSTOM_FILESYSTEM_INCLUDE="${CMAKE_CURRENT_SOURCE_DIR}/FileSystemBoost.hpp")
endif()

if(MSVC)
set(ORIGINAL_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})

if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_definitions(-DMSVC)
if (USE_STD_FILESYSTEM)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++11")
endif()
else ()
else()
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wdeprecated-declarations -Wunused-parameter")
if (USE_STD_FILESYSTEM)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Wextra -Wpedantic -Wdeprecated-declarations -Wunused-parameter")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wpedantic -Wdeprecated-declarations -Wunused-parameter")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
endif ()
endif()

add_definitions(${GLFW_DEFINITIONS})
add_definitions(-DIMGUI_DISABLE_OBSOLETE_FUNCTIONS)
Expand Down Expand Up @@ -90,30 +93,32 @@ file(GLOB RES_WIDGETS
file(GLOB RES_DEMO_DIALOG
${CMAKE_CURRENT_SOURCE_DIR}/DemoDialog.cpp
${CMAKE_CURRENT_SOURCE_DIR}/DemoDialog.h)

file(GLOB_RECURSE CMAKE_SOURCES ${CMAKE_SOURCE_DIR}/cmake/*.*)

if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
file(GLOB MAIN_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/mainAndroid.cpp)
file(GLOB IMGUIIMPL_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/imgui/backends/imgui_impl_android.cpp
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/imgui/backends/imgui_impl_android.h
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/imgui/backends/imgui_impl_opengl3.cpp
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/imgui/backends/imgui_impl_opengl3.h
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
file(GLOB MAIN_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/mainAndroid.cpp)
file(GLOB IMGUIIMPL_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/imgui/backends/imgui_impl_android.cpp
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/imgui/backends/imgui_impl_android.h
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/imgui/backends/imgui_impl_opengl3.cpp
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/imgui/backends/imgui_impl_opengl3.h
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
else()
file(GLOB MAIN_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/mainWinLinuxMacos.cpp)
file(GLOB IMGUIIMPL_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/imgui/backends/imgui_impl_glfw.cpp
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/imgui/backends/imgui_impl_glfw.h
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/imgui/backends/imgui_impl_opengl3.cpp
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/imgui/backends/imgui_impl_opengl3.h)
file(GLOB MAIN_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/mainWinLinuxMacos.cpp)
file(GLOB IMGUIIMPL_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/imgui/backends/imgui_impl_glfw.cpp
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/imgui/backends/imgui_impl_glfw.h
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/imgui/backends/imgui_impl_opengl3.cpp
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/imgui/backends/imgui_impl_opengl3.h)
endif()

source_group(main FILES ${MAIN_SOURCES})
source_group(src\\DemoDialog FILES ${RES_DEMO_DIALOG})
source_group(src\\Custom FILES ${CUSTOM_SOURCES})
source_group(src\\ImGuiImpl FILES ${IMGUIIMPL_SOURCES})
source_group(cmake FILES ${CMAKE_SOURCES})
source_group(src\\Res FILES ${RES_SOURCES})
source_group(src\\Widgets FILES ${RES_WIDGETS})
source_group(src\\Custom FILES ${CUSTOM_SOURCES})
source_group(src\\DemoDialog FILES ${RES_DEMO_DIALOG})
source_group(src\\ImGuiImpl FILES ${IMGUIIMPL_SOURCES})

if (APPLE)
##set(ICON icon.icns)
Expand Down Expand Up @@ -149,25 +154,20 @@ target_link_libraries(ImGuiFileDialog PRIVATE
${BOOST_FILESYSTEM_LIBRARIES}
)

if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
add_library(${PROJECT} SHARED
set(SOURCES
${RES_SOURCES}
${RES_WIDGETS}
${MAIN_SOURCES}
${BOOST_SOURCES}
${CMAKE_SOURCES}
${CUSTOM_SOURCES}
${RES_DEMO_DIALOG}
${IMGUIIMPL_SOURCES})

if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
add_library(${PROJECT} SHARED ${SOURCES})
else()
add_executable(${PROJECT}
MACOSX_BUNDLE
${RES_SOURCES}
${RES_WIDGETS}
${MAIN_SOURCES}
${BOOST_SOURCES}
${CUSTOM_SOURCES}
${RES_DEMO_DIALOG}
${IMGUIIMPL_SOURCES})
add_executable(${PROJECT} MACOSX_BUNDLE ${SOURCES})
endif()

set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
2 changes: 1 addition & 1 deletion ImGuiFileDialog
5 changes: 5 additions & 0 deletions cmake/boost.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ function(set_target_dir _PREFIX DIR TARGET_DIR)
foreach (_var IN LISTS _matchedVars)
if (TARGET ${_var})
set_target_properties(${_var} PROPERTIES FOLDER ${TARGET_DIR})
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
#target_compile_options(${_var} PRIVATE "-Wno-everything")
else()
target_compile_options(${_var} PRIVATE "-Wno-everything")
endif()
endif()
endforeach()
get_property(SUBDIRS DIRECTORY "${DIR}" PROPERTY SUBDIRECTORIES)
Expand Down
5 changes: 5 additions & 0 deletions cmake/glad.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ include_directories(${GLAD_INCLUDE_DIR})

set_target_properties(glad PROPERTIES LINKER_LANGUAGE C)
set_target_properties(glad PROPERTIES FOLDER 3rdparty)
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
#target_compile_options(glad PRIVATE "-Wno-everything")
else()
target_compile_options(glad PRIVATE "-Wno-everything")
endif()

set(GLAD_LIBRARIES glad)

Expand Down
6 changes: 6 additions & 0 deletions cmake/glfw.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ add_subdirectory(${CMAKE_SOURCE_DIR}/3rdparty/glfw)

set_target_properties(glfw PROPERTIES FOLDER 3rdparty) # Override standard 'GLFW3' subfolder

if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
#target_compile_options(glfw PRIVATE "-Wno-everything")
else()
target_compile_options(glfw PRIVATE "-Wno-everything")
endif()

set(GLFW_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/3rdparty/glfw/include)
set(GLFW_DEFINITIONS -DGLFW_INCLUDE_NONE)
set(GLFW_LIBRARIES ${GLFW_LIBRARIES} glfw)
33 changes: 17 additions & 16 deletions cmake/imgui.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@ add_library(imgui STATIC ${IMGUI_SOURCES})
add_definitions(-DIMGUI_DISABLE_OBSOLETE_FUNCTIONS)

if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")

add_definitions(-DIMGUI_IMPL_OPENGL_ES3)
include_directories(${IMGUI_INCLUDE_DIR})

add_definitions(-DIMGUI_IMPL_OPENGL_ES3)
include_directories(${IMGUI_INCLUDE_DIR})
else()

add_definitions(-DIMGUI_IMPL_OPENGL_LOADER_GLAD)
include_directories(
${IMGUI_INCLUDE_DIR}
${OPENGL_INCLUDE_DIR}
${GLFW_INCLUDE_DIR}
${GLAD_INCLUDE_DIR})
target_link_libraries(imgui
${OPENGL_LIBRARIES}
${GLFW_LIBRARIES}
${GLAD_LIBRARIES})

add_definitions(-DIMGUI_IMPL_OPENGL_LOADER_GLAD)
include_directories(
${IMGUI_INCLUDE_DIR}
${OPENGL_INCLUDE_DIR}
${GLFW_INCLUDE_DIR}
${GLAD_INCLUDE_DIR})
target_link_libraries(imgui
${OPENGL_LIBRARIES}
${GLFW_LIBRARIES}
${GLAD_LIBRARIES})
endif()

set_target_properties(imgui PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(imgui PROPERTIES FOLDER 3rdparty)
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
#target_compile_options(imgui PRIVATE "-Wno-everything")
else()
target_compile_options(imgui PRIVATE "-Wno-everything")
endif()

set(IMGUI_LIBRARIES imgui)

28 changes: 12 additions & 16 deletions cmake/imwidgets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@ file(GLOB IMWIDGETS_HEADERS ${IMWIDGETS_INCLUDE_DIR}/*.h)
add_library(imwidgets STATIC ${IMWIDGETS_SOURCES})

if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")

add_definitions(-DIMGUI_IMPL_OPENGL_ES3)
include_directories(${IMWIDGETS_INCLUDE_DIR})

add_definitions(-DIMGUI_IMPL_OPENGL_ES3)
include_directories(${IMWIDGETS_INCLUDE_DIR})
else()

add_definitions(-DIMGUI_IMPL_OPENGL_LOADER_GLAD)
include_directories(
${IMWIDGETS_INCLUDE_DIR}
${OPENGL_INCLUDE_DIR}
${GLFW_INCLUDE_DIR}
${GLAD_INCLUDE_DIR})
target_link_libraries(imwidgets
${IMGUI_LIBRARIES}
${GLFW_LIBRARIES}
${GLAD_LIBRARIES})

add_definitions(-DIMGUI_IMPL_OPENGL_LOADER_GLAD)
include_directories(
${IMWIDGETS_INCLUDE_DIR}
${OPENGL_INCLUDE_DIR}
${GLFW_INCLUDE_DIR}
${GLAD_INCLUDE_DIR})
target_link_libraries(imwidgets
${IMGUI_LIBRARIES}
${GLFW_LIBRARIES}
${GLAD_LIBRARIES})
endif()

set_target_properties(imwidgets PROPERTIES LINKER_LANGUAGE CXX)
Expand Down
4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ SetTest(Test_IGFD_FileManager_Filtering_insensitive_case_1)
## Test_IGFD_FileManager -- FileInfos SearchForExts
SetTest(Test_IGFD_FileManager_FileInfos_SearchForExts_0)

## Test_IGFD_FileManager -- GetResultingFilePathName
SetTest(Test_IGFD_FileManager_GetResultingFilePathName_issue_144)
SetTest(Test_IGFD_FileManager_GetResultingFilePathName_issue_184)

## Test_IGFD_FileStyle
##SetTest(Test_IGFD_FileStyle_ByExtention_0)
##SetTest(Test_IGFD_FileStyle_ByExtention_1)
Expand Down
86 changes: 83 additions & 3 deletions tests/ImGuiFileDialog/Test_FileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@

#include <cassert>

#include "ImGuiFileDialog/ImGuiFileDialog.h"
#include <ImGuiFileDialog/ImGuiFileDialog.h>

#include <imgui_internal.h>

// specific
#ifdef WIN32
#include <direct.h> // _chdir
#define GetCurrentDir _getcwd
#elif defined(UNIX)
#include <unistd.h> // chdir
#define GetCurrentDir getcwd
#endif

#pragma region Helper

class FileManagerTestHelper {
private:
IGFD::FileDialogInternal fd;
std::set<std::string> arr;
std::unique_ptr<IGFD::IFileSystem> m_FileSystemPtr = nullptr;

private:
void compute_name_array() {
void m_compute_name_array() {
for (const auto& file_ptr : fd.fileManager.m_FileList) {
if (file_ptr) {
arr.emplace(file_ptr->fileNameExt);
Expand All @@ -36,9 +48,21 @@ class FileManagerTestHelper {
}
};

void createDirectoryOnDisk(const std::string& vDirectory) {
fd.fileManager.m_FileSystemPtr->CreateDirectoryIfNotExist(vDirectory);
}

void createFileOnDisk(const std::string& vFile) {
std::ofstream fileWriter(vFile, std::ios::out);
if (!fileWriter.bad()) {
fileWriter << "for testing";
fileWriter.close();
}
}

bool isFileExist(const std::string& vFile) {
if (arr.empty()) {
compute_name_array();
m_compute_name_array();
}
return (arr.find(vFile) != arr.end());
}
Expand All @@ -54,6 +78,24 @@ class FileManagerTestHelper {
IGFD::FileDialogInternal& getFileDialogInternal() {
return fd;
}

void setInput(const std::string& vInput) {
if (!vInput.empty()) {
ImFormatString(fd.fileManager.fileNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER, "%s", vInput.c_str());
} else {
fd.fileManager.fileNameBuffer[0] = '\0';
}
}

void setCurrentPath(const std::string& vPath) {
fd.fileManager.m_CurrentPath = vPath;
}

std::string getCurrentDir() {
char buffer[1024 + 1] = "\0";
GetCurrentDir(buffer, 1024);
return std::string(buffer);
}
};

#pragma endregion
Expand Down Expand Up @@ -226,6 +268,42 @@ bool Test_IGFD_FileManager_FileInfos_SearchForExts_0() {

#pragma endregion

#pragma region GetResultingFilePathName

// ensure #144
bool Test_IGFD_FileManager_GetResultingFilePathName_issue_144() {
FileManagerTestHelper mgr;
auto& fd = mgr.getFileDialogInternal();
mgr.setInput("toto.cpp");
if (fd.fileManager.GetResultingFileName(fd, IGFD_ResultMode_AddIfNoFileExt) != "toto.cpp") return false;
mgr.createDirectoryOnDisk("TITI");
const std::string& existing_path_file = "TITI" + IGFD::Utils::GetPathSeparator() + "toto.cpp ";
mgr.createFileOnDisk(existing_path_file);
mgr.setInput(existing_path_file);
if (fd.fileManager.GetResultingFilePathName(fd, IGFD_ResultMode_AddIfNoFileExt) != existing_path_file) return false;
return true;
}

// ensure #184
bool Test_IGFD_FileManager_GetResultingFilePathName_issue_184() {
FileManagerTestHelper mgr;
auto& fd = mgr.getFileDialogInternal();
mgr.setInput("toto.cpp");
if (fd.fileManager.GetResultingFileName(fd, IGFD_ResultMode_AddIfNoFileExt) != "toto.cpp") return false;
mgr.createFileOnDisk("toto.cpp"); // we create a local file toto.cpp
mgr.createDirectoryOnDisk("TITI");
const std::string& exisitng_path = mgr.getCurrentDir() + IGFD::Utils::GetPathSeparator() + "TITI";
const std::string& existing_path_file = exisitng_path + IGFD::Utils::GetPathSeparator() + "toto.cpp";
mgr.createFileOnDisk(existing_path_file); // we crate also a local file toto.cpp in the dir TITI
mgr.setInput("toto.cpp"); // we select the file toto.cpp
mgr.setCurrentPath(exisitng_path); // in the dir TITI
// but we must ensure than the returned file path is TITI/toto.cpp and not the toto.cpp from the current dir
if (fd.fileManager.GetResultingFilePathName(fd, IGFD_ResultMode_AddIfNoFileExt) != existing_path_file) return false;
return true;
}

#pragma endregion

#pragma region Entry Point

#define IfTestExist(v) \
Expand All @@ -244,6 +322,8 @@ bool Test_FileManager(const std::string& vTest) {
IfTestExist(Test_IGFD_FileManager_Filtering_insensitive_case_0);
IfTestExist(Test_IGFD_FileManager_Filtering_insensitive_case_1);
IfTestExist(Test_IGFD_FileManager_FileInfos_SearchForExts_0);
IfTestExist(Test_IGFD_FileManager_GetResultingFilePathName_issue_144);
IfTestExist(Test_IGFD_FileManager_GetResultingFilePathName_issue_184);

assert(0);

Expand Down
Loading

0 comments on commit a5eb548

Please sign in to comment.