Skip to content

Commit 09495f9

Browse files
author
Youssef Abukwaik
committed
Compile with MSVC 2019 + use CMake instead of make
1 parent 85668f9 commit 09495f9

File tree

8 files changed

+194
-13
lines changed

8 files changed

+194
-13
lines changed

.github/workflows/linux.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v2
1616
- name: install glfw
17-
run: sudo apt-get install -y libglfw3 libglfw3-dev
17+
run: sudo apt-get install -y libglfw3 libglfw3-dev build-essential git cmake
1818
- name: make
19-
run: make
19+
run: |
20+
mkdir build
21+
cd build
22+
cmake ..
23+
make
24+
make install

CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
set(CMAKE_CXX_STANDARD 11)
3+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
4+
5+
SET(PROJECT_VERSION_MAJOR 0)
6+
SET(PROJECT_VERSION_MINOR 1)
7+
SET(PROJECT_VERSION_PATCH 0)
8+
9+
project(ImStudio C CXX)
10+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
11+
include(glfw)
12+
find_package(OpenGL REQUIRED)
13+
14+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
15+
16+
include(CheckCXXCompilerFlag)
17+
18+
if (WIN32)
19+
add_compile_definitions(WIN32_LEAN_AND_MEAN)
20+
add_compile_definitions(NOMINMAX)
21+
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
22+
add_compile_definitions(_SCL_SECURE_NO_WARNINGS)
23+
else()
24+
find_program(CCACHE_FOUND ccache)
25+
if (CCACHE_FOUND)
26+
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
27+
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
28+
endif (CCACHE_FOUND)
29+
endif()
30+
31+
add_subdirectory(src)
32+
33+
if(UNIX AND NOT APPLE)
34+
SET(CPACK_PACKAGE_DIRECTORY ${CMAKE_BINARY_DIR}/packages)
35+
SET(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
36+
SET(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
37+
SET(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
38+
SET(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE)
39+
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Raais <?? @ ?? .com>")
40+
SET(CPACK_DEBIAN_FILE_NAME "ImStudio-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}-Ubuntu.deb")
41+
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libglfw3")
42+
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE all)
43+
SET(CPACK_GENERATOR "TGZ;DEB")
44+
include(CPack)
45+
endif()

Makefile renamed to _Makefile

File renamed without changes.

cmake/glfw.cmake

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
find_package(GLFW 3.3.5 QUIET)
2+
3+
if(GLFW_FOUND)
4+
message(STATUS "Found GLFW")
5+
else()
6+
message(STATUS "GLFW not found - will build from source")
7+
include(ExternalProject)
8+
9+
ExternalProject_Add(glfw PREFIX glfw
10+
GIT_REPOSITORY https://github.com/glfw/glfw.git
11+
GIT_TAG 3.3.5
12+
13+
UPDATE_COMMAND ""
14+
15+
CMAKE_ARGS
16+
"-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
17+
"-DCMAKE_BUILD_TYPE=Release"
18+
"-DGLFW_BUILD_EXAMPLES=OFF"
19+
"-DGLFW_BUILD_TESTS=OFF"
20+
"-DGLFW_BUILD_DOCS=OFF"
21+
22+
CMAKE_CACHE_ARGS
23+
"-DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}"
24+
"-DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}"
25+
26+
LOG_DOWNLOAD 1 LOG_UPDATE 1 LOG_CONFIGURE 1 LOG_BUILD 1 LOG_INSTALL 1
27+
)
28+
29+
ExternalProject_Get_Property(glfw INSTALL_DIR)
30+
set(GLFW_INCLUDE_DIR ${INSTALL_DIR}/include)
31+
set(GLFW_LIBRARIES
32+
${INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}glfw3${CMAKE_STATIC_LIBRARY_SUFFIX})
33+
34+
if(UNIX)
35+
find_package(Threads REQUIRED)
36+
find_package(X11 REQUIRED)
37+
38+
if(NOT X11_Xrandr_FOUND)
39+
message(FATAL_ERROR "Xrandr library not found - required for GLFW")
40+
endif()
41+
42+
if(NOT X11_xf86vmode_FOUND)
43+
message(FATAL_ERROR "xf86vmode library not found - required for GLFW")
44+
endif()
45+
46+
if(NOT X11_Xcursor_FOUND)
47+
message(FATAL_ERROR "Xcursor library not found - required for GLFW")
48+
endif()
49+
50+
if(NOT X11_Xinerama_FOUND)
51+
message(FATAL_ERROR "Xinerama library not found - required for GLFW")
52+
endif()
53+
54+
if(NOT X11_Xinput_FOUND)
55+
message(FATAL_ERROR "Xinput library not found - required for GLFW")
56+
endif()
57+
58+
list(APPEND GLFW_LIBRARIES
59+
"${X11_Xrandr_LIB}" "${X11_Xxf86vm_LIB}" "${X11_Xcursor_LIB}"
60+
"${X11_Xinerama_LIB}" "${X11_Xinput_LIB}"
61+
"${CMAKE_THREAD_LIBS_INIT}" -lrt -ldl)
62+
endif()
63+
endif()
64+
65+
set(GLFW_INCLUDE_DIR ${GLFW_INCLUDE_DIR} CACHE STRING "")
66+
set(GLFW_LIBRARIES ${GLFW_LIBRARIES} CACHE STRING "")

cmake/third-party.cmake

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
add_library(imgui
2+
#ImGui Core
3+
${CMAKE_SOURCE_DIR}/src/third-party/imgui/imgui.cpp
4+
${CMAKE_SOURCE_DIR}/src/third-party/imgui/imgui_demo.cpp
5+
${CMAKE_SOURCE_DIR}/src/third-party/imgui/imgui_draw.cpp
6+
${CMAKE_SOURCE_DIR}/src/third-party/imgui/imgui_tables.cpp
7+
${CMAKE_SOURCE_DIR}/src/third-party/imgui/imgui_widgets.cpp
8+
9+
#ImGui Backends
10+
${CMAKE_SOURCE_DIR}/src/third-party/imgui/backends/imgui_impl_glfw.cpp
11+
${CMAKE_SOURCE_DIR}/src/third-party/imgui/backends/imgui_impl_opengl3.cpp
12+
13+
#ImGui Extras
14+
${CMAKE_SOURCE_DIR}/src/third-party/imgui/misc/cpp/imgui_stdlib.cpp
15+
)
16+
17+
add_dependencies(imgui glfw)
18+
19+
list(APPEND IMGUI_INCLUDE_DIRS
20+
${CMAKE_SOURCE_DIR}/src/third-party/imgui
21+
${CMAKE_SOURCE_DIR}/src/third-party/imgui/backends)
22+
list(APPEND IMGUI_LIBRARIES imgui)
23+
24+
target_include_directories(imgui PRIVATE SYSTEM ${IMGUI_INCLUDE_DIRS})
25+
target_include_directories(imgui PRIVATE SYSTEM ${GLFW_INCLUDE_DIR})
26+
target_link_libraries(imgui PRIVATE ${GLFW_LIBRARIES})
27+
target_compile_definitions(imgui PUBLIC -DIMGUI_IMPL_OPENGL_LOADER_GLAD)
28+
29+
add_library(fmt
30+
${CMAKE_SOURCE_DIR}/src/third-party/fmt/src/format.cc
31+
)
32+
list(APPEND FMT_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/third-party/fmt/include)
33+
list(APPEND FMT_LIBRARIES fmt)
34+
35+
target_include_directories(fmt PRIVATE SYSTEM ${FMT_INCLUDE_DIRS})

src/CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
set(TARGET ImStudio)
2+
3+
include(third-party)
4+
5+
file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/sources/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/utils/*.cpp)
6+
file(GLOB_RECURSE HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/headers/*.h ${CMAKE_CURRENT_SOURCE_DIR}/utils/*.h)
7+
8+
add_executable(${TARGET}
9+
${SOURCES}
10+
${HEADERS}
11+
main.cpp
12+
)
13+
14+
message(STATUS "IMGUI_INCLUDE_DIRS: ${IMGUI_INCLUDE_DIRS}")
15+
message(STATUS "FMT_INCLUDE_DIRS: ${FMT_INCLUDE_DIRS}")
16+
17+
target_include_directories(${TARGET} PRIVATE SYSTEM ${IMGUI_INCLUDE_DIRS})
18+
target_include_directories(${TARGET} PRIVATE SYSTEM ${FMT_INCLUDE_DIRS})
19+
target_include_directories(${TARGET} PRIVATE SYSTEM ${GLFW_INCLUDE_DIR})
20+
21+
target_link_libraries(${TARGET} PRIVATE ${IMGUI_LIBRARIES})
22+
target_link_libraries(${TARGET} PRIVATE ${GLFW_LIBRARIES})
23+
target_link_libraries(${TARGET} PRIVATE ${FMT_LIBRARIES})
24+
target_link_libraries(${TARGET} PRIVATE ${OPENGL_LIBRARIES})
25+
26+
if(UNIX AND NOT APPLE)
27+
install(TARGET ${TARGET} RUNTIME DESTINATION bin)
28+
install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION share/${TARGET})
29+
install(FILES ${CMAKE_SOURCE_DIR}/README.md DESTINATION share/${TARGET})
30+
endif()

src/sources/console.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,11 @@ void ImStudio::Console::ExecCommand(const char *command_line)
271271
}
272272
else if (Stricmp(command_line, "WINDOW") == 0)
273273
{
274-
gui_->bw.state = not gui_->bw.state;
274+
gui_->bw.state = ! gui_->bw.state;
275275
}
276276
else if (Stricmp(command_line, "STATIC") == 0)
277277
{
278-
gui_->bw.staticlayout = not gui_->bw.staticlayout;
278+
gui_->bw.staticlayout = ! gui_->bw.staticlayout;
279279
}
280280
else if (Stricmp(command_line, "BUTTON") == 0)
281281
{
@@ -287,11 +287,11 @@ void ImStudio::Console::ExecCommand(const char *command_line)
287287
}
288288
else if (Stricmp(command_line, "DEMO") == 0)
289289
{
290-
gui_->child_demo = not gui_->child_demo;
290+
gui_->child_demo = ! gui_->child_demo;
291291
}
292292
else if (Stricmp(command_line, "STDOUT") == 0)
293293
{
294-
StdoutMode = not StdoutMode;
294+
StdoutMode = ! StdoutMode;
295295
}
296296
else if (Stricmp(command_line, "EXIT") == 0)
297297
{

src/sources/gui.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ void ImStudio::GUI::ShowSidebar()
356356
}
357357
if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_F9)))
358358
{
359-
child_console = not child_console;
359+
child_console = ! child_console;
360360
}
361361

362362
}
@@ -392,13 +392,14 @@ void ImStudio::GUI::ShowProperties()
392392
}
393393
}
394394

395-
const char *items[allvecsize]; // contains identifiers ex: child1::button2
396-
int idarr[allvecsize]; // contains id associated with ^
395+
std::vector<const char*> items; // contains identifiers ex: child1::button2
396+
std::vector<int> idarr; // contains id associated with ^
397397
int i = 0;
398398
for (Object &o : bw.objects) // Fill both arrays with contents from bw.objects [Object]
399399
{
400-
items[i] = o.identifier.c_str();
401-
idarr[i] = o.id;
400+
char* identifier = const_cast<char *>(o.identifier.c_str());
401+
items.push_back(identifier);
402+
idarr.push_back(o.id);
402403
if (o.id == selectid) // 1. if last select/drag in bw
403404
{
404405
if (ImGui::IsMouseDown(0))
@@ -445,8 +446,7 @@ void ImStudio::GUI::ShowProperties()
445446
}
446447
}
447448
//!SECTION CREATE PROPARRAY
448-
449-
ImGui::Combo("combo", &selectproparray, items, IM_ARRAYSIZE(items));
449+
ImGui::Combo("combo", &selectproparray, items.data(), items.size());
450450

451451
if (ImGui::IsMouseDown(0))
452452
{ // bw select

0 commit comments

Comments
 (0)