Skip to content

Commit

Permalink
Scope MinGW workarounds
Browse files Browse the repository at this point in the history
  • Loading branch information
thetic committed Oct 30, 2022
1 parent 4261d0a commit 597c2b9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
12 changes: 0 additions & 12 deletions CMakeLists.txt
Expand Up @@ -150,18 +150,6 @@ if(HAVE_SIZEOF_LONGLONG)
set(CPPUTEST_HAVE_LONG_LONG_INT ON)
endif()

if (MINGW)
check_struct_has_member("struct timespec" tv_sec time.h CPPUTEST_HAVE_STRUCT_TIMESPEC LANGUAGE CXX)
if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# Apply workaround for static/shared libraries on MinGW C/C++ compiler
# Issue occurs with CMake >= 3.9.0, it doesn't filter out gcc,gcc_s,gcc_eh from
# the implicit library list anymore, so the C++ linker is getting passed the static
# gcc_eh library since that's what the C linker uses by default. Only solution appears
# to be to force static linkage.
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
endif()
endif()

configure_file (
"${PROJECT_SOURCE_DIR}/config.h.cmake"
"${PROJECT_BINARY_DIR}/generated/CppUTestGeneratedConfig.h"
Expand Down
3 changes: 3 additions & 0 deletions CMakePresets.json
Expand Up @@ -46,6 +46,9 @@
{
"name": "MinGW",
"inherits": ["GNU"],
"environment": {
"LDFLAGS": "-static"
},
"cacheVariables": {
"CMAKE_C_COMPILER": "x86_64-w64-mingw32-gcc",
"CMAKE_CXX_COMPILER": "x86_64-w64-mingw32-g++",
Expand Down
6 changes: 0 additions & 6 deletions config.h.cmake
Expand Up @@ -13,12 +13,6 @@

#cmakedefine01 CPPUTEST_HAVE_FENV

#cmakedefine CPPUTEST_HAVE_STRUCT_TIMESPEC
#ifdef CPPUTEST_HAVE_STRUCT_TIMESPEC
/* Apply workaround for MinGW timespec redefinition (pthread.h / time.h) */
#define _TIMESPEC_DEFINED 1
#endif

#cmakedefine CPPUTEST_STD_C_LIB_DISABLED
#cmakedefine CPPUTEST_STD_CPP_LIB_DISABLED

Expand Down
7 changes: 7 additions & 0 deletions src/CppUTest/CMakeLists.txt
Expand Up @@ -59,6 +59,11 @@ if(CPPUTEST_PLATFORM)
)
endif()

if (MINGW)
include(CheckStructHasMember)
check_struct_has_member("struct timespec" tv_sec time.h HAVE_STRUCT_TIMESPEC LANGUAGE CXX)
endif()

#[[Arrange for the include directory to be added to the include paths of any CMake target depending on CppUTest.]]
target_include_directories(${CppUTestLibName}
PUBLIC
Expand All @@ -69,6 +74,8 @@ target_include_directories(${CppUTestLibName}
target_compile_definitions(${CppUTestLibName}
PRIVATE
$<$<BOOL:${CPPUTEST_USE_SECURE_STDLIB}>:STDC_WANT_SECURE_LIB>
# Apply workaround for MinGW timespec redefinition (pthread.h / time.h).
$<$<BOOL:${HAVE_STRUCT_TIMESPEC}>:_TIMESPEC_DEFINED>
)

if (WIN32)
Expand Down

0 comments on commit 597c2b9

Please sign in to comment.