summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-05-12 18:10:06 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-05-12 18:10:06 +0200
commita82dfe5aa6df19296d148d9754d9c58e388b9155 (patch)
tree93edd41ed30e58f2029c17dc3f5c924b76c6f07d
parente2b1b2249024da9b2cc8cf4a6d5d1598bcd33eba (diff)
cmake: workaround LTO issue on Windows.
With the GNU toolchain there's some mix-up and the "opentrack_version" symbol isn't emitted into the object file at all. Disable LTO for the "version" statically linked library. The "version" statically linked library exists so that files needing the version only need to be re-linked, not recompiled. A preprocessor global -DVERSION=foo rebuilds the whole project after each commit. A header definition rebuilds all include sites. LTO in the GNU toolchain is very broken on Windows, particular the interaction of GCC "linker plugin" injected into Binutils bfd ld. The gold ld we can't use since it's only for ELF executables. There's nothing alarming here at all unless there's some miscompilation and there doesn't seem to be any. The rest of the functional changes is changing cc -> c of that object file, and moving library definition after the source file is already generated.
-rwxr-xr-xcmake/opentrack-version.cmake17
1 files changed, 11 insertions, 6 deletions
diff --git a/cmake/opentrack-version.cmake b/cmake/opentrack-version.cmake
index 9a311ff9..d753535f 100755
--- a/cmake/opentrack-version.cmake
+++ b/cmake/opentrack-version.cmake
@@ -18,14 +18,13 @@ endif()
file(WRITE ${CMAKE_BINARY_DIR}/opentrack-version.h "#define OPENTRACK_VERSION \"${_build_type}${OPENTRACK_COMMIT}\"")
-add_library(opentrack-version STATIC ${CMAKE_BINARY_DIR}/version.cc)
-opentrack_compat(opentrack-version)
-
set(version-string "
#include \"opentrack-compat/export.hpp\"
#ifdef __cplusplus
extern \"C\"
+#else
+extern
#endif
OPENTRACK_EXPORT
const char* opentrack_version;
@@ -34,10 +33,16 @@ const char* opentrack_version = \"${_build_type}${OPENTRACK_COMMIT}\";
")
set(crapola-ver)
-if(EXISTS ${CMAKE_BINARY_DIR}/version.cc)
- file(READ ${CMAKE_BINARY_DIR}/version.cc crapola-ver)
+if(EXISTS ${CMAKE_BINARY_DIR}/version.c)
+ file(READ ${CMAKE_BINARY_DIR}/version.c crapola-ver)
endif()
if(NOT (crapola-ver STREQUAL version-string))
- file(WRITE ${CMAKE_BINARY_DIR}/version.cc "${version-string}")
+ file(WRITE ${CMAKE_BINARY_DIR}/version.c "${version-string}")
endif()
+
+add_library(opentrack-version STATIC ${CMAKE_BINARY_DIR}/version.c)
+if(NOT MSVC)
+ SET_TARGET_PROPERTIES(opentrack-version PROPERTIES COMPILE_FLAGS "-fno-lto")
+endif()
+opentrack_compat(opentrack-version)