Skip to content

Commit

Permalink
Add cygwin compilation support
Browse files Browse the repository at this point in the history
  • Loading branch information
vvromanov committed Dec 11, 2024
1 parent 8a09de7 commit 2adb0c7
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 18 deletions.
28 changes: 24 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ else (hasParent)
add_definitions(-DCOVERAGE_TEST)
endif (COVERAGE)

if (NOT CYGWIN)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fstack-protector-strong -static-libasan")
endif (NOT CYGWIN)
if (CYGWIN)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin/")
else (CYGWIN)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin_wsu/")
if (CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fsanitize=leak -fsanitize=undefined -fstack-protector-strong -static-libasan")
endif ()
endif (CYGWIN)

add_definitions(-DTX_VERSION_VERSION_STR="1.0.0")
add_definitions(-DTX_VERSION_BUILD_STR="0")
add_definitions(-DTX_VERSION_VARIANT="${CMAKE_BUILD_TYPE}")
Expand Down Expand Up @@ -151,6 +157,20 @@ target_include_directories(${TARGET} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)

add_subdirectory(rrd-writer)
# not supported on cygwin
if (NOT CYGWIN)
add_subdirectory(rrd-writer)
endif (NOT CYGWIN)

add_subdirectory(test_main)
add_subdirectory(tests)

if (CYGWIN)
add_custom_target(bins ALL
COMMAND cp -f /cygdrive/c/work/tools/${CYGWIN_DIR}/bin/cygwin1.dll ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
COMMAND cp -f /cygdrive/c/work/tools/${CYGWIN_DIR}/bin/cyggcc_s-seh-1.dll ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
COMMAND cp -f /cygdrive/c/work/tools/${CYGWIN_DIR}/bin/cygstdc++-6.dll ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
COMMAND cp -f /cygdrive/c/work/tools/${CYGWIN_DIR}/bin/cygz.dll ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
COMMENT "Copy ${CYGWIN_DIR} libraries to output directory"
)
endif (CYGWIN)
88 changes: 88 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"version": 3,
"configurePresets": [
{
"name": "linux-debug",
"displayName": "Linux Debug",
"description": "Target the Windows Subsystem for Linux (WSL) or a remote Linux system.",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" },
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"vendor": { "microsoft.com/VisualStudioRemoteSettings/CMake/2.0": { "remoteSourceRootDir": "$env{HOME}/.vs/$ms{projectDirName}" } }
},
{
"name": "macos-debug",
"displayName": "macOS Debug",
"description": "Target a remote macOS system.",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" },
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
},
"vendor": { "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": { "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}" } }
},
{
"name": "windows-base",
"description": "Target Windows with the Visual Studio development environment.",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_C_COMPILER": "cl.exe",
"CMAKE_CXX_COMPILER": "cl.exe"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "x64-debug",
"displayName": "x64 Debug",
"description": "Target Windows (64-bit) with the Visual Studio development environment. (Debug)",
"inherits": "windows-base",
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" }
},
{
"name": "x64-release",
"displayName": "x64 Release",
"description": "Target Windows (64-bit) with the Visual Studio development environment. (RelWithDebInfo)",
"inherits": "x64-debug",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Release" }
},
{
"name": "x86-debug",
"displayName": "x86 Debug",
"description": "Target Windows (32-bit) with the Visual Studio development environment. (Debug)",
"inherits": "windows-base",
"architecture": {
"value": "x86",
"strategy": "external"
},
"cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" }
},
{
"name": "x86-release",
"displayName": "x86 Release",
"description": "Target Windows (32-bit) with the Visual Studio development environment. (RelWithDebInfo)",
"inherits": "x86-debug",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Release" }
}
]
}
2 changes: 0 additions & 2 deletions cygwin-path.bat

This file was deleted.

1 change: 1 addition & 0 deletions test_main/ShmFileBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ShmFileBase : public TestBase {

filename = SHM_LOCATION;
filename += shm_name;
shm_name = "/" + shm_name;
}

const char *TestFileName() const {
Expand Down
19 changes: 10 additions & 9 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ project(${TARGET})
enable_testing()
find_package(ZLIB REQUIRED)

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z stack-size=10000000")

add_executable(${TARGET}
Convert.cpp
Dictionary_test.cpp
Expand All @@ -22,7 +20,8 @@ add_executable(${TARGET}
TestHistoryCounters.cpp
TestTimeUtils.cpp
TestUptime.cpp
"ClockOverride.h")
ClockOverride.h
)

target_link_libraries(${TARGET}
test_main
Expand All @@ -31,10 +30,12 @@ target_link_libraries(${TARGET}

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)

add_test(
NAME ${TARGET}
COMMAND ${TARGET} --gtest_output=xml:../test_report_${TARGET}.xml
include(GoogleTest)
add_dependencies(check ${TARGET})

gtest_discover_tests(
${TARGET}
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
XML_OUTPUT_DIR gtest-reports
DISCOVERY_MODE PRE_TEST
)
if (NOT ${STANDALONE_BUILD})
add_dependencies(check ${TARGET})
endif ()
11 changes: 10 additions & 1 deletion tests/ShmBase_Test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include <ShmFileBase.h>
#include <fcntl.h>
#include <sys/mman.h>

#include "ShmFileBase.h"
#include "ShmBase.h"
#include "gtest/gtest.h"
#include "file_utils.h"
Expand All @@ -17,6 +20,12 @@ class ShmBaseTest : public ShmFileBase<TestData> {

};

TEST_F(ShmBaseTest, shm_open) {
int fd = shm_open(TestShmName(), (O_CREAT | O_RDWR), (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH));
EXPECT_NE(-1, fd);
close(fd);
}

TEST_F(ShmBaseTest, Open) {
ShmBase test;
EXPECT_TRUE(test.Open(TestShmName(), TEST_SHM_SIZE));
Expand Down
5 changes: 3 additions & 2 deletions utils/cygwin-install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ IF NOT EXIST %CYGWIN_PATH%/cygwin-setup.exe (
)

REM -- These are the packages we will install (in addition to the default packages)
SET PACKAGES=make,gdb,gcc-g++,gcc-core,cmake,doxygen,libev-devel,libminizip-devel
:gcovr,python39-devel,libxslt-devel
SET PACKAGES=make,gdb,gcc-g++,gcc-core,cmake,doxygen,libev-devel,libminizip-devel,libxml2-devel,libxslt-devel,python39-devel,mc
REM gcovr,python39-devel,libxslt-devel

ECHO *** INSTALLING
%CYGWIN_PATH%\cygwin-setup --quiet-mode --no-desktop --download --local-install --no-admin --no-verify --upgrade-also --local-package-dir "%TEMP%/cygwin_packages" --site %SITE% --root %CYGWIN_PATH% -P %PACKAGES%

ECHO *** INSTALLING gcovr
%CYGWIN_PATH%\bin\bash --login -c "pip3 install --upgrade pip"
%CYGWIN_PATH%\bin\bash --login -c "python3.9 -m pip install gcovr"
del /Q %CYGWIN_PATH%\var\log\*
ENDLOCAL
Expand Down

0 comments on commit 2adb0c7

Please sign in to comment.