Skip to content

Commit 2766513

Browse files
committed
cmake: Add SECP256K1_C_FLAGS configure option
1 parent 464a911 commit 2766513

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,14 @@ if(SECP256K1_BUILD_BENCHMARK OR SECP256K1_BUILD_TESTS OR SECP256K1_BUILD_EXHAUST
216216
enable_testing()
217217
endif()
218218

219+
set(SECP256K1_C_FLAGS "" CACHE STRING "Compiler flags that can override flags set by the build system.")
220+
include(AllTargetsCompileOptions)
221+
219222
add_subdirectory(src)
223+
all_targets_compile_options(src "${SECP256K1_C_FLAGS}")
220224
if(SECP256K1_BUILD_EXAMPLES)
221225
add_subdirectory(examples)
226+
all_targets_compile_options(examples "${SECP256K1_C_FLAGS}")
222227
endif()
223228

224229
message("\n")
@@ -286,6 +291,9 @@ else()
286291
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
287292
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
288293
endif()
294+
if(SECP256K1_C_FLAGS)
295+
message("SECP256K1_C_FLAGS ..................... ${SECP256K1_C_FLAGS}")
296+
endif()
289297
message("\n")
290298
if(SECP256K1_EXPERIMENTAL)
291299
message(

cmake/AllTargetsCompileOptions.cmake

Lines changed: 12 additions & 0 deletions
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)