Skip to content

Commit a3de2c9

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 a3de2c9

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

CMakeLists.txt

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -280,19 +280,21 @@ 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+
if(CMAKE_GENERATOR MATCHES "Make|Ninja")
284+
# Only command-line build tool generators support low-level rule
285+
# variables.
286+
# Appending to the low-level rule variables is the only way to
286287
# guarantee that the flags appear at the end of the command line.
287-
string(APPEND CMAKE_C_COMPILE_OBJECT " ${SECP256K1_APPEND_CFLAGS}")
288-
endif()
288+
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.")
289+
if(SECP256K1_APPEND_CFLAGS)
290+
string(APPEND CMAKE_C_COMPILE_OBJECT " ${SECP256K1_APPEND_CFLAGS}")
291+
endif()
289292

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}")
293+
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.")
294+
if(SECP256K1_APPEND_LDFLAGS)
295+
string(APPEND CMAKE_C_CREATE_SHARED_LIBRARY " ${SECP256K1_APPEND_LDFLAGS}")
296+
string(APPEND CMAKE_C_LINK_EXECUTABLE " ${SECP256K1_APPEND_LDFLAGS}")
297+
endif()
296298
endif()
297299

298300
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
@@ -381,11 +383,13 @@ else()
381383
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
382384
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
383385
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}")
386+
if(CMAKE_GENERATOR MATCHES "Make|Ninja")
387+
if(SECP256K1_APPEND_CFLAGS)
388+
message("SECP256K1_APPEND_CFLAGS ............... ${SECP256K1_APPEND_CFLAGS}")
389+
endif()
390+
if(SECP256K1_APPEND_LDFLAGS)
391+
message("SECP256K1_APPEND_LDFLAGS .............. ${SECP256K1_APPEND_LDFLAGS}")
392+
endif()
389393
endif()
390394
message("")
391395
if(print_msan_notice)

0 commit comments

Comments
 (0)