Merge pull request #31 from Servostar/30-fix-build-on-windows

30 fix build on windows
This commit is contained in:
SirTalksalot75 2024-04-26 16:15:16 +02:00 committed by GitHub
commit 7c1ec9b6e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 53 additions and 6 deletions

View File

@ -36,6 +36,11 @@ add_custom_command(OUTPUT ${LEX_GENERATED_SOURCE_FILE}
COMMENT "generate C source file for lexer"
VERBATIM)
# remove dependency when compiling with MSVC on windows
if (MSVC)
add_compile_definitions(YY_NO_UNISTD_H)
endif()
# ------------------------------------------------ #
# Yacc #
# ------------------------------------------------ #
@ -56,7 +61,11 @@ add_custom_command(OUTPUT ${YACC_GENERATED_SOURCE_FILE}
file(GLOB_RECURSE SOURCE_FILES src/*.c)
# define default compile flags
set(FLAGS -Wall -Wextra -Wconversion -Wpedantic)
if (MSVC)
set(FLAGS /Wall /W3 /permissive)
else()
set(FLAGS -Wall -Wextra -Wconversion -Wpedantic)
endif()
# ------------------------------------------------ #
# Target RELEASE #
@ -72,13 +81,20 @@ set_target_properties(release
OUTPUT_NAME "gsc"
RUNTIME_OUTPUT_DIRECTORY "bin/release")
# FIXME: cannot compile with /O2 because of /RTC1 flag
if (MSVC)
set(RELEASE_FLAGS)
else()
set(RELEASE_FLAGS -m64 -O3 -fprefetch-loop-arrays -mrecip)
endif()
# compiler flags targeting a 64-bit GCC release environment
# flags:
# - m64: build for 64-bit
# - O3: optimization level 3
# - fprefetch-loop-arrays: pre load arrays used in loops by using prefetch instruction
# - mrecip: make use RCPSS and RSQRTSS instructions
target_compile_options(release PUBLIC ${FLAGS} -m64 -O3 -fprefetch-loop-arrays -mrecip)
target_compile_options(release PUBLIC ${FLAGS} ${RELEASE_FLAGS})
# add src directory as include path
target_include_directories(release PUBLIC src)
@ -97,8 +113,14 @@ set_target_properties(debug
OUTPUT_NAME "gsc"
RUNTIME_OUTPUT_DIRECTORY "bin/debug")
if (MSVC)
set(DEBUG_FLAGS /DEBUG)
else()
set(DEBUG_FLAGS -g)
endif()
# compiler flags targeting a GCC debug environment
target_compile_options(debug PUBLIC ${FLAGS} -g)
target_compile_options(debug PUBLIC ${FLAGS} ${DEBUG_FLAGS})
# add src directory as include path
target_include_directories(debug PUBLIC src)
@ -120,9 +142,15 @@ set_target_properties(check
OUTPUT_NAME "gsc"
RUNTIME_OUTPUT_DIRECTORY "bin/check")
if (MSVC)
set(CHECK_FLAGS /DEBUG /WX)
else()
set(DEBUG_FLAGS -g -Werror)
endif()
# compiler flags targeting a GCC debug environment
# extra -Werror flag to treat warnings as error to make github action fail on warning
target_compile_options(check PUBLIC ${FLAGS} -g -Werror)
target_compile_options(check PUBLIC ${FLAGS} ${DEBUG_FLAGS})
# add src directory as include path
target_include_directories(check PUBLIC src)

View File

@ -2,6 +2,25 @@
Gemstone is a programming language compiler written in C with lex and yacc.
## Dependencies (build)
### Windows 11
For setup instruction see issue #30
Requires:
- Microsoft Build Tools 2022 (includes: CMake, MSVC)
- WinFlexBison [find it here](https://github.com/lexxmark/winflexbison) (needs to be in PATH)
### GNU/Linux
Requires:
- GCC
- CMake
- Make
- bison
- flex
## Development with VSCode/Codium
Recommended extensions for getting a decent experience are the following:
@ -55,4 +74,4 @@ Currently, the SDK is based on Almalinux 9.3, an open source distro binary compa
The following images can be found in the offical repository at [Docker Hub](https://hub.docker.com/r/servostar/gemstone):
- SDK
- Devkit
- Devkit

View File

@ -24,7 +24,7 @@
// generally not defined by GCC < 11.3 and MSVC
#ifndef __FILE_NAME__
#if defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)
#define __FILE_NAME__ (strrstr(__FILE__, "\\") ? strrstr(__FILE__, "\\") + 1 : __FILE__)
#define __FILE_NAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#else
#define __FILE_NAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#endif