diff --git a/CMakeLists.txt b/CMakeLists.txt
index fe353a650474cbe08b14aa1b8123e73e4dbd4eeb..40d8837f41bdc0d8dfd7eac1c5960064967f1efb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -66,9 +66,13 @@ endif()
 
 target_compile_features(${module_name} PRIVATE cxx_std_14)
 
+# -fvisibility=hidden required by pybind11
+target_compile_options(${module_name} PUBLIC
+    $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
+    -fvisibility=hidden>)
 target_compile_options(${module_name} PRIVATE
     $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-    -Wall -Wextra -Wold-style-cast -Winline -pedantic -Werror=narrowing -fvisibility=hidden -Wshadow $<$<BOOL:${WERROR}>:-Werror>>)
+    -Wall -Wextra -Wold-style-cast -Winline -pedantic -Werror=narrowing -Wshadow $<$<BOOL:${WERROR}>:-Werror>>)
 target_compile_options(${module_name} PRIVATE
     $<$<CXX_COMPILER_ID:MSVC>:
     /W4>)