diff --git a/CMakeLists.txt b/CMakeLists.txt index 119440982..1ff122e4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,20 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD_REQUIRED ON) + +# In order to be able to link with other shared libraries on Linux we may need `-fPIC`. +if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + # using Clang + add_compile_options(-fPIC) +elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + # using GCC + add_compile_options(-fPIC) +elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") + # using Intel C++ +elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + # using Visual Studio C++ +endif() + # Variables for library names, source files, etc. set(WEBUI_DEFAULT_OUT_LIB_NAME "webui-2") @@ -118,4 +132,4 @@ if (WEBUI_BUILD_EXAMPLES) if (MSVC) set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT call_js_from_cpp) endif() -endif() \ No newline at end of file +endif()