cmake: Build libcriterion.so as an executable PIE
This commit is contained in:
parent
b29e662432
commit
8959dfa83f
3 changed files with 14 additions and 25 deletions
|
@ -26,7 +26,7 @@ function (cr_link_libraries _TARGET)
|
|||
endfunction ()
|
||||
|
||||
function (cr_add_library _LIB)
|
||||
set (options SHARED STATIC)
|
||||
set (options SHARED STATIC RUNNABLE)
|
||||
set (oneValueArgs COMPONENT)
|
||||
set (multiValueArgs SOURCES HEADERS PROPERTIES)
|
||||
cmake_parse_arguments (ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
@ -38,7 +38,18 @@ function (cr_add_library _LIB)
|
|||
set (flags ${flags} STATIC)
|
||||
endif ()
|
||||
|
||||
add_library(${_LIB} ${flags} ${ARGS_SOURCES} ${ARGS_HEADERS})
|
||||
if (ARGS_RUNNABLE AND ARGS_SHARED)
|
||||
include (CheckCCompilerFlag)
|
||||
check_c_compiler_flag("-fPIC -pie -Wl,-E" COMPILER_HAS_PIE)
|
||||
endif ()
|
||||
|
||||
if (ARGS_RUNNABLE AND ARGS_SHARED AND COMPILER_HAS_PIE)
|
||||
string (REPLACE "-shared" "-pie -Wl,-E" CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}")
|
||||
set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}" PARENT_SCOPE)
|
||||
add_library(${_LIB} SHARED ${ARGS_SOURCES} ${ARGS_HEADERS})
|
||||
else ()
|
||||
add_library(${_LIB} ${flags} ${ARGS_SOURCES} ${ARGS_HEADERS})
|
||||
endif ()
|
||||
set_target_properties(${_LIB} PROPERTIES ${ARGS_PROPERTIES})
|
||||
|
||||
foreach (F ${INTERFACE_FILES})
|
||||
|
|
|
@ -104,6 +104,7 @@ cr_add_library(criterion SHARED
|
|||
PROPERTIES
|
||||
VERSION ${PROJECT_SONAME}
|
||||
SOVERSION ${PROJECT_SOVERSION}
|
||||
RUNNABLE
|
||||
)
|
||||
|
||||
cr_link_subproject(criterion csptr STATIC)
|
||||
|
|
|
@ -62,26 +62,3 @@ IMPL_CALL_REPORT_HOOKS(POST_TEST)
|
|||
IMPL_CALL_REPORT_HOOKS(POST_FINI)
|
||||
IMPL_CALL_REPORT_HOOKS(POST_SUITE)
|
||||
IMPL_CALL_REPORT_HOOKS(POST_ALL)
|
||||
|
||||
ReportHook(PRE_ALL)(CR_UNUSED struct criterion_test_set *arg) {
|
||||
}
|
||||
ReportHook(PRE_SUITE)(CR_UNUSED struct criterion_suite_set *arg) {
|
||||
}
|
||||
ReportHook(PRE_INIT)(CR_UNUSED struct criterion_test *arg) {
|
||||
}
|
||||
ReportHook(PRE_TEST)(CR_UNUSED struct criterion_test *arg) {
|
||||
}
|
||||
ReportHook(ASSERT)(CR_UNUSED struct criterion_assert_stats *arg) {
|
||||
}
|
||||
ReportHook(THEORY_FAIL)(CR_UNUSED struct criterion_theory_stats *arg) {
|
||||
}
|
||||
ReportHook(TEST_CRASH)(CR_UNUSED struct criterion_test_stats *arg) {
|
||||
}
|
||||
ReportHook(POST_TEST)(CR_UNUSED struct criterion_test_stats *arg) {
|
||||
}
|
||||
ReportHook(POST_FINI)(CR_UNUSED struct criterion_test_stats *arg) {
|
||||
}
|
||||
ReportHook(POST_SUITE)(CR_UNUSED struct criterion_suite_stats *arg) {
|
||||
}
|
||||
ReportHook(POST_ALL)(CR_UNUSED struct criterion_global_stats *arg) {
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue