Skip to content

Commit

Permalink
feat: update CMakeLists.txt and system_var.h to detect system name in…
Browse files Browse the repository at this point in the history
… compile time
  • Loading branch information
Young-TW committed Jun 23, 2024
1 parent 91e9611 commit 6caaa3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ add_subdirectory(fmt)

if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_compile_definitions(YUSH_WINDOWS)
else()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
add_compile_definitions(YUSH_LINUX)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_compile_definitions(YUSH_MACOS)
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
add_compile_definitions(YUSH_FREEBSD)
elseif(CMAKE_SYSTEM_NAME STREQUAL "UNIX")
add_compile_definitions(YUSH_UNIX)
endif()

Expand Down
12 changes: 8 additions & 4 deletions include/env/system_var.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
#include <string>

const std::string sys =
#ifdef __APPLE__
"MacOS"
#elif defined(__linux__)
#ifdef YUSH_MACOS
"macOS"
#elif YUSH_LINUX
"Linux"
#elif defined(__unix__)
#elif YUSH_UNIX
"Unix"
#elif YUSH_WINDOWS
"Windows"
#elif YUSH_FREEBSD
"FreeBSD"
#else
"Unknown"
#endif
Expand Down

0 comments on commit 6caaa3d

Please sign in to comment.