Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CMake config to allow using imnodes as sub project #182

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 73 additions & 52 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,25 @@ project(imnodes)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

find_package(imgui CONFIG REQUIRED)
find_package(SDL2 CONFIG REQUIRED)

# determine whether this is a standalone project or included by other projects
if (NOT DEFINED IMNODES_STANDALONE_PROJECT)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(IMNODES_STANDALONE_PROJECT ON)
else()
set(IMNODES_STANDALONE_PROJECT OFF)
endif ()
endif()

# cmake options
option(IMNODES_EXAMPLES "Build examples" ${IMNODES_STANDALONE_PROJECT})

# allow custom imgui target name since this can vary because imgui doesn't natively include a CMakeLists.txt
if(NOT DEFINED IMNODES_IMGUI_TARGET_NAME)
find_package(imgui CONFIG REQUIRED)
set(IMNODES_IMGUI_TARGET_NAME imgui::imgui)
endif()


if(MSVC)
add_compile_definitions(SDL_MAIN_HANDLED)
Expand All @@ -22,59 +39,63 @@ target_sources(imnodes PRIVATE
imnodes.h
imnodes_internal.h
imnodes.cpp)
target_include_directories(imnodes PUBLIC ${CMAKE_SOURCE_DIR})
target_link_libraries(imnodes PUBLIC imgui::imgui)
target_include_directories(imnodes PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(imnodes PUBLIC ${IMNODES_IMGUI_TARGET_NAME})

# Example projects
if(IMNODES_EXAMPLES)

add_executable(colornode
${CMAKE_SOURCE_DIR}/imnodes.cpp
${CMAKE_SOURCE_DIR}/example/main.cpp
${CMAKE_SOURCE_DIR}/example/color_node_editor.cpp)
target_link_libraries(colornode imnodes SDL2::SDL2)
if (APPLE)
target_link_libraries(colornode "-framework OpenGL")
elseif(MSVC)
target_link_libraries(colornode "opengl32")
else()
target_link_libraries(colornode X11 Xext GL)
endif()
find_package(SDL2 CONFIG REQUIRED)

add_executable(multieditor
${CMAKE_SOURCE_DIR}/imnodes.cpp
${CMAKE_SOURCE_DIR}/example/main.cpp
${CMAKE_SOURCE_DIR}/example/multi_editor.cpp)
target_link_libraries(multieditor imnodes SDL2::SDL2)
if (APPLE)
target_link_libraries(multieditor "-framework OpenGL")
elseif(MSVC)
target_link_libraries(multieditor "opengl32")
else()
target_link_libraries(multieditor X11 Xext GL)
endif()
add_executable(colornode
${CMAKE_CURRENT_SOURCE_DIR}/imnodes.cpp
${CMAKE_CURRENT_SOURCE_DIR}/example/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/example/color_node_editor.cpp)
target_link_libraries(colornode imnodes SDL2::SDL2)
if (APPLE)
target_link_libraries(colornode "-framework OpenGL")
elseif(MSVC)
target_link_libraries(colornode "opengl32")
else()
target_link_libraries(colornode X11 Xext GL)
endif()

add_executable(saveload
${CMAKE_SOURCE_DIR}/imnodes.cpp
${CMAKE_SOURCE_DIR}/example/main.cpp
${CMAKE_SOURCE_DIR}/example/save_load.cpp)
target_link_libraries(saveload imnodes SDL2::SDL2)
if (APPLE)
target_link_libraries(saveload "-framework OpenGL")
elseif(MSVC)
target_link_libraries(saveload "opengl32")
else()
target_link_libraries(saveload X11 Xext GL)
endif()
add_executable(multieditor
${CMAKE_CURRENT_SOURCE_DIR}/imnodes.cpp
${CMAKE_CURRENT_SOURCE_DIR}/example/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/example/multi_editor.cpp)
target_link_libraries(multieditor imnodes SDL2::SDL2)
if (APPLE)
target_link_libraries(multieditor "-framework OpenGL")
elseif(MSVC)
target_link_libraries(multieditor "opengl32")
else()
target_link_libraries(multieditor X11 Xext GL)
endif()

add_executable(hello
${CMAKE_SOURCE_DIR}/imnodes.cpp
${CMAKE_SOURCE_DIR}/example/main.cpp
${CMAKE_SOURCE_DIR}/example/hello.cpp)
target_link_libraries(hello imnodes SDL2::SDL2)
if (APPLE)
target_link_libraries(hello "-framework OpenGL")
elseif(MSVC)
target_link_libraries(hello "opengl32")
else()
target_link_libraries(hello X11 Xext GL)
endif()
add_executable(saveload
${CMAKE_CURRENT_SOURCE_DIR}/imnodes.cpp
${CMAKE_CURRENT_SOURCE_DIR}/example/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/example/save_load.cpp)
target_link_libraries(saveload imnodes SDL2::SDL2)
if (APPLE)
target_link_libraries(saveload "-framework OpenGL")
elseif(MSVC)
target_link_libraries(saveload "opengl32")
else()
target_link_libraries(saveload X11 Xext GL)
endif()

add_executable(hello
${CMAKE_CURRENT_SOURCE_DIR}/imnodes.cpp
${CMAKE_CURRENT_SOURCE_DIR}/example/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/example/hello.cpp)
target_link_libraries(hello imnodes SDL2::SDL2)
if (APPLE)
target_link_libraries(hello "-framework OpenGL")
elseif(MSVC)
target_link_libraries(hello "opengl32")
else()
target_link_libraries(hello X11 Xext GL)
endif()
endif()
4 changes: 0 additions & 4 deletions imnodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
// [SECTION] render helpers
// [SECTION] API implementation

#include "imnodes.h"
#include "imnodes_internal.h"

#define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui_internal.h>

// Check minimum ImGui version
#define MINIMUM_COMPATIBLE_IMGUI_VERSION 17400
#if IMGUI_VERSION_NUM < MINIMUM_COMPATIBLE_IMGUI_VERSION
Expand Down
6 changes: 3 additions & 3 deletions imnodes_internal.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once

#include "imnodes.h"

#include <imgui.h>
#define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui.h>
#include <imgui_internal.h>

#include "imnodes.h"

#include <limits.h>

// the structure of this file:
Expand Down