Makefile modifications required for gcc >= 4.9 (fixes #981) #984
Conversation
By analyzing the blame information on this pull request, we identified @vitaly-krugl and @scottpurdy to be potential reviewers |
For the records: Don't try to use conditional statements within ExternalProject_Add() functions. |
I want to test this with Ubuntu 15 / 16 Monday. I will also ask @vitaly-krugl and @breznak to review. |
Great, thank you! I haven't had the chance to test the build in an Ubuntu 16.04./gcc 5.x environment yet, but a build on Ubuntu 15.10 amd64 (4.2.0-38-generic #45-Ubuntu SMP) with gcc version 4.9.3 performed well with all tests passed. |
Just tested: Ubuntu 16.04 amd64 fresh install w/ latest official updates (4.4.0-24-generic #43-Ubuntu SMP) Standard config/build procedure: Tests @rhyolight If you can confirm this on Monday, this means that nupic.core now builds on gcc versions 4.9 and 5.x (and the latest Ubuntu LTS version). |
set(aprlib_config_options ${aprlib_config_options} --enable-debug) | ||
endif() | ||
|
||
ExternalProject_Add(Apr1StaticLib |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just add this (and below) under the UNIX
IF() and add IF(gcc == 4.9)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I'll update the fix.
Great work @hstm ! We needed such patch very much for the coming OSes 👍 |
I just confirmed that this works on ubuntu 15 with GCC 4.9 and 5.2, and that's good enough for a 👍 from me. Would still like for @vitaly-krugl to review, if possible. |
Reviewing ... will add a comment when I'm done |
Pls fix indentations - use spaces instead of tabs. There are many tabs in the PR. |
@hstm, please hold off on pushing new commits to this PR until I let you know that I am completely done with this round of code review. Thx. |
# fixes #981 | ||
IF(UNIX AND CMAKE_COMPILER_IS_GNUCXX AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.9" OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "4.9")) | ||
set(CMAKE_AR "/usr/bin/gcc-ar") | ||
set(CMAKE_RANLIB "/usr/bin/gcc-ranlib") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both of these variables were already set in the top-level CMakeLists.txt. Shouldn't need to set here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, changes in external/CMakeLists.txt are obsolete. Will change that.
Since the new parameters are tied to LTO, and LTO optimization flags are set up in https://github.com/numenta/nupic.core/blob/master/CommonCompilerConfig.cmake, I think it's reasonable to expect that the correlated parameters should be set up in the same file for readability and maintainability. Here is what I am thinking:
This should also simplify many of the changes in external .cmake files. In particular, it should eliminate the duplications in the external .cmake files. |
Are AR and RANLIB set properly for src_lib_static_nupiccore_solo by cmake Or is this resolved by the new variables |
@hstm, thank you for your work in figuring out the necessary parameters. I am done with the first round of code review. Please see my feedback. |
There may be eventual merge and logic conflicts with #975. |
@vitaly-krugl Thanks for the review! |
Notes:
@vitaly-krugl Could you please have a look at the changes? Thx. |
@@ -91,6 +91,8 @@ set(EXTERNAL_CXX_FLAGS_OPTIMIZED) | |||
set(EXTERNAL_LINKER_FLAGS_UNOPTIMIZED) | |||
set(EXTERNAL_LINKER_FLAGS_OPTIMIZED) | |||
|
|||
set(COMMON_STATICLIB_CMAKE_DEFINITIONS_OPTIMIZED) | |||
set(COMMON_STATICLIB_CONFIGURE_DEFINITIONS_OPTIMIZED_STR "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file header contains documentation of each variable exported by this module. Pls document the two new variables there, too.
@hstm, I noticed that the new |
@hstm, I am done with the second round of code review. Please see my feedback. Thank you. |
@vitaly-krugl Thank you very much for the review. CapnProto is built without optimizations ( Just tried a build with gcc 4.9.3 and
Of course ar should be gcc-ar in this case, otherwise the build fails. This indicates that As a consequence, we have to keep the variables in CMakeLists.txt as well as both |
@vitaly-krugl We could possibly add |
@scottpurdy could have an opinion on this. |
@hstm, regarding
Let's leave |
@@ -220,6 +229,12 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") | |||
set(shared_linker_flags_unoptimized "${shared_linker_flags_unoptimized} -Wl,-undefined,error") | |||
endif() | |||
|
|||
# Compatibility with gcc >= 4.9 which requires the use of gcc's own wrappers for ar and ranlib in combination with LTO | |||
# works also with LTO disabled | |||
IF(UNIX AND CMAKE_COMPILER_IS_GNUCXX AND (NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.9" OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "4.9")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid duplication of logic, let's set CMAKE_AR
and CMAKE_RANLIB
here as well, instead of doing it separately in the root CMakeLists.txt.
Also, add a short explanatory comment to the effect that the repetition of these settings in EXTERNAL_STATICLIB_CMAKE_DEFINITIONS_OPTIMIZED
and EXTERNAL_STATICLIB_CONFIGURE_DEFINITIONS_OPTIMIZED_STR
are a workaround for a cmake bug related to propagation of CMAKE_AR (including a link to https://gitlab.kitware.com/cmake/cmake/issues/15547).
Also, document CMAKE_AR
and CMAKE_RANLIB
alongside the CMAKE_LINKER doc there.
@hstm, thanks for tracking down the |
@rhyolight I'll defer to @vitaly-krugl on this discussion. |
@vitaly-krugl Thanks for the review. I've just pushed the updated files:
Successfully tested with gcc 4.9.3 and 5.3.1. |
# INTERNAL_CXX_FLAGS_OPTIMIZED: string of C++ flags with explicit optimization flags for internal sources | ||
# | ||
# INTERNAL_LINKER_FLAGS_OPTIMIZED: string of linker flags for linking internal executables | ||
# and shared libraries (DLLs) with optimizations that are | ||
# compatible with INTERNAL_CXX_FLAGS_OPTIMIZED | ||
# | ||
# | ||
# CMAKE_LINKER: updated, if needed; use ld.gold if available. See cmake | ||
# documentation | ||
# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls add blurbs for CMAKE_AR
and CMAKE_RANLIB
in this documentation.
@hstm, LGTM after adding blurbs for |
@vitaly-krugl Done. |
@hstm, thank you for your effort and patience. @rhyolight: LGTM at 7028279 as soon as all tests pass. |
@hstm, this PR is merged - thank you! I verified the build and tests on Ubuntu 16.04 running in VirtualBox; gcc v5.3.1, python v2.7.11+. CC @rhyolight |
@vitaly-krugl Once again thank you for the reviews - the patch now looks much prettier than in my first version ;-) |
Fixes #981
This fix adds conditional cmake parameters that are required to build nupic.core with gcc version 4.9 (and higher) in combination with LTO (-flto). gcc >= 4.9 requires to use its own wrappers for ar, nm and ranlib instead of the regular binutils versions.