Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Makefile modifications required for gcc >= 4.9 (fixes #981) #984

Merged
merged 8 commits into from Jun 22, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ set(CMAKE_VERBOSE_MAKEFILE OFF)

get_filename_component(REPOSITORY_DIR ${PROJECT_SOURCE_DIR} ABSOLUTE)

# gcc v4.9 requires its own binutils-wrappers for LTO (flag -flto)
# fixes #981
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux" 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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the intention was that these variables - CMAKE_RANLIB and CMAKE_AR would be used in other modules, but the variables aren't used anywhere, and each of the modules presently uses "/usr/bin/gcc-ar" and "/usr/bin/gcc-ranlib" verbatim, which doesn't sound right.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove the absolute path in CMAKE_AR and CMAKE_RANLIB.
Both variables seem to be used in the config process (if you remove the variables, you'll get a lot of "lto plugin needed" errors and build fails).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The absolute paths for "/usr/bin/gcc-ar" and "/usr/bin/gcc-ranlib" may be a bad idea, since it only works if the toolchain is installed using those absolute paths versus relying on the environment. Those absolute paths may work in your deployment, but could fail for others. Also, your changes in Apr1Lib.cmake and AprUtil1Lib.cmake don't use absolute paths.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you have these variables defined at root level, are the explicit -DCMAKE_AR= and -DCMAKE_RANLIB= in external .cmake files actually needed?

Perhaps it would suffice to set up CMAKE_AR and CMAKE_RANLIB in CommonCompilerConfig.cmake, with the exception of Apr1 and AprUtil1 external libs, which are configure-based and don't use cmake? In that case, you probably won't need the COMMON_STATICLIB_CMAKE_DEFINITIONS_OPTIMIZED suggested in my comment #984 (comment).

ENDIF()

if( POLICY CMP0046 )
cmake_policy(VERSION 2.8)
Expand Down
30 changes: 28 additions & 2 deletions external/Apr1Lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,35 @@ set(aprlib_cflags "${EXTERNAL_C_FLAGS_OPTIMIZED} ${COMMON_COMPILER_DEFINITIONS_S
# Location of apr sources
set(aprlib_url "${REPOSITORY_DIR}/external/common/share/apr/unix/apr-1.5.2.tar.gz")

# gcc v4.9 requires its own binutils-wrappers for LTO (flag -flto)
# fixes #981
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.9" OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "4.9"))
set(aprlib_config_options --enable-static --disable-shared --disable-ipv6)

if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(aprlib_config_options ${aprlib_config_options} --enable-debug)
endif()

ExternalProject_Add(Apr1StaticLib
Copy link
Member

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)?

Copy link
Author

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.

URL ${aprlib_url}

UPDATE_COMMAND ""
PATCH_COMMAND ""

CONFIGURE_COMMAND
<SOURCE_DIR>/configure AR=gcc-ar NM=gcc-nm RANLIB=gcc-ranlib
--prefix=${aprlib_install_prefix}
${aprlib_config_options}
CFLAGS=${aprlib_cflags}

BUILD_COMMAND
make -f Makefile all

INSTALL_COMMAND
make -f Makefile install
)
# Get it built!
if (UNIX)
elseif (UNIX)
set(aprlib_config_options --enable-static --disable-shared --disable-ipv6)

if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
Expand Down Expand Up @@ -89,7 +116,6 @@ else()
-DCMAKE_INSTALL_PREFIX=${aprlib_install_prefix}
-DINSTALL_PDB=OFF


#LOG_INSTALL 1
)

Expand Down
29 changes: 28 additions & 1 deletion external/AprUtil1Lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,34 @@ set(aprutillib_cflags "${EXTERNAL_C_FLAGS_OPTIMIZED} ${COMMON_COMPILER_DEFINITIO

set(aprutillib_url "${REPOSITORY_DIR}/external/common/share/apr-util/unix/apr-util-1.5.4.tar.gz")

if (UNIX)
# gcc v4.9 requires its own binutils-wrappers for LTO (flag -flto)
# fixes #981
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.9" OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "4.9"))
set(aprutillib_config_options
--disable-util-dso --with-apr=${LIB_STATIC_APR1_INC_DIR}/..)

ExternalProject_Add(AprUtil1StaticLib
DEPENDS Apr1StaticLib

URL ${aprutillib_url}

UPDATE_COMMAND ""
PATCH_COMMAND ""

CONFIGURE_COMMAND
<SOURCE_DIR>/configure AR=gcc-ar NM=gcc-nm RANLIB=gcc-ranlib
--prefix=${aprutillib_install_prefix}
${aprutillib_config_options}
CFLAGS=${aprutillib_cflags}

BUILD_COMMAND
make -f Makefile all

INSTALL_COMMAND
make -f Makefile install
)

elseif (UNIX)
set(aprutillib_config_options
--disable-util-dso --with-apr=${LIB_STATIC_APR1_INC_DIR}/..)

Expand Down
7 changes: 7 additions & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ project(nupic_core_main CXX)

set(CMAKE_VERBOSE_MAKEFILE OFF)

# gcc v4.9 requires its own binutils-wrappers for LTO (flag -flto)
# fixes #981
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux" 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")
Copy link
Member

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.

Copy link
Author

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.

ENDIF()

set_directory_properties(PROPERTIES EP_BASE "${EP_BASE}")

# Shorter aliases for static library prefix and suffix.
Expand Down
51 changes: 37 additions & 14 deletions external/CapnProto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,44 @@ set(capnp_linker_flags "${EXTERNAL_LINKER_FLAGS_UNOPTIMIZED}")
# Print diagnostic info to debug whether -fuse-linker-plugin is being suppressed
message(STATUS "CapnProto CXX_FLAGS=${capnp_cxx_flags}")

ExternalProject_Add(CapnProto
URL ${capnproto_lib_url}
# gcc v4.9 requires its own binutils-wrappers for LTO (flag -flto)
# fixes #981
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.9" OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "4.9"))
ExternalProject_Add(CapnProto
URL ${capnproto_lib_url}

UPDATE_COMMAND ""

CMAKE_GENERATOR ${CMAKE_GENERATOR}

CMAKE_ARGS
${CAPNP_CMAKE_DEFINITIONS}
-DBUILD_SHARED_LIBS=OFF
-DBUILD_TESTING=OFF
-DCMAKE_CXX_FLAGS=${capnp_cxx_flags}
-DCMAKE_EXE_LINKER_FLAGS=${capnp_linker_flags}
-DCMAKE_INSTALL_PREFIX=${EP_BASE}/Install
-DCMAKE_AR=/usr/bin/gcc-ar
-DCMAKE_RANLIB=/usr/bin/gcc-ranlib
)
ELSE()
ExternalProject_Add(CapnProto
URL ${capnproto_lib_url}

UPDATE_COMMAND ""

CMAKE_GENERATOR ${CMAKE_GENERATOR}

CMAKE_ARGS
${CAPNP_CMAKE_DEFINITIONS}
-DBUILD_SHARED_LIBS=OFF
-DBUILD_TESTING=OFF
-DCMAKE_CXX_FLAGS=${capnp_cxx_flags}
-DCMAKE_EXE_LINKER_FLAGS=${capnp_linker_flags}
-DCMAKE_INSTALL_PREFIX=${EP_BASE}/Install
)
ENDIF()

UPDATE_COMMAND ""

CMAKE_GENERATOR ${CMAKE_GENERATOR}

CMAKE_ARGS
${CAPNP_CMAKE_DEFINITIONS}
-DBUILD_SHARED_LIBS=OFF
-DBUILD_TESTING=OFF
-DCMAKE_CXX_FLAGS=${capnp_cxx_flags}
-DCMAKE_EXE_LINKER_FLAGS=${capnp_linker_flags}
-DCMAKE_INSTALL_PREFIX=${EP_BASE}/Install
)

if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
# Install prebuilt Cap'n Proto compilers for Windows
Expand Down
44 changes: 33 additions & 11 deletions external/YamlCppLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,40 @@ set(LIB_STATIC_YAML_CPP_LOC "${yamlcpplib_install_lib_dir}/${STATIC_PRE}yaml-cpp
set(c_flags "${EXTERNAL_C_FLAGS_OPTIMIZED} ${COMMON_COMPILER_DEFINITIONS_STR}")
set(cxx_flags "${EXTERNAL_CXX_FLAGS_OPTIMIZED} ${COMMON_COMPILER_DEFINITIONS_STR}")

ExternalProject_Add(YamlCppStaticLib
DEPENDS YamlStaticLib
# gcc v4.9 requires its own binutils-wrappers for LTO (flag -flto)
# fixes #981
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.9" OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "4.9"))
ExternalProject_Add(YamlCppStaticLib
DEPENDS YamlStaticLib

URL ${yamlcpplib_url}
URL ${yamlcpplib_url}

UPDATE_COMMAND ""
UPDATE_COMMAND ""

CMAKE_GENERATOR ${CMAKE_GENERATOR}
CMAKE_GENERATOR ${CMAKE_GENERATOR}

CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_C_FLAGS=${c_flags}
-DCMAKE_CXX_FLAGS=${cxx_flags}
-DCMAKE_INSTALL_PREFIX=${yamlcpplib_install_prefix}
)
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_C_FLAGS=${c_flags}
-DCMAKE_CXX_FLAGS=${cxx_flags}
-DCMAKE_INSTALL_PREFIX=${yamlcpplib_install_prefix}
-DCMAKE_AR=/usr/bin/gcc-ar
-DCMAKE_RANLIB=/usr/bin/gcc-ranlib
)
ELSE()
ExternalProject_Add(YamlCppStaticLib
DEPENDS YamlStaticLib

URL ${yamlcpplib_url}

UPDATE_COMMAND ""

CMAKE_GENERATOR ${CMAKE_GENERATOR}

CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_C_FLAGS=${c_flags}
-DCMAKE_CXX_FLAGS=${cxx_flags}
-DCMAKE_INSTALL_PREFIX=${yamlcpplib_install_prefix}
)
ENDIF()
44 changes: 33 additions & 11 deletions external/YamlLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,40 @@ set(LIB_STATIC_YAML_LOC "${yamllib_build_dir}/${STATIC_PRE}yaml${STATIC_SUF}")

set(c_flags "${EXTERNAL_C_FLAGS_OPTIMIZED} ${COMMON_COMPILER_DEFINITIONS_STR}")

ExternalProject_Add(YamlStaticLib
URL ${yamllib_url}
# gcc v4.9 requires its own binutils-wrappers for LTO (flag -flto)
# fixes #981
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.9" OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "4.9"))
ExternalProject_Add(YamlStaticLib
URL ${yamllib_url}

UPDATE_COMMAND ""
UPDATE_COMMAND ""

# NOTE Yaml provides no rule for install
INSTALL_COMMAND ""
# NOTE Yaml provides no rule for install
INSTALL_COMMAND ""

CMAKE_GENERATOR ${CMAKE_GENERATOR}
CMAKE_GENERATOR ${CMAKE_GENERATOR}

CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_C_FLAGS=${c_flags}
-DCMAKE_INSTALL_PREFIX=${yamllib_build_dir}
)
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_C_FLAGS=${c_flags}
-DCMAKE_INSTALL_PREFIX=${yamllib_build_dir}
-DCMAKE_AR=/usr/bin/gcc-ar
-DCMAKE_RANLIB=/usr/bin/gcc-ranlib
)
ELSE()
ExternalProject_Add(YamlStaticLib
URL ${yamllib_url}

UPDATE_COMMAND ""

# NOTE Yaml provides no rule for install
INSTALL_COMMAND ""

CMAKE_GENERATOR ${CMAKE_GENERATOR}

CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_C_FLAGS=${c_flags}
-DCMAKE_INSTALL_PREFIX=${yamllib_build_dir}
)
ENDIF()
52 changes: 38 additions & 14 deletions external/Zlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,44 @@ set(LIB_STATIC_Z_LOC "${zlib_install_lib_dir}/${STATIC_PRE}${zlib_output_root}${

set(c_flags "${EXTERNAL_C_FLAGS_OPTIMIZED} ${COMMON_COMPILER_DEFINITIONS_STR}")

ExternalProject_Add(ZStaticLib
URL ${zlib_url}
# gcc v4.9 requires its own binutils-wrappers for LTO (flag -flto)
# fixes #981
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.9" OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "4.9"))
ExternalProject_Add(ZStaticLib
URL ${zlib_url}

UPDATE_COMMAND ""
UPDATE_COMMAND ""

CMAKE_GENERATOR ${CMAKE_GENERATOR}
CMAKE_GENERATOR ${CMAKE_GENERATOR}

CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_C_FLAGS=${c_flags}
-DCMAKE_INSTALL_PREFIX=${zlib_install_prefix}
-DINSTALL_BIN_DIR=${zlib_install_prefix}/bin
-DINSTALL_INC_DIR=${LIB_STATIC_Z_INC_DIR}
-DINSTALL_LIB_DIR=${zlib_install_lib_dir}
-DINSTALL_MAN_DIR=${zlib_install_prefix}/man
-DINSTALL_PKGCONFIG_DIR=${zlib_install_prefix}/pkgconfig
)
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_C_FLAGS=${c_flags}
-DCMAKE_INSTALL_PREFIX=${zlib_install_prefix}
-DINSTALL_BIN_DIR=${zlib_install_prefix}/bin
-DINSTALL_INC_DIR=${LIB_STATIC_Z_INC_DIR}
-DINSTALL_LIB_DIR=${zlib_install_lib_dir}
-DINSTALL_MAN_DIR=${zlib_install_prefix}/man
-DINSTALL_PKGCONFIG_DIR=${zlib_install_prefix}/pkgconfig
-DCMAKE_AR=/usr/bin/gcc-ar
-DCMAKE_RANLIB=/usr/bin/gcc-ranlib
)
ELSE()
ExternalProject_Add(ZStaticLib
URL ${zlib_url}

UPDATE_COMMAND ""

CMAKE_GENERATOR ${CMAKE_GENERATOR}

CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_C_FLAGS=${c_flags}
-DCMAKE_INSTALL_PREFIX=${zlib_install_prefix}
-DINSTALL_BIN_DIR=${zlib_install_prefix}/bin
-DINSTALL_INC_DIR=${LIB_STATIC_Z_INC_DIR}
-DINSTALL_LIB_DIR=${zlib_install_lib_dir}
-DINSTALL_MAN_DIR=${zlib_install_prefix}/man
-DINSTALL_PKGCONFIG_DIR=${zlib_install_prefix}/pkgconfig
)
ENDIF()