diff options
Diffstat (limited to 'examples/exe_with_static_libs/doctest_force_link_static_lib_in_target.cmake')
-rw-r--r-- | examples/exe_with_static_libs/doctest_force_link_static_lib_in_target.cmake | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/examples/exe_with_static_libs/doctest_force_link_static_lib_in_target.cmake b/examples/exe_with_static_libs/doctest_force_link_static_lib_in_target.cmake index 1192551..ecabc41 100644 --- a/examples/exe_with_static_libs/doctest_force_link_static_lib_in_target.cmake +++ b/examples/exe_with_static_libs/doctest_force_link_static_lib_in_target.cmake @@ -14,7 +14,7 @@ function(doctest_include_file_in_sources header sources) if(old_compile_flags STREQUAL "NOTFOUND") set(old_compile_flags "") endif() - + # update flags if(MSVC) set_source_files_properties(${src} PROPERTIES COMPILE_FLAGS @@ -49,7 +49,7 @@ function(doctest_force_link_static_lib_in_target target lib) set(dummy_dir ${BD}/${LIB_NAME}_DOCTEST_STATIC_LIB_FORCE_LINK_DUMMIES/) set(dummy_header ${dummy_dir}/all_dummies.h) file(MAKE_DIRECTORY ${dummy_dir}) - + # create a dummy header for each source file, include a dummy function in it and include it in the source file set(curr_dummy "0") set(DLL_PRIVATE "#ifndef _WIN32\n#define DLL_PRIVATE __attribute__ ((visibility (\"hidden\")))\n#else\n#define DLL_PRIVATE\n#endif\n\n") @@ -57,37 +57,37 @@ function(doctest_force_link_static_lib_in_target target lib) foreach(src ${lib_sources}) if(${src} MATCHES \\.\(cc|cp|cpp|CPP|c\\+\\+|cxx\)$) math(EXPR curr_dummy "${curr_dummy} + 1") - + set(curr_dummy_header ${dummy_dir}/dummy_${curr_dummy}.h) file(WRITE ${curr_dummy_header} "${DLL_PRIVATE}namespace doctest { namespace detail { DLL_PRIVATE int dummy_for_${LIB_NAME}_${curr_dummy}(); DLL_PRIVATE int dummy_for_${LIB_NAME}_${curr_dummy}() { return ${curr_dummy}; } } }\n") doctest_include_file_in_sources(${curr_dummy_header} ${src}) endif() endforeach() set(total_dummies ${curr_dummy}) - + # create the master dummy header file(WRITE ${dummy_header} "${DLL_PRIVATE}namespace doctest { namespace detail {\n\n") - + # forward declare the dummy functions in the master dummy header foreach(curr_dummy RANGE 1 ${total_dummies}) file(APPEND ${dummy_header} "DLL_PRIVATE int dummy_for_${LIB_NAME}_${curr_dummy}();\n") endforeach() - + # call the dummy functions in the master dummy header file(APPEND ${dummy_header} "\nDLL_PRIVATE int dummies_for_${LIB_NAME}();\nDLL_PRIVATE int dummies_for_${LIB_NAME}() {\n int res = 0;\n") foreach(curr_dummy RANGE 1 ${total_dummies}) file(APPEND ${dummy_header} " res += dummy_for_${LIB_NAME}_${curr_dummy}();\n") endforeach() file(APPEND ${dummy_header} " return res;\n}\n\n} } // namespaces\n") - + # set the dummy header property so we don't recreate the dummy headers the next time this macro is called for this library set_target_properties(${lib} PROPERTIES DOCTEST_DUMMY_HEADER ${dummy_header}) set(DDH ${dummy_header}) endif() - + get_target_property(DFLLTD ${target} DOCTEST_FORCE_LINKED_LIBRARIES_THROUGH_DUMMIES) get_target_property(target_sources ${target} SOURCES) - + if("${DFLLTD}" STREQUAL "DFLLTD-NOTFOUND") # if no library has been force linked to this target foreach(src ${target_sources}) @@ -96,7 +96,7 @@ function(doctest_force_link_static_lib_in_target target lib) break() endif() endforeach() - + # add the library as force linked to this target set_target_properties(${target} PROPERTIES DOCTEST_FORCE_LINKED_LIBRARIES_THROUGH_DUMMIES ${LIB_NAME}) else() @@ -109,7 +109,7 @@ function(doctest_force_link_static_lib_in_target target lib) break() endif() endforeach() - + # add this library to the list of force linked libraries for this target list(APPEND DFLLTD ${LIB_NAME}) set_target_properties(${target} PROPERTIES DOCTEST_FORCE_LINKED_LIBRARIES_THROUGH_DUMMIES "${DFLLTD}") |