-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ImGui-SFML v.2.0 * Better CMake support * Compiler warning fixes * Can now compile as shared library
- Loading branch information
Showing
9 changed files
with
680 additions
and
405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,152 @@ | ||
# Only tested in 3.1, may work in older versions. | ||
# . | ||
# Install SFML or set SFML_ROOT and set IMGUI_ROOT prior to running cmake | ||
# . | ||
# Provides the follow variables: | ||
# IMGUI_SFML_INCLUDE_DIRS - imgui and imgui_sfml include paths | ||
# IMGUI_SOURCES - imgui.cpp source path to link with your binary | ||
# IMGUI_SFML_SOURCES - imgui_sfml.cpp source path to link with your binary | ||
# IMGUI_SFML_DEPENDENCIES - found dependencies to link with your library (sfml) | ||
# . | ||
# Sample usage: | ||
# add_subdirectory(repos/imgui-sfml) | ||
# include_directories("${IMGUI_SFML_INCLUDE_DIRS}") | ||
# add_executable(MY_PROJECT ${IMGUI_SOURCES} ${IMGUI_SFML_SOURCES} ${SRCS}) | ||
# ... | ||
# target_link_libraries(MY_PROJECT ${IMGUI_SFML_DEPENDENCIES}) | ||
# . | ||
cmake_minimum_required(VERSION 3.1) | ||
|
||
project(imgui_sfml) | ||
project(imgui_sfml | ||
LANGUAGES CXX | ||
VERSION 2.0 | ||
) | ||
|
||
option(IMGUI_SFML_BUILD_EXAMPLES "Build ImGui_SFML examples" ON) | ||
option(IMGUI_SFML_BUILD_EXAMPLES "Build ImGui_SFML examples" OFF) | ||
option(IMGUI_SFML_FIND_SFML "Use find_package to find SFML" ON) | ||
|
||
# Find required libraries | ||
find_package(SFML 2.2 COMPONENTS graphics window system) | ||
message(status "** SFML Include: ${SFML_INCLUDE_DIR}") | ||
message(status "** SFML Libraries: ${SFML_LIBRARIES}") | ||
if(NOT SFML_FOUND) | ||
set(SFML_ROOT "" CACHE PATH "SFML top-level directory") | ||
message("---> SFML 2 directory not found. Set SFML_ROOT to SFML's top-level path (containing \"include\" and \"lib\" directories).\n") | ||
# If you want to use your own user config when compiling ImGui, please set the following variables | ||
# For example, if you have your config in /path/to/dir/with/config/myconfig.h, set the variables as follows: | ||
# | ||
# IMGUI_SFML_USE_DEFAULT_CONFIG = OFF | ||
# IMGUI_SFML_USER_CONFIG_DIR = /path/to/dir/with/config | ||
# IMGUI_SFML_USER_CONFIG_NAME = "myconfig.h" | ||
# | ||
# If you set IMGUI_SFML_CONFIG_INSTALL_DIR, ImGui-SFML won't install your custom config, because | ||
# you might want to do it yourself | ||
option(IMGUI_SFML_USE_DEFAULT_CONFIG "Use default imconfig-SFML.h" ON) | ||
set(IMGUI_SFML_CONFIG_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH "Path to a directory containing user ImGui config") | ||
set(IMGUI_SFML_CONFIG_NAME "imconfig-SFML.h" CACHE STRING "Name of a custom user ImGui config header") | ||
set(IMGUI_SFML_CONFIG_INSTALL_DIR "" CACHE PATH "Path where user's config header will be installed") | ||
|
||
# For FindImGui.cmake | ||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") | ||
|
||
if (IMGUI_SFML_FIND_SFML) | ||
find_package(SFML 2.5 COMPONENTS graphics system window) | ||
|
||
if(NOT SFML_FOUND) | ||
message(FATAL_ERROR "SFML 2 directory not found. Set SFML_DIR to directory where SFML was built (or one which ccontains SFMLConfig.cmake)") | ||
endif() | ||
endif() | ||
|
||
# ImGui does not provide native support for CMakeLists, workaround for now to have | ||
# users specify IMGUI_ROOT. See: | ||
# https://github.com/ocornut/imgui/pull/255 | ||
if(NOT IMGUI_ROOT) | ||
set(IMGUI_ROOT "" CACHE PATH "imgui top-level directory") | ||
message("---> ImGui directory not found. Set IMGUI_ROOT to imgui's top-level path (containing \"imgui.cpp\" and \"imgui.h\" files).\n") | ||
# users specify IMGUI_DIR. Waiting for this PR to get merged... | ||
# https://github.com/ocornut/imgui/pull/1713 | ||
if(NOT IMGUI_DIR) | ||
set(IMGUI_DIR "" CACHE PATH "imgui top-level directory") | ||
message(FATAL_ERROR "ImGui directory not found. Set IMGUI_ROOT to imgui's top-level path (containing 'imgui.h' and other files).\n") | ||
endif() | ||
|
||
# Do a pseudo find files for ImGui once IMGUI_ROOT is set | ||
if(IMGUI_ROOT) | ||
set(IMGUI_SERACH_PATH | ||
${IMGUI_ROOT} | ||
$ENV{IMGUI_ROOT} | ||
) | ||
find_path(IMGUI_INCLUDE_DIR imgui.cpp | ||
PATHS ${IMGUI_SERACH_PATH}) | ||
if(NOT IMGUI_INCLUDE_DIR) | ||
message(FATAL_ERROR "---> IMGUI imgui.cpp not found. Set IMGUI_ROOT to imgui's top-level path (containing \"imgui.cpp\" and \"imgui.h\" files).\n") | ||
else() | ||
file(GLOB IMGUI_FILES | ||
"${IMGUI_INCLUDE_DIR}/imgui_draw.cpp" | ||
"${IMGUI_INCLUDE_DIR}/imgui_demo.cpp" | ||
"${IMGUI_INCLUDE_DIR}/imgui.cpp" ) | ||
message("Found imgui.cpp in ${IMGUI_INCLUDE_DIR}") | ||
# Rename that pesky imconfig.h file for the user. | ||
install(FILES ${IMGUI_INCLUDE_DIR}/imconfig.h DESTINATION include RENAME imconfig-sample.h) | ||
endif() | ||
# This uses FindImGui.cmake provided in ImGui-SFML repo for now | ||
find_package(ImGui 1.68 REQUIRED) | ||
|
||
# these headers will be installed alongside ImGui-SFML | ||
set(IMGUI_PUBLIC_HEADERS | ||
${IMGUI_INCLUDE_DIR}/imconfig.h | ||
${IMGUI_INCLUDE_DIR}/imgui.h | ||
${IMGUI_INCLUDE_DIR}/imgui_internal.h # not actually public, but users might need it | ||
${IMGUI_INCLUDE_DIR}/imstb_rectpack.h | ||
${IMGUI_INCLUDE_DIR}/imstb_textedit.h | ||
${IMGUI_INCLUDE_DIR}/imstb_truetype.h | ||
${IMGUI_INCLUDE_DIR}/misc/cpp/imgui_stdlib.h | ||
) | ||
|
||
# CMake 3.11 and later prefer to choose GLVND, but we choose legacy OpenGL just because it's safer | ||
# (unless the OpenGL_GL_PREFERENCE was explicitly set) | ||
# See CMP0072 for more details (cmake --help-policy CMP0072) | ||
if ((NOT ${CMAKE_VERSION} VERSION_LESS 3.11) AND (NOT OpenGL_GL_PREFERENCE)) | ||
set(OpenGL_GL_PREFERENCE "LEGACY") | ||
endif() | ||
|
||
# Glob up both source and headers as sources for VS users. | ||
file(GLOB IMGUI_SFML_FILES "${PROJECT_SOURCE_DIR}/*.cpp" "${PROJECT_SOURCE_DIR}/*.h") | ||
find_package(OpenGL REQUIRED) | ||
|
||
# Set these for users to use | ||
set(IMGUI_SFML_INCLUDE_DIRS | ||
${PROJECT_SOURCE_DIR} | ||
${IMGUI_INCLUDE_DIR} | ||
${SFML_INCLUDE_DIR} CACHE INTERNAL "") | ||
add_library(ImGui-SFML | ||
imgui-SFML.cpp | ||
${IMGUI_SOURCES} | ||
) | ||
|
||
set(IMGUI_SOURCES | ||
${IMGUI_FILES} CACHE INTERNAL "") | ||
# Add pretty alias | ||
add_library(ImGui-SFML::ImGui-SFML ALIAS ImGui-SFML) | ||
|
||
set(IMGUI_SFML_SOURCES | ||
${IMGUI_SFML_FILES} CACHE INTERNAL "") | ||
target_link_libraries(ImGui-SFML | ||
PUBLIC | ||
sfml-graphics | ||
sfml-system | ||
sfml-window | ||
${OPENGL_LIBRARIES} | ||
) | ||
|
||
set(IMGUI_SFML_DEPENDENCIES | ||
${SFML_DEPENDENCIES} | ||
${SFML_LIBRARIES} CACHE INTERNAL "") | ||
include(GNUInstallDirs) | ||
|
||
target_include_directories(ImGui-SFML | ||
PUBLIC | ||
$<BUILD_INTERFACE:${IMGUI_INCLUDE_DIR}> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}> | ||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> | ||
) | ||
|
||
if(NOT IMGUI_SFML_USE_DEFAULT_CONFIG) | ||
if (IMGUI_SFML_CONFIG_DIR) | ||
target_include_directories(ImGui-SFML | ||
PUBLIC | ||
$<BUILD_INTERFACE:${IMGUI_SFML_CONFIG_DIR}> | ||
$<INSTALL_INTERFACE:${IMGUI_SFML_INSTALL_CONFIG_DIR}> | ||
) | ||
else() | ||
message(FATAL_ERROR "IMGUI_SFML_CONFIG_DIR should be set if IMGUI_SFML_USE_DEFAULT_CONFIG is OFF") | ||
endif() | ||
endif() | ||
|
||
target_compile_definitions(ImGui-SFML | ||
PUBLIC | ||
IMGUI_USER_CONFIG="${IMGUI_SFML_CONFIG_NAME}" | ||
) | ||
|
||
if(BUILD_SHARED_LIBS) | ||
target_compile_definitions(ImGui-SFML PRIVATE IMGUI_SFML_SHARED_LIB) | ||
set_target_properties(ImGui-SFML PROPERTIES | ||
DEFINE_SYMBOL "IMGUI_SFML_EXPORTS" | ||
) | ||
endif() | ||
|
||
set(IMGUI_SFML_PUBLIC_HEADERS | ||
"${CMAKE_CURRENT_LIST_DIR}/imgui-SFML.h" | ||
"${CMAKE_CURRENT_LIST_DIR}/imgui-SFML_export.h" | ||
) | ||
|
||
if (IMGUI_SFML_USE_DEFAULT_CONFIG OR | ||
(NOT DEFINED "${IMGUI_SFML_CONFIG_INSTALL_DIR}")) | ||
list(APPEND IMGUI_SFML_PUBLIC_HEADERS | ||
"${IMGUI_SFML_CONFIG_DIR}/${IMGUI_SFML_CONFIG_NAME}" | ||
) | ||
# If user set IMGUI_SFML_INSTALL_CONFIG_DIR, it means that they'll install file themselves | ||
endif() | ||
|
||
list(APPEND IMGUI_SFML_PUBLIC_HEADERS "${IMGUI_PUBLIC_HEADERS}") | ||
|
||
set_target_properties(ImGui-SFML PROPERTIES | ||
PUBLIC_HEADER "${IMGUI_SFML_PUBLIC_HEADERS}" | ||
) | ||
|
||
if(IMGUI_SFML_BUILD_EXAMPLES) | ||
# Build examples | ||
add_subdirectory(examples) | ||
endif(IMGUI_SFML_BUILD_EXAMPLES) | ||
endif() | ||
|
||
# installation rules | ||
install(TARGETS ImGui-SFML | ||
EXPORT ImGui-SFML | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} | ||
) | ||
|
||
install(EXPORT ImGui-SFML | ||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ImGui-SFML | ||
NAMESPACE ImGui-SFML:: | ||
FILE ImGui-SFMLConfig.cmake | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.