forked from ocornut/imgui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
69 lines (60 loc) · 2.33 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
cmake_minimum_required(VERSION 3.3)
project(imgui)
find_package(glfw3)
find_package(OpenGL)
find_package(glew CONFIG)
set(root ${CMAKE_CURRENT_SOURCE_DIR})
set(phdrs ${root}/imgui.h)
set(hdrs ${root}/stb_rect_pack.h ${root}/stb_textedit.h ${root}/stb_truetype.h
${root}/imgui_internal.h)
set(srcs ${root}/imgui.cpp
${root}/imgui_demo.cpp ${root}/imgui_draw.cpp)
add_library(imgui STATIC ${phdrs} ${hdrs} ${srcs})
target_include_directories(imgui PUBLIC
$<BUILD_INTERFACE:${root}>
$<INSTALL_INTERFACE:include>)
target_compile_definitions(imgui PUBLIC IMGUI_DISABLE_INCLUDE_IMCONFIG_H)
set(targets imgui)
set(headers_to_install ${phdrs})
if(glfw3_FOUND AND OPENGL_FOUND AND glew_FOUND)
message(STATUS "OpenGL, GLEW and GLFW found, installing imgui::glfw-gl3-glew.")
# replace #include gl3w.h with glew.h
file(STRINGS examples/opengl3_example/imgui_impl_glfw_gl3.cpp cppcontent)
set(cppcontent-glew "")
foreach(l ${cppcontent})
if(l MATCHES "#include.*GL/gl3w.h")
set(l "#include \"GL/glew.h\"")
endif()
string(APPEND cppcontent-glew "${l}\n")
endforeach()
set(modified_cpp "${CMAKE_CURRENT_BINARY_DIR}/imgui_impl_glfw_gl3-glew.cpp")
file(WRITE "${modified_cpp}" "${cppcontent-glew}")
add_library(glfw-gl3-glew STATIC
"${modified_cpp}"
examples/opengl3_example/imgui_impl_glfw_gl3.h
)
target_include_directories(glfw-gl3-glew PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/examples/opengl3_example>
$<INSTALL_INTERFACE:include>)
target_link_libraries(glfw-gl3-glew PUBLIC OpenGL::GL GLEW::glew_s glfw imgui)
list(APPEND targets glfw-gl3-glew)
list(APPEND headers_to_install examples/opengl3_example/imgui_impl_glfw_gl3.h)
else()
if(NOT OPENGL_FOUND)
message(STATUS "OpenGL not found, not installing imgui::glfw-gl3-glew.")
endif()
if(NOT glew_FOUND)
message(STATUS "GLEW not found, not installing imgui::glfw-gl3-glew.")
endif()
if(NOT glfw3_FOUND)
message(STATUS "GLFW not found, not installing imgui::glfw-gl3-glew.")
endif()
endif()
install(TARGETS ${targets}
EXPORT imgui-targets DESTINATION lib)
install(EXPORT imgui-targets
FILE imgui-config.cmake
NAMESPACE imgui::
DESTINATION lib/cmake/imgui)
install(FILES ${headers_to_install}
DESTINATION include)