Index: build/premake/premake5.lua =================================================================== --- build/premake/premake5.lua +++ build/premake/premake5.lua @@ -109,6 +109,24 @@ end end +-- Test whether we need to link libatomic in clang +local link_atomic = false +if os.istarget("linux") and cc == "clang" then + local _, atomic_rc3 = os.outputof(cc .. " -o atomic2.o -c ./tests/atomic2.cpp") + if atomic_rc3 == 0 then + os.execute(cc .. " -o atomic1.o -c ./tests/atomic1.cpp 2>/dev/null") + local _, atomic_rc1 = os.outputof(cc .. " -o /dev/null -lstdc++ atomic1.o atomic2.o 2>/dev/null") + local _, atomic_rc2 = os.outputof(cc .. " -o /dev/null -lstdc++ -latomic atomic1.o atomic2.o 2>/dev/null") + if atomic_rc1 ~= 0 and atomic_rc2 == 0 then + link_atomic = true + end + os.remove("atomic1.o") + else + print("NOTICE: libatomic test skipped") + end + os.remove("atomic2.o") +end + -- Set up the Workspace workspace "pyrogenesis" targetdir(rootdir.."/binaries/system") @@ -1059,6 +1077,12 @@ } end + if link_atomic then + links { + "atomic" + } + end + if os.istarget("linux") or os.getversion().description == "GNU/kFreeBSD" then links { -- Dynamic libraries (needed for linking for gold) @@ -1411,6 +1435,11 @@ "execinfo" } end + if link_atomic then + links { + "atomic" + } + end if not _OPTIONS["android"] and not (os.getversion().description == "OpenBSD") then links { "rt" } end Index: build/premake/tests/atomic1.cpp =================================================================== --- /dev/null +++ build/premake/tests/atomic1.cpp @@ -0,0 +1,6 @@ +#include "atomic2.h" + +int main () +{ + return test(); +} Index: build/premake/tests/atomic2.h =================================================================== --- /dev/null +++ build/premake/tests/atomic2.h @@ -0,0 +1,4 @@ +#ifndef TEST +#define TEST +int test(); +#endif Index: build/premake/tests/atomic2.cpp =================================================================== --- /dev/null +++ build/premake/tests/atomic2.cpp @@ -0,0 +1,9 @@ +#include +#include + +int test() { + boost::lockfree::queue queue(128); + std::atomic test; + + return 123; +}