deargui-vpl/examples/CMakeLists.txt

217 lines
9.1 KiB
CMake

cmake_minimum_required(VERSION 3.12)
project(imgui-node-editor)
# Define IMGUI_NODE_EDITOR_ROOT_DIR pointing to project root directory
get_filename_component(IMGUI_NODE_EDITOR_ROOT_DIR ${CMAKE_SOURCE_DIR}/.. ABSOLUTE CACHE)
# Enable solution folders in Visual Studio and Folders in Xcode
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Point CMake where to look for module files.
list(APPEND CMAKE_MODULE_PATH ${IMGUI_NODE_EDITOR_ROOT_DIR}/misc/cmake-modules)
# Node editor use C++17 (required for structured bindings and unordered_map with custom hash)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
# Option to also build console variants on Windows
option(BUILD_CONSOLE_VARIANTS "Also build console variants of applications on Windows" ON)
# Option to set console variant as default VS startup project
option(USE_CONSOLE_AS_STARTUP "Set console variant as Visual Studio startup project" ON)
# Macro that will configure an example application
macro(add_example_executable name)
project(${name})
set(_Example_Sources
${ARGN}
)
# Add entry_point.cpp to sources (not in application library due to _CONSOLE conditional compilation)
list(APPEND _Example_Sources ${APPLICATION_ENTRY_POINT_SOURCE})
#source_group("" FILES ${_Example_Sources})
# Group example sources under their tree
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${ARGN})
# Group entry_point.cpp separately since it's from application directory
source_group("application" FILES ${APPLICATION_ENTRY_POINT_SOURCE})
file(GLOB _Example_CommonResources CONFIGURE_DEPENDS "${IMGUI_NODE_EDITOR_ROOT_DIR}/examples/data/*")
file(GLOB _Example_Resources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/data/*")
#message(FATAL_ERROR "_Example_Resources = ${_Example_Resources}")
set(_Example_Type)
if (WIN32)
set(_Example_Type WIN32)
set(ApplicationIcon ${IMGUI_NODE_EDITOR_ROOT_DIR}/examples/Application/Support/Icon.ico)
file(TO_NATIVE_PATH "${ApplicationIcon}" ApplicationIcon)
string(REPLACE "\\" "\\\\" ApplicationIcon "${ApplicationIcon}")
configure_file(
${IMGUI_NODE_EDITOR_ROOT_DIR}/examples/Application/Support/Resource.rc.in
${CMAKE_CURRENT_BINARY_DIR}/Resource.rc
)
source_group(TREE "${IMGUI_NODE_EDITOR_ROOT_DIR}/examples" FILES ${_Example_CommonResources})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${_Example_Resources})
list(APPEND _Example_Resources
${CMAKE_CURRENT_BINARY_DIR}/Resource.rc
${_Example_CommonResources}
)
source_group("resources" FILES ${CMAKE_CURRENT_BINARY_DIR}/Resource.rc)
elseif (APPLE)
set(_Example_Type MACOSX_BUNDLE)
set_source_files_properties(${_Example_Resources} ${_Example_CommonResources} PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources/data"
)
set(_Example_Icon "${IMGUI_NODE_EDITOR_ROOT_DIR}/examples/application/support/Icon.icns")
list(APPEND _Example_Resources ${_Example_Icon})
set_source_files_properties(${_Example_Icon} PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources"
)
endif()
add_executable(${name} ${_Example_Type} ${_Example_Sources} ${_Example_Resources} ${_Example_CommonResources})
# Add /FS flag for MSVC to prevent PDB locking issues during parallel builds
if (WIN32 AND MSVC)
target_compile_options(${name} PRIVATE /FS)
endif()
find_package(imgui REQUIRED)
find_package(imgui_node_editor REQUIRED)
target_link_libraries(${name} PRIVATE imgui imgui_node_editor application)
set(_ExampleBinDir ${CMAKE_BINARY_DIR}/bin)
set_target_properties(${name} PROPERTIES
FOLDER "examples"
RUNTIME_OUTPUT_DIRECTORY "${_ExampleBinDir}"
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${_ExampleBinDir}"
RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${_ExampleBinDir}"
RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${_ExampleBinDir}"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${_ExampleBinDir}"
DEBUG_POSTFIX _d
RELWITHDEBINGO_POSTFIX _rd
MINSIZEREL_POSTFIX _r
VS_DEBUGGER_WORKING_DIRECTORY ${_ExampleBinDir}
MACOSX_BUNDLE_INFO_PLIST "${IMGUI_NODE_EDITOR_ROOT_DIR}/examples/application/support/Info.plist.in"
MACOSX_BUNDLE_BUNDLE_NAME "${PACKAGE_NAME}"
MACOSX_BUNDLE_GUI_IDENTIFIER "com.sandbox.collisions"
MACOSX_BUNDLE_LONG_VERSION_STRING "${PACKAGE_VERSION}"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}"
MACOSX_BUNDLE_ICON_FILE Icon.icns
)
add_custom_command(
TARGET ${name}
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ARGS ${_ExampleBinDir}/data
)
set(_ResourceRoot ${CMAKE_CURRENT_SOURCE_DIR})
foreach(_Resource ROOT "${IMGUI_NODE_EDITOR_ROOT_DIR}/examples/data" ${_Example_CommonResources} ROOT "${CMAKE_CURRENT_SOURCE_DIR}/data" ${_Example_Resources})
if (_Resource STREQUAL ROOT)
set(_ResourceRoot FALSE)
continue()
elseif(NOT _ResourceRoot)
set(_ResourceRoot ${_Resource})
continue()
endif()
if ("${_Resource}" MATCHES "\.DS_Store$")
list(REMOVE_ITEM _Example_Resources ${_Resource})
list(REMOVE_ITEM _Example_CommonResources ${_Resource})
continue()
endif()
file(RELATIVE_PATH _RelResource ${_ResourceRoot} ${_Resource})
add_custom_command(
TARGET ${name}
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ARGS ${_Resource} ${_ExampleBinDir}/data/${_RelResource}
)
endforeach()
# On Windows, optionally create a console variant
if (WIN32 AND BUILD_CONSOLE_VARIANTS)
set(_ConsoleTargetName ${name}-console)
# Create console executable (without WIN32 flag)
add_executable(${_ConsoleTargetName} ${_Example_Sources} ${_Example_Resources} ${_Example_CommonResources})
# Define _CONSOLE to use main() instead of WinMain()
target_compile_definitions(${_ConsoleTargetName} PRIVATE _CONSOLE)
# Add /FS flag for MSVC to prevent PDB locking issues during parallel builds
if (MSVC)
target_compile_options(${_ConsoleTargetName} PRIVATE /FS)
endif()
# Link the same libraries
find_package(imgui REQUIRED)
find_package(imgui_node_editor REQUIRED)
target_link_libraries(${_ConsoleTargetName} PRIVATE imgui imgui_node_editor application)
# Set the same properties as the GUI version
set_target_properties(${_ConsoleTargetName} PROPERTIES
FOLDER "examples"
RUNTIME_OUTPUT_DIRECTORY "${_ExampleBinDir}"
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${_ExampleBinDir}"
RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${_ExampleBinDir}"
RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${_ExampleBinDir}"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${_ExampleBinDir}"
DEBUG_POSTFIX _d
RELWITHDEBINGO_POSTFIX _rd
MINSIZEREL_POSTFIX _r
VS_DEBUGGER_WORKING_DIRECTORY ${_ExampleBinDir}
)
# Add custom commands for resource copying (same as GUI version)
add_custom_command(
TARGET ${_ConsoleTargetName}
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ARGS ${_ExampleBinDir}/data
)
foreach(_Resource ROOT "${IMGUI_NODE_EDITOR_ROOT_DIR}/examples/data" ${_Example_CommonResources} ROOT "${CMAKE_CURRENT_SOURCE_DIR}/data" ${_Example_Resources})
if (_Resource STREQUAL ROOT)
set(_ResourceRoot FALSE)
continue()
elseif(NOT _ResourceRoot)
set(_ResourceRoot ${_Resource})
continue()
endif()
if ("${_Resource}" MATCHES "\.DS_Store$")
continue()
endif()
file(RELATIVE_PATH _RelResource ${_ResourceRoot} ${_Resource})
add_custom_command(
TARGET ${_ConsoleTargetName}
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ARGS ${_Resource} ${_ExampleBinDir}/data/${_RelResource}
)
endforeach()
endif()
endmacro()
add_subdirectory(application)
add_subdirectory(blueprints-example)
# Set the default Visual Studio startup project
if (WIN32 AND BUILD_CONSOLE_VARIANTS AND USE_CONSOLE_AS_STARTUP)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT blueprints-example-console)
message(STATUS "Visual Studio startup project: blueprints-example-console")
else()
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT blueprints-example)
message(STATUS "Visual Studio startup project: blueprints-example")
endif()