Skip to content

Commit 61ab029

Browse files
authored
fix inclusion via CMake (#78)
* fix: Cleanup workspace * chore: move CR to include-able subfolder * refactor: Update all includes to use the path * feat(CMake): Only build samples/tests/etc. if this project is top level This project now uses include_directories to make the cr.h file appear the root level as it did before. Note: this required bumping the cmake minimum required version to 3.21 for PROJECT_IS_TOP_LEVEL * fix: Replace outdated imgui APIs * fix: Fix conversion warning
1 parent 3537d1c commit 61ab029

13 files changed

+126
-109
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.fips-imports.cmake
22
.fips-gen.py
3+
CMakeUserPresets.json

.vscode/tasks.json

+95-85
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,100 @@
11
{
2-
"isShellCommand":true,
3-
"version":"0.1.0",
4-
"showOutput":"silent",
2+
"version": "2.0.0",
53
"tasks":[
6-
{
7-
"problemMatcher":"$msCompile",
8-
"taskName":"glfw3",
9-
"args":[
10-
"make",
11-
"glfw3"
12-
]
13-
},
14-
{
15-
"problemMatcher":"$msCompile",
16-
"taskName":"googletest",
17-
"args":[
18-
"make",
19-
"googletest"
20-
]
21-
},
22-
{
23-
"problemMatcher":"$msCompile",
24-
"taskName":"basic_guest",
25-
"args":[
26-
"make",
27-
"basic_guest"
28-
]
29-
},
30-
{
31-
"problemMatcher":"$msCompile",
32-
"taskName":"imgui_host",
33-
"args":[
34-
"make",
35-
"imgui_host"
36-
]
37-
},
38-
{
39-
"problemMatcher":"$msCompile",
40-
"taskName":"test_basic",
41-
"args":[
42-
"make",
43-
"test_basic"
44-
]
45-
},
46-
{
47-
"problemMatcher":"$msCompile",
48-
"taskName":"crTest",
49-
"args":[
50-
"make",
51-
"crTest"
52-
]
53-
},
54-
{
55-
"problemMatcher":"$msCompile",
56-
"taskName":"basic_host",
57-
"args":[
58-
"make",
59-
"basic_host"
60-
]
61-
},
62-
{
63-
"problemMatcher":"$msCompile",
64-
"taskName":"imgui_guest",
65-
"args":[
66-
"make",
67-
"imgui_guest"
68-
]
69-
},
70-
{
71-
"problemMatcher":"$msCompile",
72-
"taskName":"imgui",
73-
"args":[
74-
"make",
75-
"imgui"
76-
]
77-
},
78-
{
79-
"problemMatcher":"$msCompile",
80-
"isBuildCommand":true,
81-
"taskName":"ALL",
82-
"args":[
83-
"build"
84-
]
85-
}
86-
],
87-
"suppressTaskName":true,
4+
{
5+
"label": "glfw3",
6+
"type": "shell",
7+
"args": [
8+
"make",
9+
"glfw3"
10+
],
11+
"problemMatcher": "$msCompile"
12+
},
13+
{
14+
"label": "googletest",
15+
"type": "shell",
16+
"args": [
17+
"make",
18+
"googletest"
19+
],
20+
"problemMatcher": "$msCompile"
21+
},
22+
{
23+
"label": "basic_guest",
24+
"type": "shell",
25+
"args": [
26+
"make",
27+
"basic_guest"
28+
],
29+
"problemMatcher": "$msCompile"
30+
},
31+
{
32+
"label": "imgui_host",
33+
"type": "shell",
34+
"args": [
35+
"make",
36+
"imgui_host"
37+
],
38+
"problemMatcher": "$msCompile"
39+
},
40+
{
41+
"label": "test_basic",
42+
"type": "shell",
43+
"args": [
44+
"make",
45+
"test_basic"
46+
],
47+
"problemMatcher": "$msCompile"
48+
},
49+
{
50+
"label": "crTest",
51+
"type": "shell",
52+
"args": [
53+
"make",
54+
"crTest"
55+
],
56+
"problemMatcher": "$msCompile"
57+
},
58+
{
59+
"label": "basic_host",
60+
"type": "shell",
61+
"args": [
62+
"make",
63+
"basic_host"
64+
],
65+
"problemMatcher": "$msCompile"
66+
},
67+
{
68+
"label": "imgui_guest",
69+
"type": "shell",
70+
"args": [
71+
"make",
72+
"imgui_guest"
73+
],
74+
"problemMatcher": "$msCompile"
75+
},
76+
{
77+
"label": "imgui",
78+
"type": "shell",
79+
"args": [
80+
"make",
81+
"imgui"
82+
],
83+
"problemMatcher": "$msCompile"
84+
},
85+
{
86+
"label": "ALL",
87+
"type": "shell",
88+
"args": [
89+
"build"
90+
],
91+
"problemMatcher": "$msCompile",
92+
"group": {
93+
"_id": "build",
94+
"isDefault": false
95+
}
96+
}
97+
],
8898
"echoCommand":true,
8999
"command":"fips"
90100
}

CMakeLists.txt

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
#
22
# project: cr
33
#
4-
cmake_minimum_required(VERSION 3.0)
4+
cmake_minimum_required(VERSION 3.21)
55
project(cr)
66

7-
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
8-
SET(FIPS_DYNAMIC_CRT 1)
9-
10-
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
11-
12-
if (NOT CMAKE_EXPORT_FIND_PACKAGE_NAME)
7+
if (PROJECT_IS_TOP_LEVEL)
8+
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
9+
set(FIPS_DYNAMIC_CRT 1)
1310
get_filename_component(FIPS_ROOT_DIR "../fips" ABSOLUTE)
1411
include("${FIPS_ROOT_DIR}/cmake/fips.cmake")
15-
16-
if (NOT FIPS_IMPORT)
17-
fips_setup(PROJECT cr)
12+
fips_setup(PROJECT cr)
1813
add_definitions(-DCR_DEPLOY_PATH="${FIPS_PROJECT_DEPLOY_DIR}")
14+
include_directories(cr)
1915
add_subdirectory(samples)
2016
add_subdirectory(tests)
21-
endif()
17+
fips_finish()
18+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
19+
else()
20+
add_library(cr INTERFACE)
21+
target_include_directories(cr INTERFACE cr)
2222
endif()
23+

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ live-reloading of the real application in the form of dynamic loadable binary, a
3535

3636
```c
3737
#define CR_HOST // required in the host only and before including cr.h
38-
#include "../cr.h"
38+
#include "cr.h"
3939

4040
int main(int argc, char *argv[]) {
4141
// the host application should initalize a plugin with a context, a plugin

cr.h renamed to cr/cr.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,19 @@ You can download and install cr using the [vcpkg](https://github.com/Microsoft/v
2828
2929
The cr port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
3030
31+
### Building cr - Using CMake FetchContent
32+
33+
FetchContent_Declare(cr GIT_REPOSITORY https://github.com/fungos/cr GIT_TAG master)
34+
FetchContent_MakeAvailable(cr)
35+
3136
### Example
3237
3338
A (thin) host application executable will make use of `cr` to manage
3439
live-reloading of the real application in the form of dynamic loadable binary, a host would be something like:
3540
3641
```c
3742
#define CR_HOST // required in the host only and before including cr.h
38-
#include "../cr.h"
43+
#include "cr.h"
3944
4045
int main(int argc, char *argv[]) {
4146
// the host application should initalize a plugin with a context, a plugin
@@ -1102,7 +1107,7 @@ static so_handle cr_so_load(const std::string &filename) {
11021107
11031108
static cr_plugin_main_func cr_so_symbol(so_handle handle) {
11041109
CR_ASSERT(handle);
1105-
auto new_main = (cr_plugin_main_func)GetProcAddress(handle, CR_MAIN_FUNC);
1110+
auto new_main = (cr_plugin_main_func)(void*)GetProcAddress(handle, CR_MAIN_FUNC);
11061111
if (!new_main) {
11071112
CR_ERROR("Couldn't find plugin entry point: %d\n",
11081113
GetLastError());

samples/basic_guest.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <stdio.h>
33
#include <stdbool.h>
44
#include <assert.h>
5-
#include "../cr.h"
5+
#include "cr.h"
66

77
// To save states automatically from previous instance to a new loaded one, use CR_STATE flag on statics/globals.
88
// This will create a new data section in the binary for transferable states between instances that will be copied

samples/basic_guest_b.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <stdio.h>
33
#include <stdbool.h>
44
#include <assert.h>
5-
#include "../cr.h"
5+
#include "cr.h"
66

77
// To save states automatically from previous instance to a new loaded one, use CR_STATE flag on statics/globals.
88
// This will create a new data section in the binary for transferable states between instances that will be copied

samples/basic_host.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <thread>
44

55
#define CR_HOST CR_UNSAFE // try to best manage static states
6-
#include "../cr.h"
6+
#include "cr.h"
77

88
const char *plugin = CR_DEPLOY_PATH "/" CR_PLUGIN("basic_guest");
99

samples/basic_host_b.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <thread>
44

55
#define CR_HOST CR_UNSAFE // try to best manage static states
6-
#include "../cr.h"
6+
#include "cr.h"
77

88
// avoid finishing the name by a number to not clash with the version
99
// as we copy the file as filenameversion.ext

samples/imgui_guest.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <GL/gl3w.h> // gl*
1010
#include <GLFW/glfw3.h> // GLFW_KEY*
1111

12-
#include "../cr.h"
12+
#include "cr.h"
1313

1414
// To test imgui 100% guest side, enable this
1515
//#define IMGUI_GUEST_ONLY
@@ -180,7 +180,7 @@ bool ImGui_ImplGlfwGL3_CreateFontsTexture() {
180180
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
181181

182182
// Store our identifier
183-
io.Fonts->TexID = (void *)(intptr_t)g_FontTexture;
183+
io.Fonts->TexID = (ImTextureID)(intptr_t)g_FontTexture;
184184

185185
// Restore state
186186
glBindTexture(GL_TEXTURE_2D, last_texture);
@@ -334,7 +334,7 @@ bool imui_init() {
334334
io.SetClipboardTextFn = g_data->set_clipboard_fn;
335335
io.GetClipboardTextFn = g_data->get_clipboard_fn;
336336
io.ClipboardUserData = g_data->window;
337-
io.ImeWindowHandle = g_data->wndh;
337+
ImGui::GetMainViewport()->PlatformHandleRaw = g_data->wndh;
338338

339339
return true;
340340
}

samples/imgui_host.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#endif
1212

1313
#define CR_HOST CR_UNSAFE
14-
#include "../cr.h"
14+
#include "cr.h"
1515

1616
const char *plugin = CR_DEPLOY_PATH "/" CR_PLUGIN("imgui_guest");
1717

tests/test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <gtest/gtest.h>
22

33
#define CR_HOST
4-
#include "../cr.h"
4+
#include "cr.h"
55
#include "test_data.h"
66

77
#if defined(CR_WINDOWS) || defined(CR_LINUX)

tests/test_basic.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "../cr.h"
1+
#include "cr.h"
22
#include "test_data.h"
33
#include <chrono>
44
#include <cstdint>

0 commit comments

Comments
 (0)