Skip to content

Commit 42f8c51

Browse files
committed
cmake: Add SECP256K1_LATE_CFLAGS configure option
1 parent 1f33bb2 commit 42f8c51

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,14 @@ if(SECP256K1_BUILD_BENCHMARK OR SECP256K1_BUILD_TESTS OR SECP256K1_BUILD_EXHAUST
217217
enable_testing()
218218
endif()
219219

220+
set(SECP256K1_LATE_CFLAGS "" CACHE STRING "Compiler flags that are added to the command line after all other flags added by the build system.")
221+
include(AllTargetsCompileOptions)
222+
220223
add_subdirectory(src)
224+
all_targets_compile_options(src "${SECP256K1_LATE_CFLAGS}")
221225
if(SECP256K1_BUILD_EXAMPLES)
222226
add_subdirectory(examples)
227+
all_targets_compile_options(examples "${SECP256K1_LATE_CFLAGS}")
223228
endif()
224229

225230
message("\n")
@@ -292,6 +297,9 @@ else()
292297
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
293298
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
294299
endif()
300+
if(SECP256K1_LATE_CFLAGS)
301+
message("SECP256K1_LATE_CFLAGS ................. ${SECP256K1_LATE_CFLAGS}")
302+
endif()
295303
message("\n")
296304
if(SECP256K1_EXPERIMENTAL)
297305
message(

cmake/AllTargetsCompileOptions.cmake

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Add compile options to all targets added in the subdirectory.
2+
function(all_targets_compile_options dir options)
3+
get_directory_property(targets DIRECTORY ${dir} BUILDSYSTEM_TARGETS)
4+
separate_arguments(options)
5+
set(compiled_target_types STATIC_LIBRARY SHARED_LIBRARY OBJECT_LIBRARY EXECUTABLE)
6+
foreach(target ${targets})
7+
get_target_property(type ${target} TYPE)
8+
if(type IN_LIST compiled_target_types)
9+
target_compile_options(${target} PRIVATE ${options})
10+
endif()
11+
endforeach()
12+
endfunction()

0 commit comments

Comments
 (0)