Skip to content

Commit

Permalink
Move JsonCpp and SPLINTER from submodules to external CMake dependencies
Browse files Browse the repository at this point in the history
- git submodules are not working well for bundled libraries, and also it's not clear how they would be packaged in the final version

- therefore, JsonCpp and SPLINTER have been moved from git submodules to external CMake dependencies handled with the EXTERNALPROJECT_ADD command. This automatically clones their repositories at a fixed commit and builds the results. This will make packaging much easier

- Improvements to FindCppTransport.cmake module which is now configured using the installation prefix, so it is guaranteed to find the JsonCpp and SPLINTER libraries which were installed with CppTransport

- Boost and GiNaC dependencies still handled as before, assuming they have been pre-installed by a sysadmin or package manager. This seems to make most sense; installing shared libraries (eg. for Boost) in non-standard locations is complex and difficult to do correctly, and also both Boost and GiNaC (via CLN and then GMP) have not-completely-trivial build procedures. We get the best user experience by having these components properly installed in standard locations

- update to SPLINTER 3.0, and adjustments for its new API
  • Loading branch information
ds283 committed Apr 22, 2016
1 parent 548e332 commit f59bef0
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 86 deletions.
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
[submodule "CppTransport/thirdparty/jsoncpp"]
path = CppTransport/thirdparty/jsoncpp
url = https://ds283@github.com/open-source-parsers/jsoncpp.git
[submodule "CppTransport/thirdparty/splinter"]
path = CppTransport/thirdparty/splinter
url = https://ds283@github.com/bgrimstad/splinter.git
58 changes: 42 additions & 16 deletions CppTransport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ PROJECT(CppTransport)
# no consequences for us
SET(CMAKE_MACOSX_RPATH TRUE)

SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/splinter/cmake/")

LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/)
INCLUDE(BuildDeps)

# Attempt some platform/compiler introspection
STRING(COMPARE EQUAL "Linux" ${CMAKE_SYSTEM_NAME} LINUX)
Expand Down Expand Up @@ -50,21 +49,30 @@ ENDIF()
# find Bison to produce parser
FIND_PACKAGE(BISON 3.0 REQUIRED)

# find MPI library
FIND_PACKAGE(MPI REQUIRED)

# find required Boost libraries
FIND_PACKAGE(Boost REQUIRED COMPONENTS log system filesystem random timer date_time mpi thread serialization program_options regex)

# pull in bundled JsonCpp and SPLINTER libraries
SET(ARCH x86-64)
ADD_SUBDIRECTORY(thirdparty/splinter)
ADD_SUBDIRECTORY(thirdparty/jsoncpp)
# find GiNaC library
FIND_PACKAGE(GiNaC REQUIRED)


# find required libraries
FIND_PACKAGE(MPI REQUIRED)
FIND_PACKAGE(Boost 1.56 REQUIRED COMPONENTS system filesystem random timer date_time mpi log_setup log serialization thread program_options regex)
FIND_PACKAGE(GiNaC 1.6 REQUIRED)
# handle non-standard external dependencies
ADD_CUSTOM_TARGET(DEPS ALL)
SET(EXTERNAL_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/thirdparty/dist")

BUILD_JSONCPP(${CMAKE_BINARY_DIR}/thirdparty/jsoncpp ${EXTERNAL_INSTALL_PREFIX})
BUILD_SPLINTER(${CMAKE_BINARY_DIR}/thirdparty/SPLINTER ${EXTERNAL_INSTALL_PREFIX})


# configure build_data.h
STRING(TIMESTAMP CONFIG_TIMESTAMP)
CONFIGURE_FILE(configure_assets/build_data.h.in ${CMAKE_BINARY_DIR}/build_data.h)

# build parser
BISON_TARGET(translator/parser translator/parser/bison/y_parser.yy ${CMAKE_CURRENT_BINARY_DIR}/y_parser.cpp)
BISON_TARGET(parser translator/parser/bison/y_parser.yy ${CMAKE_CURRENT_BINARY_DIR}/y_parser.cpp)


ADD_EXECUTABLE(CppTransport
Expand Down Expand Up @@ -153,7 +161,9 @@ ADD_EXECUTABLE(CppTransport
translator/utilities/argument_cache.cpp
)

TARGET_LINK_LIBRARIES(CppTransport ${GINAC_LIBRARIES} ${Boost_LIBRARIES})
ADD_DEPENDENCIES(CppTransport DEPS)

TARGET_LINK_LIBRARIES(CppTransport ${GINAC_LIBRARIES} ${CLN_LIBRARIES} ${GMP_LIBRARIES} ${Boost_LIBRARIES})
TARGET_COMPILE_OPTIONS(CppTransport PRIVATE -std=c++14)

TARGET_INCLUDE_DIRECTORIES(CppTransport PRIVATE
Expand Down Expand Up @@ -181,25 +191,41 @@ TARGET_INCLUDE_DIRECTORIES(CppTransport PRIVATE
translator/utilities
${Boost_INCLUDE_DIRS}
${GINAC_INCLUDE_DIRS}
${CLN_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}
)


# pull in test target
ADD_SUBDIRECTORY(test-target EXCLUDE_FROM_ALL)


# install targets for CppTransport translator, templates, and header-only library/runtime API
INSTALL(TARGETS CppTransport DESTINATION bin)
INSTALL(DIRECTORY templates DESTINATION share/cpptransport)

# install HTML, CSS and JavaScript assets
INSTALL(DIRECTORY thirdparty/bootstrap DESTINATION share/cpptransport/HTML)
INSTALL(DIRECTORY thirdparty/bootstrap-tab-history DESTINATION share/cpptransport/HTML)
INSTALL(DIRECTORY thirdparty/jQuery DESTINATION share/cpptransport/HTML)
INSTALL(DIRECTORY thirdparty/prism DESTINATION share/cpptransport/HTML)
INSTALL(DIRECTORY thirdparty/DataTables DESTINATION share/cpptransport/HTML)
INSTALL(DIRECTORY HTML_assets DESTINATION share/cpptransport/HTML)
INSTALL(DIRECTORY transport-runtime DESTINATION include)
INSTALL(FILES cmake/FindCppTransport.cmake DESTINATION share/cmake)

# install runtime system
INSTALL(DIRECTORY transport-runtime DESTINATION include/cpptransport)
INSTALL(FILES ${CMAKE_BINARY_DIR}/build_data.h DESTINATION include/cpptransport/transport-runtime)

# emplace jsoncpp assets into runtime system folders
INSTALL(DIRECTORY ${EXTERNAL_INSTALL_PREFIX}/include/json DESTINATION include/cpptransport)
INSTALL(DIRECTORY ${EXTERNAL_INSTALL_PREFIX}/lib DESTINATION lib/cpptransport)

# emplace SPLINTER assets into runtime system folders
INSTALL(DIRECTORY ${EXTERNAL_INSTALL_PREFIX}/include/SPLINTER DESTINATION include/cpptransport)
INSTALL(DIRECTORY ${EXTERNAL_INSTALL_PREFIX}/lib DESTINATION lib/cpptransport)

# install CMake finder script for all these assets
CONFIGURE_FILE(cmake/FindCppTransport.cmake.in ${CMAKE_BINARY_DIR}/FindCppTransport.cmake @ONLY)
INSTALL(FILES ${CMAKE_BINARY_DIR}/FindCppTransport.cmake DESTINATION share/cmake)


## FILL IN DUMMY TARGETS FOR CLION
Expand Down
1 change: 0 additions & 1 deletion CppTransport/SPLINTER

This file was deleted.

51 changes: 51 additions & 0 deletions CppTransport/cmake/BuildDeps.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)

INCLUDE(ExternalProject)


FUNCTION(BUILD_JSONCPP BUILD_DIR INSTALL_PREFIX)

SET(JSONCPP_SRC ${BUILD_DIR}/src)
SET(JSONCPP_BIN ${BUILD_DIR}/bin)
SET(JSONCPP_INSTALL ${INSTALL_PREFIX})
SET(JSONCPP_INSTALL ${INSTALL_PREFIX} PARENT_SCOPE)

EXTERNALPROJECT_ADD(
jsoncpp
GIT_REPOSITORY https://github.com/open-source-parsers/jsoncpp.git
GIT_TAG 45da594e71ad0ac323aada534c338a308d63b84f
SOURCE_DIR ${JSONCPP_SRC}
BINARY_DIR ${JSONCPP_BIN}
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${JSONCPP_INSTALL} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
)

SET(JSONCPP_LIBRARIES ${JSONCPP_INSTALL}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}jsoncpp${CMAKE_STATIC_LIBRARY_SUFFIX} PARENT_SCOPE)
SET(JSONCPP_INCLUDE_DIRS ${JSONCPP_INSTALL}/include PARENT_SCOPE)

ADD_DEPENDENCIES(DEPS jsoncpp)

ENDFUNCTION(BUILD_JSONCPP)


FUNCTION(BUILD_SPLINTER BUILD_DIR INSTALL_PREFIX)

SET(SPLINTER_SRC ${BUILD_DIR}/src)
SET(SPLINTER_BIN ${BUILD_DIR}/bin)
SET(SPLINTER_INSTALL ${INSTALL_PREFIX})
SET(SPLINTER_INSTALL ${INSTALL_PREFIX} PARENT_SCOPE)

EXTERNALPROJECT_ADD(
SPLINTER
GIT_REPOSITORY https://github.com/bgrimstad/splinter.git
GIT_TAG 2c877c0d7f68025764f7af048cc609e5c05080e0
SOURCE_DIR ${SPLINTER_SRC}
BINARY_DIR ${SPLINTER_BIN}
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${SPLINTER_INSTALL} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
)

SET(SPLINTER_LIBRARIES ${SPLINTER_INSTALL}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}splinter-static-3-0${CMAKE_STATIC_LIBRARY_SUFFIX} PARENT_SCOPE)
SET(SPLINTER_INCLUDE_DIRS ${SPLINTER_INSTALL}/include PARENT_SCOPE)

ADD_DEPENDENCIES(DEPS SPLINTER)

ENDFUNCTION(BUILD_SPLINTER)
40 changes: 0 additions & 40 deletions CppTransport/cmake/FindCppTransport.cmake

This file was deleted.

36 changes: 36 additions & 0 deletions CppTransport/cmake/FindCppTransport.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# determine path to runtime system .h files
FIND_PATH(CPPTRANSPORT_INCLUDE_DIR NAMES transport.h PATHS @CMAKE_INSTALL_PREFIX@ PATH_SUFFIXES include/cpptransport/transport-runtime)

# determine path to pre-installed SPLINTER and JsonCpp libraries
FIND_LIBRARY(CPPTRANSPORT_SPLINTER_LIBRARY NAMES splinter-static-3-0 PATHS @CMAKE_INSTALL_PREFIX@ PATH_SUFFIXES lib/cpptransport/lib NO_DEFAULT_PATH)
FIND_LIBRARY(CPPTRANSPORT_JSONCPP_LIBRARY NAMES jsoncpp PATHS @CMAKE_INSTALL_PREFIX@ PATH_SUFFIXES lib/cpptransport/lib NO_DEFAULT_PATH)

# determine paths for system installation of Boost
FIND_PACKAGE(Boost REQUIRED COMPONENTS log system filesystem random timer date_time mpi thread serialization program_options regex)


SET(CPPTRANSPORT_INCLUDE_DIRS
${CPPTRANSPORT_INCLUDE_DIR}/..
${CPPTRANSPORT_INCLUDE_DIR}/../SPLINTER
${Boost_INCLUDE_DIRS}
)


SET(CPPTRANSPORT_LIBRARIES
${CPPTRANSPORT_SPLINTER_LIBRARY}
${CPPTRANSPORT_JSONCPP_LIBRARY}
${Boost_LIBRARIES}
)


INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(CppTransport DEFAULT_MSG
CPPTRANSPORT_INCLUDE_DIR
CPPTRANSPORT_SPLINTER_LIBRARY
CPPTRANSPORT_JSONCPP_LIBRARY
)


MARK_AS_ADVANCED(
CPPTRANSPORT_INCLUDE_DIR
)
25 changes: 25 additions & 0 deletions CppTransport/configure_assets/build_data.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Created by David Seery on 20/04/2016.
// Copyright (c) 2016 University of Sussex. All rights reserved.
//

#ifndef CPPTRANSPORT_BUILD_DATA_H
#define CPPTRANSPORT_BUILD_DATA_H


#include <string>


namespace build_data
{

const std::string config_timestamp = "${CONFIG_TIMESTAMP}";
const std::string c_compiler = "${CMAKE_C_COMPILER_ID}";
const std::string cpp_compiler = "${CMAKE_CXX_COMPILER_ID}";
const std::string build_type = "${CMAKE_BUILD_TYPE}";
const std::string system_name = "${CMAKE_SYSTEM}";

} // namespace build_data


#endif //CPPTRANSPORT_BUILD_DATA_H
13 changes: 6 additions & 7 deletions CppTransport/test-target/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ PROJECT(test-target)
# don't use FindCppTransport package; want to pull in headers from the source tree,
# not from any already installed elsewhere on the system
#FIND_PACKAGE(CppTransport REQUIRED)
FIND_PACKAGE(MPI REQUIRED)
FIND_PACKAGE(Boost 1.56 REQUIRED COMPONENTS system filesystem random timer date_time mpi log_setup log serialization thread program_options regex)
#FIND_PACKAGE(MPI REQUIRED)
#FIND_PACKAGE(Boost 1.56 REQUIRED COMPONENTS system filesystem random timer date_time mpi log_setup log serialization thread program_options regex)
#find_package(CUDA REQUIRED)
#find_package(OpenCL REQUIRED)


SET(CPPTRANSPORT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
SET(CPPTRANSPORT_JSONCPP_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../thirdparty/jsoncpp/include)
SET(CPPTRANSPORT_SPLINTER_EIGEN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../thirdparty/splinter/thirdparty/Eigen)


# main SPLINTER includes have a different relative position in the build tree
Expand All @@ -27,12 +25,13 @@ SET(CPPTRANSPORT_SPLINTER_EIGEN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../thirdparty/sp
SET(
CPPTRANSPORT_INCLUDE_DIRS
${CPPTRANSPORT_INCLUDE_DIR}
${CPPTRANSPORT_JSONCPP_INCLUDE_DIR}
${CPPTRANSPORT_SPLINTER_EIGEN_DIR}
${JSONCPP_INCLUDE_DIRS}
${SPLINTER_INCLUDE_DIRS}
${SPLINTER_INCLUDE_DIRS}/SPLINTER
)


SET(CPPTRANSPORT_LIBRARIES jsoncpp_lib_static splinter-static-2-0)
SET(CPPTRANSPORT_LIBRARIES ${JSONCPP_LIBRARIES} ${SPLINTER_LIBRARIES})


ADD_CUSTOM_COMMAND(
Expand Down
1 change: 0 additions & 1 deletion CppTransport/thirdparty/jsoncpp
Submodule jsoncpp deleted from 45da59
1 change: 0 additions & 1 deletion CppTransport/thirdparty/splinter
Submodule splinter deleted from 88e502
10 changes: 6 additions & 4 deletions CppTransport/transport-runtime/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
// Copyright (c) 2013-2016 University of Sussex. All rights reserved.
//

#ifndef CPPTRANSPORT_TRANSPORT_H_
#define CPPTRANSPORT_TRANSPORT_H_
#ifndef CPPTRANSPORT_TRANSPORT_H
#define CPPTRANSPORT_TRANSPORT_H


// expect Boost to be linked with dynamic libraries;
// note this macro is essential for Boost.Log
#define BOOST_ALL_DYN_LINK
#define FUSION_MAX_VECTOR_SIZE 20

#include "transport-runtime/messages.h"
#include "transport-runtime/defaults.h"
Expand All @@ -29,4 +31,4 @@
#include "transport-runtime/manager/task_manager.h"


#endif // CPPTRANSPORT_TRANSPORT_H_
#endif // CPPTRANSPORT_TRANSPORT_H
21 changes: 11 additions & 10 deletions CppTransport/transport-runtime/utilities/spline1d.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
//
//

#ifndef CPPTRANSPORT_SPLINE_H_
#define CPPTRANSPORT_SPLINE_H_
#ifndef CPPTRANSPORT_SPLINE_H
#define CPPTRANSPORT_SPLINE_H


#include <vector>
Expand All @@ -15,8 +15,9 @@
#include <assert.h>

#include "SPLINTER/datatable.h"
#include "SPLINTER/bsplineapproximant.h"
#include "SPLINTER/psplineapproximant.h"
#include "SPLINTER/bspline.h"
#include "SPLINTER/bsplinebuilder.h"


namespace transport
{
Expand Down Expand Up @@ -93,12 +94,12 @@ namespace transport
//! which also deals correctly with taking copies.
//! This is a raw BSpline, meaning that it goes through each of the data points.
//! We use it to interpolate values.
std::shared_ptr<SPLINTER::BSplineApproximant> b_spline;
std::shared_ptr<SPLINTER::BSpline> b_spline;

//! pointer to penalized-B spline object.
//! This is smoothed, so it need not go through every data point.
//! We use it to interpolate derivatives
std::shared_ptr<SPLINTER::PSplineApproximant> p_spline;
std::shared_ptr<SPLINTER::BSpline> p_spline;

//! DataTable instance
SPLINTER::DataTable table;
Expand Down Expand Up @@ -139,8 +140,8 @@ namespace transport

try
{
b_spline = std::make_shared<SPLINTER::BSplineApproximant>(table, SPLINTER::BSplineType::CUBIC);
p_spline = std::make_shared<SPLINTER::PSplineApproximant>(table, 0.03);
b_spline = std::make_shared<SPLINTER::BSpline>(SPLINTER::BSpline::Builder(table).degree(3).build());
p_spline = std::make_shared<SPLINTER::BSpline>(SPLINTER::BSpline::Builder(table).degree(3).smoothing(SPLINTER::BSpline::Smoothing::PSPLINE).alpha(0.03).build());
}
catch(SPLINTER::Exception& xe)
{
Expand Down Expand Up @@ -172,7 +173,7 @@ namespace transport
template <typename number>
void spline1d<number>::write(std::ostream& out) const
{
for(std::multiset<SPLINTER::DataSample>::const_iterator t = this->table.cbegin(); t != this->table.cend(); ++t)
for(std::multiset<SPLINTER::DataPoint>::const_iterator t = this->table.cbegin(); t != this->table.cend(); ++t)
{
assert(t->getDimX() == 1);
out << "x = " << t->getX()[0] << ", y = " << t->getY() << '\n';
Expand All @@ -191,4 +192,4 @@ namespace transport
} // namespace transport


#endif // CPPTRANSPORT_SPLINE_H_
#endif // CPPTRANSPORT_SPLINE_H

0 comments on commit f59bef0

Please sign in to comment.