diff --git a/CMakeLists.txt b/CMakeLists.txt index 745e52f..0f32f2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,16 @@ if (ENABLE_SANITIZERS) ) endif() +option(ENABLE_PUBLIC_SYMBOLS "Export library symbols." On) +if (ENABLE_PUBLIC_SYMBOLS) + list(APPEND custom_compiler_flags -fvisibility=hidden) + add_definitions(-DCJSON_EXPORT_SYMBOLS -DCJSON_API_VISIBILITY) +endif() +option(ENABLE_HIDDEN_SYMBOLS "Hide library symbols." Off) +if (ENABLE_HIDDEN_SYMBOLS) + add_definitions(-DCJSON_HIDE_SYMBOLS -UCJSON_API_VISIBILITY) +endif() + # apply custom compiler flags foreach(compiler_flag ${custom_compiler_flags}) #remove problematic characters diff --git a/cJSON.c b/cJSON.c index af93a8a..766b0f7 100644 --- a/cJSON.c +++ b/cJSON.c @@ -23,6 +23,7 @@ /* cJSON */ /* JSON parser in C. */ +#pragma GCC visibility push(default) #include #include #include @@ -30,6 +31,8 @@ #include #include #include +#pragma GCC visibility pop + #include "cJSON.h" /* define our own boolean type */ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4767e50..f9cd564 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,6 +7,11 @@ if(ENABLE_CJSON_TEST) if (werror_found) target_compile_options(unity PRIVATE "-Wno-error") endif() + # Disable -fvisibility=hidden for Unity + list(FIND custom_compiler_flags "-fvisibility=hidden" visibility_found) + if (visibility_found) + target_compile_options(unity PRIVATE "-fvisibility=default") + endif() #copy test files file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/inputs")