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

Yaml Crash Problem WIP #282

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
Language: Cpp
BasedOnStyle: LLVM
DisableFormat: false
IndentWidth: 2
ColumnLimit: 120
...
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# along with this program. If not, see http://www.gnu.org/licenses.
# -----------------------------------------------------------------------------

cmake_minimum_required(VERSION 3.7)
cmake_minimum_required(VERSION 3.9)
project(htm_core CXX)

set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}")
Expand All @@ -29,6 +29,7 @@ set($ENV{HTM_CPP} ${REPOSITORY_DIR})
#
option(FORCE_CPP11 "Force compiler to use C++11 standard." OFF)
option(FORCE_BOOST "Force compiler to install and use Boost." OFF)
set(YAML_PARSER "yamlcpp" CACHE STRING "Specify the YAML parser to use 'yamlcpp', 'RapidYaml', 'libyaml', default 'yamlcpp'." )
Copy link
Member

Choose a reason for hiding this comment

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

i know this is a WIP, eventually we'll want to have just 1 parser.

set(BINDING_BUILD "none" CACHE STRING "Specify the Binding to build 'Python2','Python3' or 'none', default 'none'." )
# Note: by setting the CXX environment variable, a non-default c++ compiler can be specified.

Expand Down Expand Up @@ -77,6 +78,8 @@ message(STATUS "INTERNAL_LINKER_FLAGS_STR= ${INTERNAL_LINKER_FLAGS_STR}")
message(STATUS "COMMON_COMPILER_DEFINITIONS_STR=${COMMON_COMPILER_DEFINITIONS_STR}")
message(STATUS "COMMON_OS_LIBS = ${COMMON_OS_LIBS}")

add_definitions(-DYAML_PARSER_${YAML_PARSER})

# Set up builds of external dependencies and get their exports.
# (see individual external/*.cmake modules for exported settings and functions)
include(external/bootstrap.cmake)
Expand Down
24 changes: 14 additions & 10 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
# - cmake ../..
# Note: on MSVC, run startupMSVC.bat after deleting the build folder.

cmake_minimum_required(VERSION 3.7)
cmake_minimum_required(VERSION 3.9)
project(htm_core CXX)

set(CMAKE_VERBOSE_MAKEFILE OFF)
Expand Down Expand Up @@ -78,16 +78,20 @@ FILE(REMOVE "${EXPORT_FILE_NAME}")
# common
include(common.cmake)


################
# Yaml-cpp
include(YamlCppLib.cmake)

################
# libyaml
include(libyaml.cmake)


# Yaml Parser
if (${YAML_PARSER} STREQUAL "yamlcpp")
# Yaml-cpp
include(YamlCppLib.cmake)

elseif(${YAML_PARSER} STREQUAL "RapidYaml")
# Rapid YAML
include(RapidYaml.cmake)

elseif(${YAML_PARSER} STREQUAL "libyaml")
# libyaml
include(libyaml.cmake)
endif()
################
# Eigen
include(eigen.cmake)
Expand Down
107 changes: 107 additions & 0 deletions external/RapidYaml.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# -----------------------------------------------------------------------------
# HTM Community Edition of NuPIC
# Copyright (C) 2019, Numenta, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero Public License for more details.
#
# You should have received a copy of the GNU Affero Public License
# along with this program. If not, see http://www.gnu.org/licenses.
# -----------------------------------------------------------------------------

# Rapid YAML must be downloaded in four parts.
# - ryml from repository at https://github.com/biojppm/rapidyaml - the main library
# - c4core from repository at https://github.com/biojppm/c4core/ - the C library of utilities
# - cmake from repository at https://github.com/biojppm/cmake/ - Cmake scripts
# - debugbreak from repository at https://github.com/biojppm/debugbreak/ - debug break function
# There are links from rapidyaml to a specific branch of c4core in the extern folder of rapidyaml
# but the downloader does not follow it. So we need to do three downloads.

message(STATUS "${REPOSITORY_DIR}/build/ThirdParty/share/ryml.zip")
if( (EXISTS "${REPOSITORY_DIR}/build/ThirdParty/share/ryml.zip")
AND (EXISTS "${REPOSITORY_DIR}/build/ThirdParty/share/ryml_c4core.zip")
AND (EXISTS "${REPOSITORY_DIR}/build/ThirdParty/share/ryml_cmake.zip")
AND (EXISTS "${REPOSITORY_DIR}/build/ThirdParty/share/ryml_debugbreak.zip"))
set(URL1 "${REPOSITORY_DIR}/build/ThirdParty/share/ryml.zip")
set(URL2 "${REPOSITORY_DIR}/build/ThirdParty/share/ryml_c4core.zip")
set(URL3 "${REPOSITORY_DIR}/build/ThirdParty/share/ryml_cmake.zip")
set(URL4 "${REPOSITORY_DIR}/build/ThirdParty/share/ryml_debugbreak.zip")
else()
#There are no releases. Use the masters.
set(URL1 https://github.com/biojppm/rapidyaml/archive/master.zip)
set(URL2 https://github.com/biojppm/c4core/archive/master.zip)
set(URL3 https://github.com/biojppm/cmake/archive/master.zip)
set(URL4 https://github.com/biojppm/debugbreak/archive/master.zip)
endif()

message(STATUS "Obtaining RapidYAML from ${URL1}" )
include(DownloadProject/DownloadProject.cmake)
download_project(PROJ ryml
PREFIX "${EP_BASE}/ryml"
URL ${URL1}
UPDATE_DISCONNECTED 1
QUIET
)
download_project(PROJ ryml_c4core
PREFIX "${EP_BASE}/ryml_c4core"
SOURCE_DIR "${ryml_SOURCE_DIR}/extern/c4core"
URL ${URL2}
UPDATE_DISCONNECTED 1
QUIET
)
download_project(PROJ ryml_cmake
PREFIX "${EP_BASE}/ryml_cmake"
SOURCE_DIR "${ryml_SOURCE_DIR}/extern/c4core/cmake"
URL ${URL3}
UPDATE_DISCONNECTED 1
QUIET
)
download_project(PROJ ryml_debugbreak
PREFIX "${EP_BASE}/ryml_debugbreak"
SOURCE_DIR "${ryml_SOURCE_DIR}/extern/c4core/extern/debugbreak"
URL ${URL4}
UPDATE_DISCONNECTED 1
QUIET
)

#Need to enable Exceptions
set(c4path "${ryml_SOURCE_DIR}/extern/c4core/src/c4")
file(RENAME "${c4path}/config.hpp" "${c4path}/config1.hpp")
file(READ "${c4path}/config1.hpp" content1)
string(REPLACE "//#define C4_ERROR_THROWS_EXCEPTION"
"#define C4_ERROR_EXCEPTIONS_ENABLED\n#define C4_ERROR_THROWS_EXCEPTION"
content
"${content1}")
file(WRITE "${c4path}/config.hpp" "${content}")

file(RENAME "${c4path}/error.cpp" "${c4path}/error1.cpp")
file(READ "${c4path}/error1.cpp" content2)
string(REPLACE "if(s_error_flags & (ON_ERROR_LOG|ON_ERROR_CALLBACK))"
"if(s_error_flags & (ON_ERROR_LOG|ON_ERROR_CALLBACK|ON_ERROR_THROW))"
content1
"${content2}")
string(REPLACE "throw Exception(ss.c_str())"
"throw Exception(buf)"
content
"${content1}")
file(WRITE "${c4path}/error.cpp" "${content}")

set(C4_EXCEPTIONS_ENABLED ON)
set(C4_ERROR_THROWS_EXCEPTION ON)
add_subdirectory(${ryml_SOURCE_DIR} ${ryml_BINARY_DIR})

set(yaml_INCLUDE_DIRS "${ryml_SOURCE_DIR}/src@@@${ryml_SOURCE_DIR}/extern/c4core/src@@@${ryml_SOURCE_DIR}/extern/c4core/extern")
if (MSVC)
set(yaml_LIBRARIES "${ryml_BINARY_DIR}$<$<CONFIG:Release>:/Release/ryml.lib>$<$<CONFIG:Debug>:/Debug/ryml.lib>")
else()
set(yaml_LIBRARIES ${ryml_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}ryml${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()
FILE(APPEND "${EXPORT_FILE_NAME}" "yaml_INCLUDE_DIRS@@@${yaml_INCLUDE_DIRS}\n")
FILE(APPEND "${EXPORT_FILE_NAME}" "yaml_LIBRARIES@@@${yaml_LIBRARIES}\n")

10 changes: 5 additions & 5 deletions external/YamlCppLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ set(YAML_CPP_BUILD_CONTRIB OFF CACHE BOOL "prevent contrib modules" FORCE)
set(MSVC_SHARED_RT ON CACHE BOOL "Use compile option /MD rather than /MT" FORCE)
add_subdirectory(${yaml-cpp_SOURCE_DIR} ${yaml-cpp_BINARY_DIR})

set(yaml-cpp_INCLUDE_DIRS ${yaml-cpp_SOURCE_DIR}/include)
set(yaml_INCLUDE_DIRS ${yaml-cpp_SOURCE_DIR}/include)
if (MSVC)
set(yaml-cpp_LIBRARIES "${yaml-cpp_BINARY_DIR}$<$<CONFIG:Release>:/Release/libyaml-cppmd.lib>$<$<CONFIG:Debug>:/Debug/libyaml-cppmdd.lib>")
set(yaml_LIBRARIES "${yaml-cpp_BINARY_DIR}$<$<CONFIG:Release>:/Release/libyaml-cppmd.lib>$<$<CONFIG:Debug>:/Debug/libyaml-cppmdd.lib>")
else()
set(yaml-cpp_LIBRARIES ${yaml-cpp_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}yaml-cpp${CMAKE_STATIC_LIBRARY_SUFFIX})
set(yaml_LIBRARIES ${yaml-cpp_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}yaml-cpp${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()
FILE(APPEND "${EXPORT_FILE_NAME}" "yaml-cpp_INCLUDE_DIRS@@@${yaml-cpp_SOURCE_DIR}/include\n")
FILE(APPEND "${EXPORT_FILE_NAME}" "yaml-cpp_LIBRARIES@@@${yaml-cpp_LIBRARIES}\n")
FILE(APPEND "${EXPORT_FILE_NAME}" "yaml_INCLUDE_DIRS@@@${yaml-cpp_SOURCE_DIR}/include\n")
FILE(APPEND "${EXPORT_FILE_NAME}" "yaml_LIBRARIES@@@${yaml_LIBRARIES}\n")

37 changes: 29 additions & 8 deletions external/bootstrap.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
# - create build/scripts (mkdir -d build/scripts)
# - cd build/scripts
# - cmake ../..
#
# externals are always built in Release mode, CMake's build type is ignored



FILE(MAKE_DIRECTORY ${REPOSITORY_DIR}/build/ThirdParty)
execute_process(COMMAND ${CMAKE_COMMAND}
-G ${CMAKE_GENERATOR}
-D CMAKE_INSTALL_PREFIX=.
-D CMAKE_INSTALL_PREFIX=.
-D NEEDS_BOOST:BOOL=${NEEDS_BOOST}
-D BINDING_BUILD:STRING=${BINDING_BUILD}
-D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-D YAML_PARSER:STRING=${YAML_PARSER}
-D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-D REPOSITORY_DIR=${REPOSITORY_DIR}
../../external
WORKING_DIRECTORY ${REPOSITORY_DIR}/build/ThirdParty
RESULT_VARIABLE result
Expand All @@ -45,15 +45,36 @@ execute_process(COMMAND ${CMAKE_COMMAND}
if(result)
message(FATAL_ERROR "CMake step for Third Party builds failed: ${result}")
endif()

execute_process(COMMAND ${CMAKE_COMMAND} --build .
if(MSVC)
# for MSVC builds we need to build both Release and Debug builds
# because this will not be ran again if we switch modes in the IDE.
execute_process(COMMAND ${CMAKE_COMMAND} --build . --config Release
WORKING_DIRECTORY ${REPOSITORY_DIR}/build/ThirdParty
RESULT_VARIABLE result
# OUTPUT_QUIET ### Disable this to debug external buiilds
)
if(result)
message(FATAL_ERROR "build step for MSVC Release Third Party builds failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build . --config Debug
WORKING_DIRECTORY ${REPOSITORY_DIR}/build/ThirdParty
RESULT_VARIABLE result
# OUTPUT_QUIET ### Disable this to debug external buiilds
)
if(result)
message(FATAL_ERROR "build step for MSVC Debug Third Party builds failed: ${result}")
endif()
else(MSVC)
# for linux and OSx builds
execute_process(COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE}
WORKING_DIRECTORY ${REPOSITORY_DIR}/build/ThirdParty
RESULT_VARIABLE result
# OUTPUT_QUIET ### Disable this to debug external builds
# OUTPUT_QUIET ### Disable this to debug external buiilds
)
if(result)
message(FATAL_ERROR "build step for Third Party builds failed: ${result}")
endif()
endif(MSVC)

# extract the external directory paths
# The external third party modules are being built
Expand All @@ -71,7 +92,7 @@ FOREACH(line ${lines})
message(STATUS " ${name} = ${${name}}")
ENDFOREACH()
set(EXTERNAL_INCLUDES
${yaml-cpp_INCLUDE_DIRS}
${yaml_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${eigen_INCLUDE_DIRS}
${mnist_INCLUDE_DIRS}
Expand Down
12 changes: 6 additions & 6 deletions external/libYaml.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -----------------------------------------------------------------------------
# Numenta Platform for Intelligent Computing (NuPIC)
# Copyright (C) 2016, Numenta, Inc. Unless you have purchased from
# Copyright (C) 2019, Numenta, Inc. Unless you have purchased from
# Numenta, Inc. a separate commercial license for this software code, the
# following terms and conditions apply:
#
Expand Down Expand Up @@ -38,12 +38,12 @@ download_project(PROJ libyaml

add_subdirectory(${libyaml_SOURCE_DIR} ${libyaml_BINARY_DIR})

set(libyaml_INCLUDE_DIRS ${libyaml_SOURCE_DIR}/include)
set(yaml_INCLUDE_DIRS ${libyaml_SOURCE_DIR}/include)
if (MSVC)
set(libyaml_LIBRARIES "${libyaml_BINARY_DIR}$<$<CONFIG:Release>:/Release/liblibyamlmd.lib>$<$<CONFIG:Debug>:/Debug/liblibyamlmdd.lib>")
set(yaml_LIBRARIES "${libyaml_BINARY_DIR}$<$<CONFIG:Release>:/Release/liblibyamlmd.lib>$<$<CONFIG:Debug>:/Debug/liblibyamlmdd.lib>")
else()
set(ylibyaml_LIBRARIES ${libyaml_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}libyaml${CMAKE_STATIC_LIBRARY_SUFFIX})
set(yaml_LIBRARIES ${libyaml_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}libyaml${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()
FILE(APPEND "${EXPORT_FILE_NAME}" "libyaml_INCLUDE_DIRS@@@${libyaml_SOURCE_DIR}/include\n")
FILE(APPEND "${EXPORT_FILE_NAME}" "libyaml_LIBRARIES@@@${libyaml_LIBRARIES}\n")
FILE(APPEND "${EXPORT_FILE_NAME}" "yaml_INCLUDE_DIRS@@@${yaml_SOURCE_DIR}\n")
FILE(APPEND "${EXPORT_FILE_NAME}" "yaml_LIBRARIES@@@${yaml_LIBRARIES}\n")

Loading