@@ -23,14 +23,20 @@ if(WIN32 AND NOT MINGW)
2323 set (CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
2424endif ()
2525
26- if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
26+ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
2727 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS } -fstandalone-debug" )
2828endif ()
29+ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
30+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS } -Wno-unused-parameter -Wno-conversion -Wno-extra-semi" )
31+ endif ()
2932
3033include_directories (include src )
3134include_directories (deps/cppdecl/include )
3235
3336
37+ option (MRBIND_STATIC_BUILD "Build the parser and the generators as static binaries." OFF )
38+
39+
3440add_library (mrbind_common STATIC
3541 src/common/command_line_args_as_utf8.cpp
3642 src/common/command_line_parser.cpp
@@ -55,7 +61,7 @@ if(MRBIND_BUILD_PARSER)
5561 src/parser/multiplex_data.cpp
5662 )
5763
58- if (CMAKE_CXX_COMPILER_ID STREQUAL "GCC " OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
64+ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU " OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
5965 set_source_files_properties (src/parser/disable_rtti.cpp PROPERTIES COMPILE_FLAGS -fno-rtti)
6066 endif ()
6167
@@ -65,11 +71,19 @@ if(MRBIND_BUILD_PARSER)
6571
6672 target_include_directories (mrbind PRIVATE ${LLVM_INCLUDE_DIR} ${CLANG_INCLUDE_DIR} )
6773
68- # Clang lets you choose between large dynamic libraries, and fine-grained static libraries.
69- # Those are the large dynamic ones. If they are not available for some reason,
70- # we could switch to the static ones (probably conditionally here in CMake, by checking what's available).
71- # See the git history to see some related static library names.
72- target_link_libraries (mrbind PRIVATE LLVM clang-cpp )
74+ if (MRBIND_STATIC_BUILD)
75+ target_link_libraries (mrbind PRIVATE -static-libstdc++ -static-libgcc )
76+ if (NOT TARGET clangTooling)
77+ message (FATAL_ERROR "clangTooling is required for static builds" )
78+ endif ()
79+ target_link_libraries (mrbind PRIVATE clangTooling )
80+ else ()
81+ # Clang lets you choose between large dynamic libraries, and fine-grained static libraries.
82+ # Those are the large dynamic ones. If they are not available for some reason,
83+ # we could switch to the static ones (probably conditionally here in CMake, by checking what's available).
84+ # See the git history to see some related static library names.
85+ target_link_libraries (mrbind PRIVATE LLVM clang-cpp )
86+ endif ()
7387endif ()
7488
7589
@@ -123,6 +137,9 @@ if(MRBIND_BUILD_GENERATOR_C)
123137 mrbind_gen_common
124138 mrbind_c_interop
125139 )
140+ if (MRBIND_STATIC_BUILD)
141+ target_link_libraries (mrbind_gen_c PRIVATE -static-libstdc++ -static-libgcc )
142+ endif ()
126143endif ()
127144
128145if (MRBIND_BUILD_GENERATOR_CSHARP)
@@ -138,4 +155,7 @@ if(MRBIND_BUILD_GENERATOR_CSHARP)
138155 mrbind_gen_common
139156 mrbind_c_interop
140157 )
158+ if (MRBIND_STATIC_BUILD)
159+ target_link_libraries (mrbind_gen_csharp PRIVATE -static-libstdc++ -static-libgcc )
160+ endif ()
141161endif ()
0 commit comments