diff --git a/CMakeLists.txt b/CMakeLists.txt index 0774eff..7c478e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,27 +9,40 @@ project(implot_demos VERSION 0.1.0) include(FetchContent) # set(FETCHCONTENT_FULLY_DISCONNECTED ON) -FetchContent_Declare(fmt GIT_REPOSITORY https://github.com/fmtlib/fmt) +FetchContent_Declare(fmt GIT_REPOSITORY https://github.com/fmtlib/fmt FIND_PACKAGE_ARGS NAMES fmt) FetchContent_MakeAvailable(fmt) -FetchContent_Declare(glfw GIT_REPOSITORY https://github.com/glfw/glfw) +FetchContent_Declare(glfw GIT_REPOSITORY https://github.com/glfw/glfw FIND_PACKAGE_ARGS NAMES glfw3) FetchContent_MakeAvailable(glfw) -FetchContent_Declare(iir GIT_REPOSITORY https://github.com/berndporr/iir1) +FetchContent_Declare(iir GIT_REPOSITORY https://github.com/berndporr/iir1 FIND_PACKAGE_ARGS NAMES iir) FetchContent_MakeAvailable(iir) if (WIN32) set(CMAKE_USE_SCHANNEL ON) endif() -FetchContent_Declare(curl -URL https://github.com/curl/curl/releases/download/curl-7_75_0/curl-7.75.0.tar.xz -URL_HASH SHA256=fe0c49d8468249000bda75bcfdf9e30ff7e9a86d35f1a21f428d79c389d55675 # the file hash for curl-7.75.0.tar.xz -USES_TERMINAL_DOWNLOAD TRUE) -FetchContent_MakeAvailable(curl) -add_library(curl_int INTERFACE) -target_link_libraries(curl_int INTERFACE libcurl) -target_include_directories(curl_int INTERFACE ${curl_SOURCE_DIR}/include ${curl_BINARY_DIR}/include/curl) -add_library(CURL::libcurl ALIAS curl_int) + + +find_package(PkgConfig) +if (PkgConfig_FOUND) + pkg_check_modules(libcurl libcurl IMPORTED_TARGET) + if (libcurl_FOUND) + endif() +endif() + +if (libcurl_FOUND) + add_library(CURL::libcurl ALIAS PkgConfig::libcurl) +else() + FetchContent_Declare(curl + URL https://github.com/curl/curl/releases/download/curl-7_75_0/curl-7.75.0.tar.xz + URL_HASH SHA256=fe0c49d8468249000bda75bcfdf9e30ff7e9a86d35f1a21f428d79c389d55675 # the file hash for curl-7.75.0.tar.xz + USES_TERMINAL_DOWNLOAD TRUE) + FetchContent_MakeAvailable(curl) + add_library(curl_int INTERFACE) + target_link_libraries(curl_int INTERFACE libcurl) + target_include_directories(curl_int INTERFACE ${curl_SOURCE_DIR}/include ${curl_BINARY_DIR}/include/curl) + add_library(CURL::libcurl ALIAS curl_int) +endif() # LOCAL LIBS @@ -78,44 +91,56 @@ set(IMGUI_SRC find_package(OpenGL REQUIRED) -add_library(imgui ${IMGUI_HEADERS} ${IMGUI_SRC}) -if(MSVC) - target_compile_options(imgui PRIVATE /W4 /WX /arch:AVX2 /fp:fast) -endif() -target_link_libraries(imgui PUBLIC glfw glad OpenGL::GL imm32) -target_compile_definitions(imgui PRIVATE IMGUI_DLL_EXPORT) +find_package(imgui) -include_directories(../imgui/ ../imgui/examples ../imgui/examples/libs/gl3w ../imgui/backends ../imgui/misc/cpp) +if (imgui_FOUND) + add_library(imgui ALIAS imgui::imgui) +else() + add_library(imgui ${IMGUI_HEADERS} ${IMGUI_SRC}) + if(MSVC) + target_compile_options(imgui PRIVATE /W4 /WX /arch:AVX2 /fp:fast) + endif() + target_link_libraries(imgui PUBLIC glfw imm32) + target_compile_definitions(imgui PRIVATE IMGUI_DLL_EXPORT) + + include_directories(../imgui/ ../imgui/examples ../imgui/examples/libs/gl3w ../imgui/backends ../imgui/misc/cpp) +endif() # imnodes -add_library(imnodes 3rdparty/imnodes/imnodes.h 3rdparty/imnodes/imnodes_internal.h 3rdparty/imnodes/imnodes.cpp) -target_link_libraries(imnodes imgui) -include_directories(3rdparty/imnodes) +find_package(imnodes) +if (imnodes_FOUND) + add_library(imnodes ALIAS imnodes::imnodes) +else() + add_library(imnodes 3rdparty/imnodes/imnodes.h 3rdparty/imnodes/imnodes_internal.h 3rdparty/imnodes/imnodes.cpp) + target_link_libraries(imnodes imgui) + include_directories(3rdparty/imnodes) +endif() ############################################################################### # IMPLOT ############################################################################### -set(IMPLOT_HEADERS ../implot/implot.h ../implot/implot_internal.h) -set(IMPLOT_SRC ../implot/implot.cpp ../implot/implot_items.cpp ../implot/implot_demo.cpp) +find_package(implot) -if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../implot/backends") -list(APPEND IMPLOT_HEADERS ../implot/backends/implot_backend.h ../implot/backends/implot_impl_opengl3.h) -list(APPEND IMPLOT_SRC ../implot/backends/implot_backend.h ../implot/backends/implot_impl_opengl3.cpp) -endif() - -add_library(implot ${IMPLOT_HEADERS} ${IMPLOT_SRC}) -target_link_libraries(implot PUBLIC imgui) -target_compile_definitions(implot PUBLIC IMPLOT_DEBUG IMPLOT_DLL_EXPORT IMPLOT_BACKEND_ENABLE_OPENGL3 IMGUI_IMPL_OPENGL_LOADER_GLAD) -set_property(TARGET implot PROPERTY CXX_STANDARD 11) -if(MSVC) - target_compile_options(implot PRIVATE /W4 /WX /arch:AVX2 /fp:fast /permissive-) +if (implot_FOUND) + add_library(implot ALIAS implot::implot) else() - target_compile_options(implot PRIVATE -Wall -Wextra -pedantic -Werror -mavx2 -Ofast) + set(IMPLOT_HEADERS ../implot/implot.h ../implot/implot_internal.h) + set(IMPLOT_SRC ../implot/implot.cpp ../implot/implot_items.cpp ../implot/implot_demo.cpp) + + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../implot/backends") + list(APPEND IMPLOT_HEADERS ../implot/backends/implot_backend.h ../implot/backends/implot_impl_opengl3.h) + list(APPEND IMPLOT_SRC ../implot/backends/implot_backend.h ../implot/backends/implot_impl_opengl3.cpp) + endif() + + add_library(implot ${IMPLOT_HEADERS} ${IMPLOT_SRC}) + target_link_libraries(implot PUBLIC imgui) + target_compile_definitions(implot PUBLIC IMPLOT_DEBUG IMPLOT_DLL_EXPORT IMPLOT_BACKEND_ENABLE_OPENGL3 IMGUI_IMPL_OPENGL_LOADER_GLAD) + set_property(TARGET implot PROPERTY CXX_STANDARD 11) + + include_directories(../implot/) endif() -include_directories(../implot/) - ############################################################################### # APP FRAMEWORK ############################################################################### @@ -137,8 +162,13 @@ add_library(app common/Fonts/RobotoMonoItalic.cpp ) target_include_directories(app PUBLIC common) -target_link_libraries(app implot nfd) +target_link_libraries(app PUBLIC implot imgui imnodes nfd glad OpenGL::GL) target_compile_features(app PRIVATE cxx_std_17) +if(MSVC) + target_compile_options(app PRIVATE /W4 /WX /arch:AVX2 /fp:fast /permissive-) +else() + target_compile_options(app PUBLIC -Wall -Wextra -pedantic -mavx2 -Ofast) +endif() ############################################################################### # DEMO APPS @@ -213,3 +243,5 @@ if (MSVC) else() target_compile_options(benchmark PRIVATE -lstdc++fs -mavx2 -Ofast) endif() + +install(TARGETS benchmark voice stocks demo maps perlin mandel graph filter spectrogram RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/common/App.cpp b/common/App.cpp index 3f18023..3b8394c 100644 --- a/common/App.cpp +++ b/common/App.cpp @@ -149,7 +149,9 @@ App::App(std::string title, int w, int h, int argc, char const *argv[]) const bool no_vsync = result["vsync"].as(); const bool use_msaa = result["msaa"].as(); const bool im_style = result["imgui"].as(); +#if defined(_WIN32) NvOptimusEnablement = AmdPowerXpressRequestHighPerformance = result["gpu"].as(); +#endif UsingDGPU = result["gpu"].as(); #ifdef _DEBUG @@ -317,4 +319,4 @@ ImVec2 App::GetWindowSize() const int w, h; glfwGetWindowSize(Window, &w, &h); return ImVec2(w, h); -} \ No newline at end of file +} diff --git a/demos/filter.cpp b/demos/filter.cpp index c5628de..33d2d28 100644 --- a/demos/filter.cpp +++ b/demos/filter.cpp @@ -70,7 +70,7 @@ struct ImFilter : public App { ImGui::SetNextWindowPos(ImVec2(0,0), ImGuiCond_Always); ImGui::SetNextWindowSize(GetWindowSize(), ImGuiCond_Always); ImGui::Begin("Filter",nullptr, ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoTitleBar); - ImGui::BeginChild("ChildL", ImVec2(ImGui::GetWindowContentRegionWidth() * 0.5f, -1)); + ImGui::BeginChild("ChildL", ImVec2((ImGui::GetWindowContentRegionMax().x - ImGui::GetWindowContentRegionMin().x) * 0.5f, -1)); ImGui::Text("Input: x(t) = A1*sin(2*pi*F1*t) + A2*sin(2*pi*F1*t) + noise"); ImGui::Separator(); diff --git a/demos/stocks.cpp b/demos/stocks.cpp index da5ed8a..02356f1 100644 --- a/demos/stocks.cpp +++ b/demos/stocks.cpp @@ -215,7 +215,7 @@ void TickerTooltip(const TickerData& data, bool span_subplots = false) { ImGui::Text("Close:"); ImGui::SameLine(60); ImGui::Text("$%.2f", data.close[idx]); ImGui::Text("High:"); ImGui::SameLine(60); ImGui::Text("$%.2f", data.high[idx]); ImGui::Text("Low:"); ImGui::SameLine(60); ImGui::Text("$%.2f", data.low[idx]); - ImGui::Text("Volume:"); ImGui::SameLine(60); ImGui::Text(fmt::format(std::locale("en_US.UTF-8"),"{:L}", (int)(data.volume[idx])).c_str()); + ImGui::Text("Volume:"); ImGui::SameLine(60); ImGui::Text("%s", fmt::format(std::locale("en_US.UTF-8"),"{:L}", (int)(data.volume[idx])).c_str()); ImGui::EndTooltip(); } }