Skip to content

Commit

Permalink
Fix Windows MSVC compiler errors
Browse files Browse the repository at this point in the history
  • Loading branch information
latchdevel committed May 29, 2021
1 parent a517ada commit d32f8ef
Show file tree
Hide file tree
Showing 15 changed files with 1,380 additions and 53 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/BuildTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ jobs:
# The matrix will produce one job for each configuration:
matrix:
config:
- name: 'Linux'
- name: 'Linux x86_64'
os: 'ubuntu-latest'
bindir: 'echo "BIN_DIR=$BUILD_DIR" >> $GITHUB_ENV'

- name: 'MacOS'
- name: 'MacOS x86_64'
os: 'macos-latest'
bindir: 'echo "BIN_DIR=$BUILD_DIR" >> $GITHUB_ENV'

- name: 'Windows'
- name: 'Windows x86_64'
os: 'windows-latest'
bindir: 'echo "BIN_DIR=$env:BUILD_DIR/$Env:BUILD_TYPE" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf-8 -Append'

Expand All @@ -68,11 +68,6 @@ jobs:
with:
submodules: recursive

# Windows runner need install getopt
- name: Windows runner install getopt
if: runner.os == 'Windows'
run: vcpkg install getopt

- name: Create Build Environment
# Some projects don't allow in-source building, so create a separate build directory
# We'll use this as our working directory for all subsequent commands
Expand All @@ -99,7 +94,8 @@ jobs:
- name: Upload compiled binaries to Artifacts
uses: actions/upload-artifact@v2
with:
name: "Binaries for ${{ matrix.config.name }}"
name: "Picoder binary for ${{ matrix.config.name }}"
path: |
${{ env.BIN_DIR }}/${{ env.TARGET_TEST }}*
${{ env.BIN_DIR }}/${{ env.TARGET_TEST }}
${{ env.BIN_DIR }}/${{ env.TARGET_TEST }}.exe
33 changes: 21 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ elseif(MSVC)
set(MSVC_DISABLED_WARNINGS_LIST
"C4996" # warning C4996: 'may be unsafe/disable deprecation'
# To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
# "C4244" # warning C4244: '=': conversion from '__int64' to 'int', possible loss of data
# "C4267" # warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
"C4244" # warning C4244: '=': conversion from '__int64' to 'int', possible loss of data
"C4267" # warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
# "C4305" # warning C4305: '=': truncation from 'int' to 'uint16_t'
"C5105" # warning C5105: macro expansion producing 'defined' has undefined behavior
"C4201" # warning C4201: nonstandard extension used: nameless struct/union
Expand All @@ -93,20 +93,29 @@ add_subdirectory( libs/PiCode/ )
# Set source directory for picoder sources
AUX_SOURCE_DIRECTORY( src/ SRC )

# Add picoder as executable
add_executable( ${PROJECT_NAME} ${SRC} )

# Add include directory to use #include <PiCode.h>
target_include_directories( ${PROJECT_NAME} PRIVATE libs/PiCode/src/ )

# getopt is not part of ANSI C, is POSIX, not Windows
if(MSVC)
# Add include directory to use #include <getopt.h>
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} STATIC_GETOPT")
target_include_directories( ${PROJECT_NAME} PRIVATE C:/vcpkg/packages/getopt-win32_x86-windows/include )
#target_link_libraries( ${PROJECT_NAME} PUBLIC getopt )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSTATIC_GETOPT")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -DSTATIC_GETOPT")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Dstrcasecmp=_stricmp")

# Add sources for getopt() and getsubopt()
AUX_SOURCE_DIRECTORY( libs/glibc/stdlib/ STDLIB )

# Add picoder as executable static link
add_executable( ${PROJECT_NAME} ${SRC} ${STDLIB} )

# Add include directory to use #include <getopt.h> and <getsubopt.h>
target_include_directories( ${PROJECT_NAME} PRIVATE libs/glibc/stdlib/ )

else()
# Add picoder as executable
add_executable( ${PROJECT_NAME} ${SRC} )
endif()

# Add include directory to use #include <PiCode.h>
target_include_directories( ${PROJECT_NAME} PRIVATE libs/PiCode/src/ )

# Add PiCode static library (libpicode.a) to link picoder executable
target_link_libraries( ${PROJECT_NAME} PUBLIC picode )

Expand Down
Loading

0 comments on commit d32f8ef

Please sign in to comment.