Previously CMake block termination commands were required to have arguments
matching the command starting the block. This is no longer necessary and not
the preferred style. This type of change has been implemented in other open
source projects such as: ITK, vxl, and BRAINSTools. It is the preferred style
for KDE. Consistent style practices help improve readability and
maintainability of code.
This was implemented with the shell script:
NOTE: MUST USE GNU compliant version of sed
in else endif endforeach endfunction endmacro endwhile; do
echo 's/\b'"$c"'\(\s*\)(.\+)/'"$c"'\1()/'
done >convert.sed \
&& git ls-files -z -- bootstrap '*.cmake' '*.cmake.in' '*CMakeLists.txt' \
| xargs -0 gsed -i -f convert.sed \
&& rm convert.sed
This is a reimplementation of ITK commit
e52dbe7fa476f6283c9b9d1507fca052355113a4
Fixes #585
84 lines
3.0 KiB
CMake
84 lines
3.0 KiB
CMake
# Using the CMake tools to create the file arma_config.hpp, which contains
|
|
# information on the Armadillo configuration when mlpack was compiled. This
|
|
# assumes ${ARMADILLO_INCLUDE_DIR} is set. In addition, we must be careful to
|
|
# avoid overwriting arma_config.hpp with the exact same information, because
|
|
# this may trigger a new complete rebuild, which is undesired.
|
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/mlpack/core/util/arma_config.hpp")
|
|
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/src/mlpack/core/util/arma_config.hpp"
|
|
OLD_FILE_CONTENTS)
|
|
else()
|
|
set(OLD_FILE_CONTENTS "")
|
|
endif()
|
|
|
|
# If we are using Armadillo 5+, ARMA_64BIT_WORD is implicitly enabled.
|
|
set(ARMA_HAS_64BIT_WORD 0) # This may be unnecessary.
|
|
if(NOT (${ARMADILLO_VERSION_MAJOR} LESS 5))
|
|
# ARMA_64BIT_WORD is only set if we are on a 64-bit system.
|
|
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
|
|
set(ARMA_HAS_64BIT_WORD 1)
|
|
else ()
|
|
set(ARMA_HAS_64BIT_WORD 0)
|
|
endif ()
|
|
else()
|
|
# Otherwise, we'll need to open the config.hpp we are using and inspect the
|
|
# setting of ARMA_64BIT_WORD.
|
|
if(EXISTS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/config.hpp")
|
|
file(READ "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/config.hpp"
|
|
ARMA_CONFIG)
|
|
|
|
# Extract ARMA_64BIT_WORD.
|
|
string(REGEX MATCH
|
|
"[\r\n][ ]*#define ARMA_64BIT_WORD"
|
|
ARMA_HAS_64BIT_WORD_PRE
|
|
"${ARMA_CONFIG}")
|
|
|
|
string(LENGTH "${ARMA_HAS_64BIT_WORD_PRE}" ARMA_HAS_64BIT_WORD)
|
|
else()
|
|
# Assumes ARMA_64BIT_WORD is not set.
|
|
message(WARNING "Armadillo configuration file
|
|
(${ARMADILLO_INCLUDE_DIR}/armadillo_bits/config.hpp) does not exist!")
|
|
endif()
|
|
endif()
|
|
|
|
# Now use the value we gathered to generate the new file contents.
|
|
if(ARMA_HAS_64BIT_WORD EQUAL 0)
|
|
set(ARMA_64BIT_WORD_DEFINE "#define MLPACK_ARMA_NO64BIT_WORD")
|
|
else()
|
|
set(ARMA_64BIT_WORD_DEFINE "#define MLPACK_ARMA_64BIT_WORD")
|
|
endif()
|
|
|
|
set(NEW_FILE_CONTENTS
|
|
"/**
|
|
* @file arma_config.hpp
|
|
*
|
|
* This is an autogenerated file which contains the configuration of Armadillo
|
|
* at the time mlpack was built. If you modify anything in here by hand, your
|
|
* warranty is void, your house may catch fire, and we're not going to call the
|
|
* police when your program segfaults so hard that robbers come to your house
|
|
* and take everything you own. If you do decide, against better judgment, to
|
|
* modify anything at all in this file, and you are reporting a bug, be
|
|
* absolutely certain to mention that you've done something stupid in this file
|
|
* first.
|
|
*
|
|
* In short: don't touch this file.
|
|
*/
|
|
#ifndef __MLPACK_CORE_UTIL_ARMA_CONFIG_HPP
|
|
#define __MLPACK_CORE_UTIL_ARMA_CONFIG_HPP
|
|
|
|
${ARMA_64BIT_WORD_DEFINE}
|
|
|
|
#endif
|
|
")
|
|
|
|
# Did the contents of the file change at all? If not, don't write it.
|
|
if(NOT "${OLD_FILE_CONTENTS}" STREQUAL "${NEW_FILE_CONTENTS}")
|
|
# We have a reason to write the new file.
|
|
message(STATUS "Regenerating arma_config.hpp.")
|
|
file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/src/mlpack/core/util/arma_config.hpp")
|
|
file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/src/mlpack/core/util/arma_config.hpp"
|
|
"${NEW_FILE_CONTENTS}")
|
|
endif()
|
|
|
|
|
|
|