mirror of
https://github.com/marian-nmt/marian.git
synced 2024-10-03 18:17:12 +03:00
Add option for printing CMake cached variables (#583)
* Add option --build-info
This commit is contained in:
parent
f4ea8239c4
commit
aad22c9d09
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,6 +1,7 @@
|
||||
# Config files from CMake
|
||||
src/common/project_version.h
|
||||
src/common/git_revision.h
|
||||
src/common/build_info.cpp
|
||||
|
||||
*.vcxproj.user
|
||||
/vs/x64
|
||||
@ -61,4 +62,4 @@ examples/mnist/*ubyte
|
||||
|
||||
.vs
|
||||
.vscode
|
||||
|
||||
|
||||
|
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
- An option to print cached variables from CMake
|
||||
- Add support for compiling on Mac (and clang)
|
||||
- An option for resetting stalled validation metrics
|
||||
- Add CMAKE options to disable compilation for specific GPU SM types
|
||||
|
@ -56,6 +56,7 @@ if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Release")
|
||||
endif()
|
||||
|
||||
###############################################################################
|
||||
# Set compilation flags
|
||||
if(MSVC)
|
||||
# These are used in src/CMakeLists.txt on a per-target basis
|
||||
@ -185,6 +186,7 @@ else(MSVC)
|
||||
set(CMAKE_C_FLAGS_PROFUSE "${CMAKE_C_FLAGS_RELEASE} -fprofile-use -fprofile-correction")
|
||||
endif(MSVC)
|
||||
|
||||
###############################################################################
|
||||
# Downloading SentencePiece if requested and set to compile with it.
|
||||
# Requires all the dependencies imposed by SentencePiece
|
||||
if(USE_SENTENCEPIECE)
|
||||
@ -196,6 +198,7 @@ endif()
|
||||
# Find packages
|
||||
set(EXT_LIBS ${EXT_LIBS} ${CMAKE_DL_LIBS})
|
||||
|
||||
###############################################################################
|
||||
if(COMPILE_CUDA)
|
||||
|
||||
if(USE_STATIC_LIBS)
|
||||
@ -316,6 +319,8 @@ if(USE_STATIC_LIBS)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
###############################################################################
|
||||
# Find Tcmalloc
|
||||
if(NOT WIN32)
|
||||
find_package(Tcmalloc)
|
||||
if(Tcmalloc_FOUND)
|
||||
@ -326,6 +331,8 @@ if(NOT WIN32)
|
||||
endif(Tcmalloc_FOUND)
|
||||
endif()
|
||||
|
||||
###############################################################################
|
||||
# Find MPI
|
||||
if(USE_MPI)
|
||||
find_package(MPI 2.0)
|
||||
if(MPI_FOUND)
|
||||
@ -335,6 +342,8 @@ if(USE_MPI)
|
||||
endif(MPI_FOUND)
|
||||
endif(USE_MPI)
|
||||
|
||||
###############################################################################
|
||||
# Find MKL
|
||||
if(COMPILE_CPU)
|
||||
if(USE_MKL)
|
||||
find_package(MKL)
|
||||
@ -357,6 +366,8 @@ if(COMPILE_CPU)
|
||||
endif(MKL_FOUND)
|
||||
endif(COMPILE_CPU)
|
||||
|
||||
###############################################################################
|
||||
# Find OpenSSL
|
||||
set(BOOST_COMPONENTS "")
|
||||
if(COMPILE_SERVER)
|
||||
find_package(OpenSSL)
|
||||
@ -375,10 +386,13 @@ if(USE_STATIC_LIBS)
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||
endif()
|
||||
|
||||
# TODO: move inside if(BOOST_COMPONENTS) ?
|
||||
if(USE_STATIC_LIBS)
|
||||
set(Boost_USE_STATIC_LIBS ON)
|
||||
endif()
|
||||
|
||||
###############################################################################
|
||||
# Find Boost if required
|
||||
if(BOOST_COMPONENTS)
|
||||
find_package(Boost COMPONENTS ${BOOST_COMPONENTS})
|
||||
if(Boost_FOUND)
|
||||
@ -390,6 +404,7 @@ if(BOOST_COMPONENTS)
|
||||
endif(Boost_FOUND)
|
||||
endif(BOOST_COMPONENTS)
|
||||
|
||||
###############################################################################
|
||||
if(COMPILE_TESTS)
|
||||
enable_testing()
|
||||
endif(COMPILE_TESTS)
|
||||
@ -402,10 +417,17 @@ endif(COMPILE_EXAMPLES)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/common/project_version.h.in
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/common/project_version.h @ONLY)
|
||||
|
||||
# Generate build_info.cpp with CMake cache variables
|
||||
include(GetCacheVariables)
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/common/build_info.cpp.in
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/common/build_info.cpp @ONLY)
|
||||
|
||||
# Compile source files
|
||||
include_directories(${marian_SOURCE_DIR}/src)
|
||||
add_subdirectory(src)
|
||||
|
||||
###############################################################################
|
||||
if(USE_DOXYGEN)
|
||||
# Add a target to generate API documentation with Doxygen
|
||||
find_package(Doxygen)
|
||||
|
52
cmake/GetCacheVariables.cmake
Normal file
52
cmake/GetCacheVariables.cmake
Normal file
@ -0,0 +1,52 @@
|
||||
##
|
||||
# This module extracts CMake cached variables into a variable.
|
||||
#
|
||||
# Author: snukky
|
||||
#
|
||||
# This module sets the following variables:
|
||||
# * PROJECT_CMAKE_CACHE - to the output of "cmake -L" - an uncached list of
|
||||
# non-advanced cached variables
|
||||
# * PROJECT_CMAKE_CACHE_ADVANCED - to the output of "cmake -LA" - an uncached
|
||||
# list of advanced cached variables
|
||||
#
|
||||
|
||||
set(PROJECT_CMAKE_CACHE "")
|
||||
set(PROJECT_CMAKE_CACHE_ADVANCED "")
|
||||
|
||||
# Get all CMake variables
|
||||
get_cmake_property(_variableNames VARIABLES)
|
||||
list(SORT _variableNames)
|
||||
list(REMOVE_DUPLICATES _variableNames)
|
||||
|
||||
foreach(_variableName ${_variableNames})
|
||||
# If it is a cache variable
|
||||
get_property(_cachePropIsSet CACHE "${_variableName}" PROPERTY VALUE SET)
|
||||
if(_cachePropIsSet)
|
||||
# Get the variable's type
|
||||
get_property(_variableType CACHE ${_variableName} PROPERTY TYPE)
|
||||
|
||||
# Get the variable's value
|
||||
set(_variableValue "${${_variableName}}")
|
||||
|
||||
# Skip static or internal cached variables, cmake -L[A] does not print them, see
|
||||
# https://github.com/Kitware/CMake/blob/master/Source/cmakemain.cxx#L282
|
||||
if( (NOT "${_variableType}" STREQUAL "STATIC") AND
|
||||
(NOT "${_variableType}" STREQUAL "INTERNAL") AND
|
||||
(NOT "${_variableValue}" STREQUAL "") )
|
||||
|
||||
|
||||
set(PROJECT_CMAKE_CACHE_ADVANCED "${PROJECT_CMAKE_CACHE_ADVANCED} \"${_variableName}=${_variableValue}\\n\"\n")
|
||||
|
||||
# Get the variable's advanced flag
|
||||
get_property(_isAdvanced CACHE ${_variableName} PROPERTY ADVANCED SET)
|
||||
if(NOT _isAdvanced)
|
||||
set(PROJECT_CMAKE_CACHE "${PROJECT_CMAKE_CACHE} \"${_variableName}=${_variableValue}\\n\"\n")
|
||||
endif()
|
||||
|
||||
# Print variables for debugging
|
||||
#message(STATUS "${_variableName}=${${_variableName}}")
|
||||
#message(STATUS " Type=${_variableType}")
|
||||
#message(STATUS " Advanced=${_isAdvanced}")
|
||||
endif()
|
||||
endif(_cachePropIsSet)
|
||||
endforeach()
|
@ -20,6 +20,7 @@ add_library(marian STATIC
|
||||
common/config_validator.cpp
|
||||
common/options.cpp
|
||||
common/binary.cpp
|
||||
common/build_info.cpp
|
||||
common/io.cpp
|
||||
common/filesystem.cpp
|
||||
common/file_stream.cpp
|
||||
|
18
src/common/build_info.cpp.in
Normal file
18
src/common/build_info.cpp.in
Normal file
@ -0,0 +1,18 @@
|
||||
#include "common/build_info.h"
|
||||
|
||||
/*
|
||||
* File build_info.cpp is generated using CMake. Do NOT modify it manually! Edit
|
||||
* build_info.cpp.in file instead.
|
||||
*/
|
||||
|
||||
std::string marian::cmakeBuildOptions() {
|
||||
return ""
|
||||
@PROJECT_CMAKE_CACHE@
|
||||
;
|
||||
}
|
||||
|
||||
std::string marian::cmakeBuildOptionsAdvanced() {
|
||||
return ""
|
||||
@PROJECT_CMAKE_CACHE_ADVANCED@
|
||||
;
|
||||
}
|
13
src/common/build_info.h
Normal file
13
src/common/build_info.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace marian {
|
||||
|
||||
// Returns list of non-advanced cache variables used by CMake
|
||||
std::string cmakeBuildOptions();
|
||||
|
||||
// Returns list of advanced cache variables used by CMake
|
||||
std::string cmakeBuildOptionsAdvanced();
|
||||
|
||||
} // namespace marian
|
@ -1,4 +1,5 @@
|
||||
#include "common/authors.h"
|
||||
#include "common/build_info.h"
|
||||
#include "common/cli_helper.h"
|
||||
#include "common/config.h"
|
||||
#include "common/config_parser.h"
|
||||
@ -111,6 +112,9 @@ void ConfigParser::addOptionsGeneral(cli::CLIWrapper& cli) {
|
||||
"Print list of authors and exit");
|
||||
cli.add<bool>("--cite",
|
||||
"Print citation and exit");
|
||||
cli.add<std::string>("--build-info",
|
||||
"Print CMake build options and exit. Set to 'all' to print advanced options")
|
||||
->implicit_val("basic");
|
||||
cli.add<std::vector<std::string>>("--config,-c",
|
||||
"Configuration file(s). If multiple, later overrides earlier");
|
||||
cli.add<size_t>("--workspace,-w",
|
||||
@ -504,7 +508,7 @@ void ConfigParser::addOptionsTraining(cli::CLIWrapper& cli) {
|
||||
true);
|
||||
|
||||
// add ULR settings
|
||||
addSuboptionsULR(cli);
|
||||
addSuboptionsULR(cli);
|
||||
|
||||
cli.add<std::vector<std::string>>("--task",
|
||||
"Use predefined set of options. Possible values: transformer, transformer-big");
|
||||
@ -835,6 +839,15 @@ Ptr<Options> ConfigParser::parseOptions(int argc, char** argv, bool doValidate){
|
||||
exit(0);
|
||||
}
|
||||
|
||||
auto buildInfo = get<std::string>("build-info");
|
||||
if(!buildInfo.empty() && buildInfo != "false") {
|
||||
if(buildInfo == "all")
|
||||
std::cerr << cmakeBuildOptionsAdvanced() << std::endl;
|
||||
else
|
||||
std::cerr << cmakeBuildOptions() << std::endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// get paths to extra config files
|
||||
auto configPaths = findConfigPaths();
|
||||
if(!configPaths.empty()) {
|
||||
|
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* File project-version.h is generated using CMake. Do NOT modify it manually! Edit
|
||||
* project-version.h.in file instead.
|
||||
* File project_version.h is generated using CMake. Do NOT modify it manually! Edit
|
||||
* project_version.h.in file instead.
|
||||
*/
|
||||
|
||||
// e.g. v1.2.3-beta+1.abc123d
|
||||
|
Loading…
Reference in New Issue
Block a user