Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake compilation system #71

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
/src/Core/stack.hh

# From build.
.build
.build*
cmake-build*
*.a
*.pyc
*.o
Expand Down Expand Up @@ -49,7 +50,6 @@
/Sprint.includes
# CLion
/.idea
/CMakeLists.txt
# Other
.history*
*.autosave
Expand Down
50 changes: 50 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
cmake_minimum_required(VERSION 3.22)
project(RASR)

include(cmake_resources/ConfigurationTypes.cmake)
include(cmake_resources/Modules.cmake)
include(cmake_resources/GeneralCompileOptions.cmake)

if (${MODULE_PYTHON})
include(cmake_resources/Python.cmake)
endif ()

if (${MODULE_TENSORFLOW})
include(cmake_resources/Tensorflow.cmake)
endif ()

if (${MODULE_ONNX})
include(cmake_resources/Onnx.cmake)
endif ()

string(TOLOWER ${CMAKE_SYSTEM_NAME} SYSTEM_NAME)
string(TOLOWER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
set(ARCH_DESCRIPTION
"${SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}-${BUILD_TYPE}")
set(CMAKE_INSTALL_PREFIX
"${CMAKE_CURRENT_SOURCE_DIR}/arch/${ARCH_DESCRIPTION}/")
set(INSTALL_LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib/${ARCH_DESCRIPTION}")

function(add_install_executable EXECUTABLE_NAME)
install(TARGETS ${EXECUTABLE_NAME} RUNTIME DESTINATION .)
set_target_properties(
${EXECUTABLE_NAME} PROPERTIES OUTPUT_NAME
"${EXECUTABLE_NAME}.${ARCH_DESCRIPTION}")
endfunction()

function(add_install_library LIBRARY_NAME)
install(TARGETS ${LIBRARY_NAME} LIBRARY DESTINATION ${INSTALL_LIB_DIR})
endfunction()

add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/SourceVersion.cc
COMMAND
${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/src/SourceVersion.release
${CMAKE_CURRENT_SOURCE_DIR}/src/SourceVersion.cc
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/SourceVersion.release)

add_custom_target(SourceVersion
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/SourceVersion.cc)

add_subdirectory(src/)
22 changes: 22 additions & 0 deletions cmake_resources/ConfigurationTypes.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "standard" "debug"
"release")

if (NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'standard' as none was specified.")
set(CMAKE_BUILD_TYPE standard CACHE STRING "Choose the type of build." FORCE)
endif ()

set(CMAKE_C_FLAGS_STANDARD "-O2")
set(CMAKE_CXX_FLAGS_STANDARD "-O2")
set(CMAKE_EXE_LINKER_FLAGS_STANDARD "")
set(CMAKE_DEF_FLAGS_STANDARD "-DSPRINT_STANDARD_BUILD")

set(CMAKE_C_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-rdynamic")
set(CMAKE_DEF_FLAGS_RELEASE "-DSPRINT_RELEASE_BUILD -DNDEBUG")

set(CMAKE_C_FLAGS_DEBUG "-O0 -g")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "")
set(CMAKE_DEF_FLAGS_DEBUG "-D_GLIBCXX_DEBUG -DDEBUG")
85 changes: 85 additions & 0 deletions cmake_resources/GeneralCompileOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
set(CMAKE_CXX_STANDARD 17)

add_compile_definitions(CMAKE_DISABLE_MODULES_HH)

add_compile_definitions(_GNU_SOURCE)
add_compile_options(
-fPIC
-pipe
-funsigned-char
-fno-exceptions
-Wno-unknown-pragmas
-Wall
-Wno-long-long
-Wno-deprecated
-fno-strict-aliasing
-ffast-math)

if (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "linux-x86_64")
add_compile_options(-msse3)
endif ()

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
message(STATUS "Using GCC compiler")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message(STATUS "Using Clang compiler")
add_compile_definitions(_GLIBCXX_PERMIT_BACKWARD_HASH)
add_compile_options(-D__float128=void) # hack: http://llvm.org/bugs/show_bug.cgi?id=13530
else ()
message(WARNING "Compiler might not be supported. Use at your own risk")
endif ()

if (NOT DEFINED MARCH)
set(MARCH "native" CACHE STRING "Default target architecture")
endif ()
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-march=${MARCH}" COMPILER_SUPPORTS_MARCH)
if (COMPILER_SUPPORTS_MARCH)
add_compile_options("-march=${MARCH}")
message(STATUS "Using -march=${MARCH}")
else ()
message(STATUS "Architecture -march=${MARCH} is not supported")
endif ()

find_package(LibXml2 REQUIRED)
find_package(Threads REQUIRED)
find_package(ZLIB REQUIRED)
find_package(LAPACK REQUIRED)

find_library(LIB_RT rt REQUIRED)

link_libraries(LibXml2::LibXml2 ZLIB::ZLIB Threads::Threads LAPACK::LAPACK ${LIB_RT})

include_directories(${LIBXML2_INCLUDE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/src)

if (${MODULE_AUDIO_FFMPEG})
find_package(PkgConfig REQUIRED)
pkg_check_modules(AVFORMAT REQUIRED IMPORTED_TARGET libavformat)
pkg_check_modules(SWRESAMPLE REQUIRED IMPORTED_TARGET libswresample)
pkg_check_modules(AVCODEC REQUIRED IMPORTED_TARGET libavcodec)
pkg_check_modules(AVUTIL REQUIRED IMPORTED_TARGET libavutil)

include_directories(${AVFORMAT_INCLUDE_DIRS} ${SWRESAMPLE_INCLUDE_DIRS} ${AVCODEC_INCLUDE_DIRS} ${AVUTIL_INCLUDE_DIRS})
link_libraries(PkgConfig::AVFORMAT PkgConfig::SWRESAMPLE PkgConfig::AVCODEC PkgConfig::AVUTIL)
endif ()

if (${MODULE_OPENMP})
find_package(OpenMP REQUIRED)
add_compile_options(OpenMP_CXX_FLAGS)
include_directories(OpenMP_CXX_INCLUDE_DIRS)
link_libraries(OpenMP::OpenMP_CXX)
endif ()

if (${MODULE_CUDA})
enable_language(CUDA)
set(CMAKE_CUDA_ARCHITECTURES 61;75;86;89)
endif ()

if (${MODULE_AUDIO_FLAC})
link_libraries(FLAC)
endif ()

if (${MODULE_AUDIO_WAV_SYSTEM})
link_libraries(sndfile)
endif ()
156 changes: 156 additions & 0 deletions cmake_resources/Modules.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
function(add_module_option MODULE_NAME DEFAULT_VALUE)
option(${MODULE_NAME} "Enable module ${MODULE_NAME}" ${DEFAULT_VALUE})
if (${MODULE_NAME})
add_compile_definitions(${MODULE_NAME})
message(STATUS "Module ${MODULE_NAME} is enabled")
else ()
message(STATUS "Module ${MODULE_NAME} disabled")
endif ()
endfunction()

set(TOOLS "")

function(add_tool_option TOOL_NAME DEFAULT_VALUE)
option(${TOOL_NAME} "Enable tool ${TOOL_NAME}" ${DEFAULT_VALUE})
if (${TOOL_NAME})
set(TOOLS ${TOOLS} ${TOOL_NAME} PARENT_SCOPE)
message(STATUS "Tool ${TOOL_NAME} is enabled")
else ()
message(STATUS "Tool ${TOOL_NAME} is disabled")
endif ()
endfunction()

# ****** Adaptation ******
add_module_option(MODULE_ADAPT_CMLLR ON)
add_module_option(MODULE_ADAPT_MLLR ON)
add_module_option(MODULE_ADAPT_ADVANCED ON)

# ****** Audio ******
add_module_option(MODULE_AUDIO_FFMPEG OFF)
add_module_option(MODULE_AUDIO_FLAC ON)
add_module_option(MODULE_AUDIO_OTK ON)
add_module_option(MODULE_AUDIO_OSS ON)
add_module_option(MODULE_AUDIO_RAW ON)
add_module_option(MODULE_AUDIO_WAV_SYSTEM ON)

# ****** Cache Manager integration ******
add_module_option(MODULE_CORE_CACHE_MANAGER ON)

# ****** Cart ******
add_module_option(MODULE_CART ON)

# ****** Flf ******
add_module_option(MODULE_FLF_CORE ON)
add_module_option(MODULE_FLF_EXT ON)
add_module_option(MODULE_FLF ON)

# ****** Lattice ******
add_module_option(MODULE_LATTICE_BASIC ON)
add_module_option(MODULE_LATTICE_HTK ON)
add_module_option(MODULE_LATTICE_DT ON)

# ****** Lm ******
add_module_option(MODULE_LM_ARPA ON)
add_module_option(MODULE_LM_FSA ON)
add_module_option(MODULE_LM_ZEROGRAM ON)
add_module_option(MODULE_LM_FFNN ON)
add_module_option(MODULE_LM_TFRNN ON)

# ****** Math ******
add_module_option(MODULE_MATH_NR ON)

# ****** Mm ******
add_module_option(MODULE_MM_BATCH ON)
add_module_option(MODULE_MM_DT ON)

# ****** Neural Network ******
add_module_option(MODULE_NN ON)
add_module_option(MODULE_NN_SEQUENCE_TRAINING ON)
add_module_option(MODULE_THEANO_INTERFACE ON)
add_module_option(MODULE_PYTHON ON)

# ****** OpenFst ******
add_module_option(MODULE_OPENFST OFF)

# ****** Search ******
add_module_option(MODULE_SEARCH_MBR ON)
add_module_option(MODULE_SEARCH_WFST OFF)
add_module_option(MODULE_SEARCH_LINEAR ON)
add_module_option(MODULE_ADVANCED_TREE_SEARCH ON)
add_module_option(MODULE_GENERIC_SEQ2SEQ_TREE_SEARCH ON)

# ****** Signal ******
add_module_option(MODULE_SIGNAL_GAMMATONE ON)
add_module_option(MODULE_SIGNAL_PLP ON)
add_module_option(MODULE_SIGNAL_VTLN ON)
add_module_option(MODULE_SIGNAL_VOICEDNESS ON)
add_module_option(MODULE_SIGNAL_ADVANCED ON)
add_module_option(MODULE_SIGNAL_ADVANCED_NR ON)

# ****** Speech ******
add_module_option(MODULE_SPEECH_DT ON)
add_module_option(MODULE_SPEECH_DT_ADVANCED ON)
add_module_option(MODULE_SPEECH_ALIGNMENT_FLOW_NODES ON)
add_module_option(MODULE_SPEECH_LATTICE_FLOW_NODES ON)
add_module_option(MODULE_SPEECH_LATTICE_ALIGNMENT ON)
add_module_option(MODULE_SPEECH_LATTICE_RESCORING ON)

# ****** Unit Tests ******
add_module_option(MODULE_TEST OFF)

# ****** Intel Threading Building Blocks ******
add_module_option(MODULE_TBB OFF)

# ****** OpenMP library ******
add_module_option(MODULE_OPENMP OFF)
# **** choose optimized blas library if available ******
add_module_option(MODULE_INTEL_MKL OFF)
add_module_option(MODULE_ACML OFF)
add_module_option(MODULE_CUDA OFF)

# ****** Tensorflow integration ******
add_module_option(MODULE_TENSORFLOW ON)

# ****** ONNX integration ******
add_module_option(MODULE_ONNX ON)

# ****** Tools ******
add_tool_option(AcousticModelTrainer ON)
add_tool_option(Archiver ON)
add_tool_option(CorpusStatistics ON)
add_tool_option(FeatureExtraction ON)
add_tool_option(FeatureStatistics ON)
add_tool_option(Fsa ON)
add_tool_option(LibRASR ON)
add_tool_option(Lm ON)
add_tool_option(SpeechRecognizer ON)
add_tool_option(Xml ON)

if (${MODULE_CART})
add_tool_option(Cart ON)
endif ()

if (${MODULE_MM_DT}
AND ${MODULE_LATTICE_DT}
AND ${MODULE_SPEECH_DT})
add_tool_option(LatticeProcessor ON)
endif ()

if (${MODULE_FLF})
add_tool_option(Flf ON)
endif ()

if (${MODULE_NN})
add_tool_option(NnTrainer ON)
endif ()

set(SEARCH_LIBS RasrSearch)
if (${MODULE_SEARCH_WFST})
list(APPEND SEARCH_LIBS RasrSearchWfst RasrOpenFst)
endif ()
if (${MODULE_ADVANCED_TREE_SEARCH})
list(APPEND SEARCH_LIBS RasrAdvancedTreeSearch)
endif ()
if (${MODULE_GENERIC_SEQ2SEQ_TREE_SEARCH})
list(APPEND SEARCH_LIBS RasrGenericSeq2SeqTreeSearch)
endif ()
9 changes: 9 additions & 0 deletions cmake_resources/Onnx.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(onnx_INCLUDE_DIR "/opt/thirdparty/usr/include")

find_library(onnxruntime_LIBRARY onnxruntime REQUIRED HINTS "/opt/thirdparty/usr/lib")

function(add_onnx_dependencies TARGET)
target_compile_options(${TARGET} PUBLIC "-fexceptions")
target_include_directories(${TARGET} PUBLIC ${onnx_INCLUDE_DIR})
target_link_libraries(${TARGET} PUBLIC ${onnxruntime_LIBRARY})
endfunction()
7 changes: 7 additions & 0 deletions cmake_resources/Python.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
find_package(Python3 REQUIRED COMPONENTS Development NumPy)

function(add_python_dependencies TARGET)
target_compile_definitions(${TARGET} PUBLIC ${Python3_DEFINITIONS})
target_include_directories(${TARGET} PUBLIC ${Python3_INCLUDE_DIRS} ${Python3_NumPy_INCLUDE_DIRS})
target_link_libraries(${TARGET} PUBLIC ${Python3_LIBRARIES})
endfunction()
Loading