Generated export header does not use custom file name for inclusion guard
Generated export header uses value of EXPORT_MACRO_NAME
instead of EXPORT_FILE_NAME
when generating inclusion guard.
CMakeLists.txt
:
cmake_minimum_required (VERSION 3.8 FATAL_ERROR)
include (GenerateExportHeader)
project("test_c_export")
add_library(test_lib SHARED test_lib.c test_lib.h)
GENERATE_EXPORT_HEADER (test_lib
EXPORT_FILE_NAME "generated_export.h"
EXPORT_MACRO_NAME SD_API
)
Current preamble looks like this:
#ifndef SD_API_H
#define SD_API_H
......
#endif
Macro name SD_API_H
is too short for the guard to be unique.
I suggest to use upper-cased EXPORT_FILE_NAME
and probably target name for more robustness:
#ifndef GENERATED_EXPORT_H
#define GENERATED_EXPORT_H
......
#endif // GENERATED_EXPORT_H
or
#ifndef TEST_LIB_GENERATED_EXPORT_H
#define TEST_LIB_GENERATED_EXPORT_H
......
#endif // TEST_LIB_GENERATED_EXPORT_H
Note that I also suggest to add comment to the final #endif
.