Skip to content

Commit c324e7b

Browse files
authored
Fix linking to m.lib on Windows (#1080)
We separate configuring warnings and linking to the math library. This way, it works for clang on Windows when using Microsoft's standard library.
1 parent 46f6391 commit c324e7b

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

CPP/CMakeLists.txt

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,19 @@ if (NOT (CLIPPER2_USINGZ STREQUAL "ONLY"))
7777
$<INSTALL_INTERFACE:include>
7878
)
7979

80-
if (MSVC)
80+
# Configure the warning flags.
81+
if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
8182
target_compile_options(Clipper2 PRIVATE /W4 /WX)
82-
else()
83+
elseif (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
8384
target_compile_options(Clipper2 PRIVATE -Wall -Wextra -Wpedantic -Werror)
85+
else ()
86+
message(AUTHOR_WARNING "Clipper2: cannot configure warnings for the unrecognized C++ compiler front end ${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}")
87+
endif ()
88+
89+
# On Windows, if using Microsoft's the standard library, there is no `m.lib`.
90+
if (NOT WIN32 OR MINGW)
8491
target_link_libraries(Clipper2 PUBLIC -lm)
85-
endif()
92+
endif ()
8693
endif()
8794

8895
# secondary Clipper2 library with USINGZ defined (if required)
@@ -102,12 +109,19 @@ if (NOT (CLIPPER2_USINGZ STREQUAL "OFF"))
102109
$<INSTALL_INTERFACE:include>
103110
)
104111

105-
if (MSVC)
106-
target_compile_options(Clipper2Z PRIVATE /W4 /WX)
107-
else()
108-
target_compile_options(Clipper2Z PRIVATE -Wall -Wextra -Wpedantic -Werror)
109-
target_link_libraries(Clipper2Z PUBLIC -lm)
110-
endif()
112+
# Configure the warning flags.
113+
if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
114+
target_compile_options(Clipper2 PRIVATE /W4 /WX)
115+
elseif (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
116+
target_compile_options(Clipper2 PRIVATE -Wall -Wextra -Wpedantic -Werror)
117+
else ()
118+
message(AUTHOR_WARNING "Clipper2: cannot configure warnings for the unrecognized C++ compiler front end ${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}")
119+
endif ()
120+
121+
# On Windows, if using Microsoft's the standard library, there is no `m.lib`.
122+
if (NOT WIN32 OR MINGW)
123+
target_link_libraries(Clipper2 PUBLIC -lm)
124+
endif ()
111125
endif()
112126

113127
set_target_properties(${CLIPPER2_LIBS} PROPERTIES FOLDER Libraries

0 commit comments

Comments
 (0)