Skip to content

Commit 7b2ea35

Browse files
authored
Fix static luajit library lookup on windows (#14)
Fix windows build
1 parent ead1b88 commit 7b2ea35

File tree

14 files changed

+426
-257
lines changed

14 files changed

+426
-257
lines changed

CMakeLists.txt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ if(BUILD_LUA_BINDINGS)
4040
set(ADDITIONAL_SOURCES src/lua/script.cpp ${ADDITIONAL_SOURCES})
4141
endif(BUILD_LUA_BINDINGS)
4242

43-
if(BUILD_KATANA_FROM_SUBMODULE)
44-
set(KATANA_INCLUDE_DIRS katana-parser/src/)
45-
set(KATANA_LIBRARY katana)
46-
include_directories(${KATANA_INCLUDE_DIRS})
47-
file(GLOB_RECURSE sources katana-parser/src/*.c)
48-
add_library(${KATANA_LIBRARY} STATIC ${sources})
49-
endif(BUILD_KATANA_FROM_SUBMODULE)
43+
# disable it for now. It's not used, and does not build on windows
44+
#if(BUILD_KATANA_FROM_SUBMODULE)
45+
# set(KATANA_INCLUDE_DIRS katana-parser/src/)
46+
# set(KATANA_LIBRARY katana)
47+
# include_directories(${KATANA_INCLUDE_DIRS})
48+
# file(GLOB_RECURSE sources katana-parser/src/*.c)
49+
# add_library(${KATANA_LIBRARY} STATIC ${sources})
50+
#endif(BUILD_KATANA_FROM_SUBMODULE)
5051

5152
if(BUILD_TESTS)
5253
find_package(GTest)
@@ -72,6 +73,7 @@ add_library(${LIB_NAME} STATIC
7273
src/imvue_element.cpp
7374
src/imvue_script.cpp
7475
src/imvue_context.cpp
76+
src/imstring.cpp
7577
${ADDITIONAL_SOURCES})
7678

7779
set(IMGUI_SOURCES
@@ -98,7 +100,7 @@ endif(BUILD_IMGUI_FROM_SUBMODULE)
98100
target_link_libraries(${LIB_NAME} ${ADDITIONAL_LIBS})
99101

100102
if(MSVC)
101-
target_compile_options(${LIB_NAME} PRIVATE /W4 /WX)
103+
target_compile_options(${LIB_NAME} PRIVATE /W4)
102104
else()
103-
target_compile_options(${LIB_NAME} PRIVATE -Wall -Wextra -pedantic -Werror)
105+
target_compile_options(${LIB_NAME} PRIVATE -Wall -Wextra -pedantic)
104106
endif()

cmake/Modules/FindLuaJIT.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ FIND_PATH(LUA_INCLUDE_DIR lua.h
4444
)
4545

4646
FIND_LIBRARY(LUA_LIBRARY
47-
NAMES libluajit-static.a luajit-51 luajit-5.1 luajit
47+
NAMES libluajit-static.a luajit-static.lib libluajit luajit-51 luajit-5.1 luajit
4848
HINTS
4949
$ENV{LUAJIT_DIR}
5050
PATH_SUFFIXES lib64 lib

src/imstring.cpp

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*
2+
Copyright (c) 2019 Artem Chernyshev
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
SOFTWARE.
21+
*/
22+
23+
#include "imstring.h"
24+
#include "imgui.h"
25+
#include "imgui_internal.h"
26+
27+
ImString::ImString()
28+
: mData(0)
29+
, mRefCount(0)
30+
{
31+
}
32+
33+
ImString::ImString(size_t len)
34+
: mData(0)
35+
, mRefCount(0)
36+
{
37+
reserve(len);
38+
}
39+
40+
ImString::ImString(char* string)
41+
: mData(string)
42+
, mRefCount(0)
43+
{
44+
ref();
45+
}
46+
47+
ImString::ImString(const char* string)
48+
: mData(0)
49+
, mRefCount(0)
50+
{
51+
if(string) {
52+
mData = ImStrdup(string);
53+
ref();
54+
}
55+
}
56+
57+
ImString::ImString(const ImString& other)
58+
{
59+
mRefCount = other.mRefCount;
60+
mData = other.mData;
61+
ref();
62+
}
63+
64+
ImString::~ImString()
65+
{
66+
unref();
67+
}
68+
69+
char& ImString::operator[](size_t pos) {
70+
return mData[pos];
71+
}
72+
73+
ImString::operator char* () { return mData; }
74+
75+
bool ImString::operator==(const char* string)
76+
{
77+
return strcmp(string, mData) == 0;
78+
}
79+
80+
bool ImString::operator!=(const char* string)
81+
{
82+
return strcmp(string, mData) != 0;
83+
}
84+
85+
bool ImString::operator==(const ImString& string)
86+
{
87+
return strcmp(string.c_str(), mData) == 0;
88+
}
89+
90+
bool ImString::operator!=(const ImString& string)
91+
{
92+
return strcmp(string.c_str(), mData) != 0;
93+
}
94+
95+
ImString& ImString::operator=(const char* string)
96+
{
97+
if(mData)
98+
unref();
99+
mData = ImStrdup(string);
100+
ref();
101+
return *this;
102+
}
103+
104+
ImString& ImString::operator=(const ImString& other)
105+
{
106+
if(mData && mData != other.mData)
107+
unref();
108+
mRefCount = other.mRefCount;
109+
mData = other.mData;
110+
ref();
111+
return *this;
112+
}
113+
114+
void ImString::reserve(size_t len)
115+
{
116+
if(mData)
117+
unref();
118+
mData = (char*)ImGui::MemAlloc(len + 1);
119+
mData[len] = '\0';
120+
ref();
121+
}
122+
123+
char* ImString::get() {
124+
return mData;
125+
}
126+
127+
const char* ImString::c_str() const {
128+
return mData;
129+
}
130+
131+
bool ImString::empty() const {
132+
return mData == 0 || mData[0] == '\0';
133+
}
134+
135+
int ImString::refcount() const {
136+
return *mRefCount;
137+
}
138+
139+
void ImString::ref() {
140+
if(!mRefCount) {
141+
mRefCount = new int();
142+
(*mRefCount) = 0;
143+
}
144+
(*mRefCount)++;
145+
}
146+
147+
void ImString::unref()
148+
{
149+
if(mRefCount) {
150+
(*mRefCount)--;
151+
if(*mRefCount == 0) {
152+
ImGui::MemFree(mData);
153+
mData = 0;
154+
delete mRefCount;
155+
}
156+
mRefCount = 0;
157+
}
158+
}

0 commit comments

Comments
 (0)