Skip to content

Commit 159bf70

Browse files
committed
build: fix cmake + add patch for android in tiny-process-library
1 parent ef9558a commit 159bf70

File tree

4 files changed

+43
-53
lines changed

4 files changed

+43
-53
lines changed

CMakeLists.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ include_directories(include/libs)
1515

1616
set_source_files_properties(
1717
"src/libs/toml++/toml.cpp"
18+
"src/libs/tiny-process-library/process.cpp"
1819
PROPERTIES COMPILE_FLAGS "-fvisibility=default"
1920
)
2021

@@ -93,6 +94,36 @@ add_library(fmt STATIC
9394
set_target_properties(fmt PROPERTIES POSITION_INDEPENDENT_CODE ON)
9495
target_link_libraries(${TARGET_NAME} PUBLIC fmt)
9596

97+
# tiny-process-library (integrated from its own CMakeLists.txt)
98+
add_library(tiny-process-library STATIC
99+
"src/libs/tiny-process-library/process.cpp")
100+
add_library(tiny-process-library::tiny-process-library ALIAS tiny-process-library)
101+
102+
if(MSVC)
103+
target_compile_definitions(tiny-process-library PRIVATE /D_CRT_SECURE_NO_WARNINGS)
104+
else()
105+
target_compile_options(tiny-process-library PRIVATE -std=c++11 -Wall -Wextra)
106+
endif()
107+
108+
if(WIN32)
109+
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
110+
target_sources(tiny-process-library PRIVATE "src/libs/tiny-process-library/process_win.cpp")
111+
# If compiled using MSYS2, use sh to run commands
112+
if(MSYS)
113+
target_compile_definitions(tiny-process-library PUBLIC MSYS_PROCESS_USE_SH)
114+
endif()
115+
else()
116+
target_sources(tiny-process-library PRIVATE "src/libs/tiny-process-library/process_unix.cpp")
117+
endif()
118+
119+
find_package(Threads REQUIRED)
120+
target_link_libraries(tiny-process-library Threads::Threads)
121+
target_include_directories(tiny-process-library PUBLIC
122+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/libs/tiny-process-library>
123+
$<INSTALL_INTERFACE:include>
124+
)
125+
target_link_libraries(${TARGET_NAME} PUBLIC tiny-process-library)
126+
96127
# libcufetch
97128
set(CUFETCH_HEADERS
98129
include/libcufetch/config.hh

src/libs/tiny-process-library/CMakeLists.txt

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../include/tiny-process-library/process.hpp
1+
../../../include/libs/tiny-process-library/process.hpp

src/libs/tiny-process-library/process_unix.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,20 @@ static int portable_execvpe(const char *file, char *const argv[], char *const en
3232
const char *path = getenv("PATH");
3333
char cspath[PATH_MAX + 1] = {};
3434
if(!path) {
35+
// small patch for android
36+
#ifndef __ANDROID__
3537
// If env variable is not set, use static path string.
3638
confstr(_CS_PATH, cspath, sizeof(cspath));
3739
path = cspath;
40+
#else
41+
// we are certainly on termux, thus android,
42+
// and it doesn't have _CS_PATH, so here's a fix/workaround
43+
const char *prefix = getenv("PREFIX");
44+
if (prefix)
45+
path = prefix;
46+
else
47+
path = "/data/data/com.termux/files/usr";
48+
#endif
3849
}
3950

4051
const size_t path_len = strlen(path);

0 commit comments

Comments
 (0)