Skip to content

Commit 0be7d3d

Browse files
committed
cmake: Enable APPEND_*FLAGS only for command-line generators
Command-line build tool generators are the only ones that support low-level rule variables. IDE build tool generators, such as "Visual Studio" and "Xcode", do not utilize these variables when creating project files. This change ensures that CMake warns users if any of the `SECP256K1_APPEND_*FLAGS` options are set while using an unsupported generator.
1 parent f79f46c commit 0be7d3d

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

CMakeLists.txt

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -280,19 +280,20 @@ if(SECP256K1_BUILD_CTIME_TESTS)
280280
unset(msan_enabled)
281281
endif()
282282

283-
set(SECP256K1_APPEND_CFLAGS "" CACHE STRING "Compiler flags that are appended to the command line after all other flags added by the build system. This variable is intended for debugging and special builds.")
284-
if(SECP256K1_APPEND_CFLAGS)
285-
# Appending to this low-level rule variable is the only way to
283+
# Only some generators use low-level rule variables.
284+
if(CMAKE_GENERATOR MATCHES "Make|Ninja")
285+
# Appending to the low-level rule variables is the only way to
286286
# guarantee that the flags appear at the end of the command line.
287-
string(APPEND CMAKE_C_COMPILE_OBJECT " ${SECP256K1_APPEND_CFLAGS}")
288-
endif()
287+
set(SECP256K1_APPEND_CFLAGS "" CACHE STRING "Compiler flags that are appended to the command line after all other flags added by the build system. This variable is intended for debugging and special builds.")
288+
if(SECP256K1_APPEND_CFLAGS)
289+
string(APPEND CMAKE_C_COMPILE_OBJECT " ${SECP256K1_APPEND_CFLAGS}")
290+
endif()
289291

290-
set(SECP256K1_APPEND_LDFLAGS "" CACHE STRING "Linker flags that are appended to the command line after all other flags added by the build system. This variable is intended for debugging and special builds.")
291-
if(SECP256K1_APPEND_LDFLAGS)
292-
# Appending to this low-level rule variable is the only way to
293-
# guarantee that the flags appear at the end of the command line.
294-
string(APPEND CMAKE_C_CREATE_SHARED_LIBRARY " ${SECP256K1_APPEND_LDFLAGS}")
295-
string(APPEND CMAKE_C_LINK_EXECUTABLE " ${SECP256K1_APPEND_LDFLAGS}")
292+
set(SECP256K1_APPEND_LDFLAGS "" CACHE STRING "Linker flags that are appended to the command line after all other flags added by the build system. This variable is intended for debugging and special builds.")
293+
if(SECP256K1_APPEND_LDFLAGS)
294+
string(APPEND CMAKE_C_CREATE_SHARED_LIBRARY " ${SECP256K1_APPEND_LDFLAGS}")
295+
string(APPEND CMAKE_C_LINK_EXECUTABLE " ${SECP256K1_APPEND_LDFLAGS}")
296+
endif()
296297
endif()
297298

298299
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
@@ -381,11 +382,13 @@ else()
381382
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
382383
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
383384
endif()
384-
if(SECP256K1_APPEND_CFLAGS)
385-
message("SECP256K1_APPEND_CFLAGS ............... ${SECP256K1_APPEND_CFLAGS}")
386-
endif()
387-
if(SECP256K1_APPEND_LDFLAGS)
388-
message("SECP256K1_APPEND_LDFLAGS .............. ${SECP256K1_APPEND_LDFLAGS}")
385+
if(CMAKE_GENERATOR MATCHES "Make|Ninja")
386+
if(SECP256K1_APPEND_CFLAGS)
387+
message("SECP256K1_APPEND_CFLAGS ............... ${SECP256K1_APPEND_CFLAGS}")
388+
endif()
389+
if(SECP256K1_APPEND_LDFLAGS)
390+
message("SECP256K1_APPEND_LDFLAGS .............. ${SECP256K1_APPEND_LDFLAGS}")
391+
endif()
389392
endif()
390393
message("")
391394
if(print_msan_notice)

0 commit comments

Comments
 (0)