Redesign cmake
Tune the makefile according to new principles, which adds a few bells
and whistles and for clarity.
Synopsis:
* The dependency on opm-common is completely gone. This is reflected in
travis and appveyor as well. No non-kitware cmake modules are used.
* Directories are flattened, quite a bit - source code is located in the
lib/ directory if it belongs to opm-parser, and external/ if third
party.
* The sibling build feature is implemented through cmake's
export(PACKAGE) rather than implicitly looking through source files.
* Targets explicitly set required public and private include
directories, compile options and definitions, which cmake will handle
and propagate
* opm-parser-config.cmake for downstream users is now provided.
* Dependencies are set up using targets. In the future, when cmake 3.x+
can be used, these should be either targets from newer Find modules,
or interface libraries.
* Fewer system specific assumptions are coded in, instead we assume
cmake or users set up system specific details.
* All module wide configuration and looking up libraries is handled in
the root makefile - all sub directories only set up libraries and
compile options for the module in question.
* Targets are defined and links handled transitively because cmake now
is told about them. ${module_LIBRARIES} variables are gone.
This is largely guided by the principles outlined in
https://rix0r.nl/blog/2015/08/13/cmake-guide/
Most source files are just moved - if they have some content change then
it's nothing more than include fixes or similar in order to make them
compile.
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
Copyright 2016 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <opm/parser/eclipse/Utility/Functional.hpp>
|
||||
|
||||
namespace Opm {
|
||||
namespace fun {
|
||||
|
||||
iota::iota( int fst, int lst ) : first( fst ), last( lst ) {}
|
||||
|
||||
iota::iota( int lst ) : iota( 0, lst ) {}
|
||||
|
||||
size_t iota::size() const {
|
||||
return this->last - this->first;
|
||||
}
|
||||
|
||||
iota::const_iterator iota::begin() const {
|
||||
return { first };
|
||||
}
|
||||
|
||||
iota::const_iterator iota::end() const {
|
||||
return { last };
|
||||
}
|
||||
|
||||
int iota::const_iterator::operator*() const {
|
||||
return this->value;
|
||||
}
|
||||
|
||||
iota::const_iterator& iota::const_iterator::operator++() {
|
||||
++( this->value );
|
||||
return *this;
|
||||
}
|
||||
|
||||
iota::const_iterator iota::const_iterator::operator++( int ) {
|
||||
iota::const_iterator copy( *this );
|
||||
this->operator++();
|
||||
return copy;
|
||||
}
|
||||
|
||||
bool iota::const_iterator::operator==( const const_iterator& rhs ) const {
|
||||
return this->value == rhs.value;
|
||||
}
|
||||
|
||||
bool iota::const_iterator::operator!=( const const_iterator& rhs ) const {
|
||||
return !(*this == rhs );
|
||||
}
|
||||
|
||||
iota::const_iterator::const_iterator( int x ) : value( x ) {}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
#include <iterator>
|
||||
#include <ostream>
|
||||
|
||||
#include <opm/parser/eclipse/Utility/Stringview.hpp>
|
||||
|
||||
std::ostream& Opm::operator<<( std::ostream& stream, const Opm::string_view& view ) {
|
||||
std::copy( view.begin(), view.end(), std::ostream_iterator< char >( stream ) );
|
||||
return stream;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
foreach(tapp FunctionalTests StringviewTests StringTests )
|
||||
|
||||
opm_add_test(run${tapp} SOURCES ${tapp}.cpp
|
||||
LIBRARIES opmparser ${Boost_LIBRARIES})
|
||||
|
||||
endforeach()
|
||||
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
Copyright 2016 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#define BOOST_TEST_MODULE FunctionalTests
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Utility/Functional.hpp>
|
||||
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestMap) {
|
||||
std::map<std::string, int> m = { {"C", 3}, {"B" , 2} , {"A" , 1}};
|
||||
std::vector<std::string> keys_expected = {"A" , "B" , "C"};
|
||||
auto keys = fun::map( [] ( const std::pair<std::string,int>& pair) { return pair.first; } , m);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(keys.begin(), keys.end(),
|
||||
keys_expected.begin(), keys_expected.end());
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestConcat) {
|
||||
std::vector<std::vector<int>> vector_of_vectors = {{1},{2,2},{3,3,3}};
|
||||
auto conc = fun::concat( std::move(vector_of_vectors) );
|
||||
std::vector<int> expected = {1,2,2,3,3,3};
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(conc.begin(), conc.end(),
|
||||
expected.begin(), expected.end());
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestConcatMap) {
|
||||
std::vector<int> input = {1,2,3};
|
||||
auto conc = fun::concat( fun::map( []( int x ) { return std::vector<int>( x,x ); } , input));
|
||||
|
||||
std::vector<int> expected = {1,2,2,3,3,3};
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(conc.begin(), conc.end(),
|
||||
expected.begin(), expected.end());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(iotaEqualCollections) {
|
||||
std::vector< int > vec( 5 );
|
||||
|
||||
for( int i = 0; i < 5; ++i )
|
||||
vec[ i ] = i;
|
||||
|
||||
fun::iota iota( 5 );
|
||||
for( auto x : iota )
|
||||
std::cout << x << " ";
|
||||
std::cout << std::endl;
|
||||
std::vector< int > vec_iota( iota.begin(), iota.end() );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
vec_iota.begin(), vec_iota.end(),
|
||||
vec.begin(), vec.end() );
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
vec_iota.begin(), vec_iota.end(),
|
||||
fun::iota( 5 ).begin(), fun::iota( 5 ).end() );
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
vec.begin(), vec.end(),
|
||||
fun::iota( 5 ).begin(), fun::iota( 5 ).end() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(iotaForeach) {
|
||||
/* this test is mostly a syntax verification test */
|
||||
|
||||
std::vector< int > vec = { 0, 1, 2, 3, 4 };
|
||||
|
||||
for( auto x : fun::iota( 5 ) )
|
||||
BOOST_CHECK_EQUAL( vec[ x ], x );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(iotaSize) {
|
||||
BOOST_CHECK_EQUAL( 5, fun::iota( 5 ).size() );
|
||||
BOOST_CHECK_EQUAL( 5, fun::iota( 1, 6 ).size() );
|
||||
BOOST_CHECK_EQUAL( 0, fun::iota( 0 ).size() );
|
||||
BOOST_CHECK_EQUAL( 0, fun::iota( 0, 0 ).size() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(iotaWithMap) {
|
||||
const auto plus1 = []( int x ) { return x + 1; };
|
||||
|
||||
std::vector< int > vec = { 1, 2, 3, 4, 5 };
|
||||
auto vec_iota = fun::map( plus1, fun::iota( 5 ) );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
vec_iota.begin(), vec_iota.end(),
|
||||
vec.begin(), vec.end() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(iotaNegativeBegin) {
|
||||
const auto vec = { -4, -3, -2, -1, 0 };
|
||||
|
||||
fun::iota iota( -4, 1 );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
vec.begin(), vec.end(),
|
||||
iota.begin(), iota.end() );
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
#define BOOST_TEST_MODULE StringTests
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Utility/String.hpp>
|
||||
#include <opm/parser/eclipse/Utility/Stringview.hpp>
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE( uppercase_copy ) {
|
||||
const std::string src = "string";
|
||||
const std::string dst = uppercase( src );
|
||||
|
||||
BOOST_CHECK_EQUAL( src, "string" );
|
||||
BOOST_CHECK_EQUAL( dst, "STRING" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( uppercase_inplace ) {
|
||||
std::string src = "string";
|
||||
auto& ref = uppercase( src, src );
|
||||
|
||||
BOOST_CHECK_EQUAL( src, "STRING" );
|
||||
BOOST_CHECK_EQUAL( src, ref );
|
||||
BOOST_CHECK_EQUAL( std::addressof( src ), std::addressof( ref ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( nonconst_ref ) {
|
||||
std::string src = "string";
|
||||
auto dst = uppercase( src );
|
||||
|
||||
BOOST_CHECK_EQUAL( src, "string" );
|
||||
BOOST_CHECK_EQUAL( dst, "STRING" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( uppercase_move ) {
|
||||
std::string src = "string";
|
||||
auto dst = uppercase( std::move( src ) );
|
||||
|
||||
BOOST_CHECK_EQUAL( dst, "STRING" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( uppercase_mixed_type ) {
|
||||
std::string src = "string";
|
||||
string_view view( src );
|
||||
|
||||
|
||||
std::string dst = "string";
|
||||
uppercase( view, dst );
|
||||
BOOST_CHECK_EQUAL( dst, "STRING" );
|
||||
BOOST_CHECK_EQUAL( view, "string" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( write_parts_of_dst ) {
|
||||
std::string src = "string";
|
||||
string_view view( src );
|
||||
|
||||
|
||||
std::string dst = "stringmixed";
|
||||
uppercase( view, dst );
|
||||
BOOST_CHECK_EQUAL( dst, "STRINGmixed" );
|
||||
BOOST_CHECK_EQUAL( view, "string" );
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
#define BOOST_TEST_MODULE StringviewTests
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Utility/Stringview.hpp>
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(fullStringView) {
|
||||
std::string srcstr = "lorem ipsum";
|
||||
string_view view( srcstr );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
srcstr.begin(), srcstr.end(),
|
||||
view.begin(), view.end() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(viewCorrectSize) {
|
||||
std::string srcstr = "lorem ipsum";
|
||||
|
||||
string_view full( srcstr );
|
||||
BOOST_CHECK_EQUAL( srcstr.size(), full.size() );
|
||||
|
||||
string_view view( srcstr, 5 );
|
||||
BOOST_CHECK_EQUAL( 5, view.size() );
|
||||
BOOST_CHECK_EQUAL( 5, view.length() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(viewOperatorAt) {
|
||||
std::string srcstr = "lorem ipsum";
|
||||
string_view view( srcstr );
|
||||
|
||||
for( size_t i = 0; i < view.size(); ++i )
|
||||
BOOST_CHECK_EQUAL( view[ i ], srcstr[ i ] );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(viewFrontBack) {
|
||||
std::string srcstr = "lorem ipsum";
|
||||
string_view view( srcstr );
|
||||
|
||||
BOOST_CHECK_EQUAL( view.front(), 'l' );
|
||||
BOOST_CHECK_EQUAL( view.back(), 'm' );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(viewSubstr) {
|
||||
std::string srcstr = "lorem ipsum";
|
||||
string_view view( srcstr );
|
||||
|
||||
BOOST_CHECK_NO_THROW( view.string() );
|
||||
BOOST_CHECK_EQUAL( srcstr, view.string() );
|
||||
BOOST_CHECK_EQUAL( srcstr, view.substr() );
|
||||
BOOST_CHECK_EQUAL( "", view.substr( 0, 0 ) );
|
||||
|
||||
BOOST_CHECK_EQUAL( srcstr.substr( 1 ), view.substr( 1 ) );
|
||||
|
||||
BOOST_CHECK_THROW( view.substr( srcstr.size() + 1 ), std::out_of_range );
|
||||
BOOST_CHECK_THROW( view.substr( 0, srcstr.size() + 1 ), std::out_of_range );
|
||||
BOOST_CHECK_THROW( view.substr( 1, 0 ), std::invalid_argument );
|
||||
BOOST_CHECK_NO_THROW( view.substr( 0, 0 ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(viewStream) {
|
||||
std::string srcstr = "lorem ipsum";
|
||||
string_view view( srcstr );
|
||||
|
||||
std::stringstream str;
|
||||
str << view;
|
||||
|
||||
BOOST_CHECK_EQUAL( srcstr, str.str() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(equalityOperators) {
|
||||
std::string srcstr = "lorem ipsum";
|
||||
std::string diffstr = "lorem";
|
||||
string_view view( srcstr );
|
||||
|
||||
BOOST_CHECK_EQUAL( srcstr, view );
|
||||
BOOST_CHECK_NE( diffstr, view );
|
||||
|
||||
BOOST_CHECK_EQUAL( view, srcstr );
|
||||
BOOST_CHECK_NE( view, diffstr );
|
||||
|
||||
BOOST_CHECK_EQUAL( "lorem ipsum", view );
|
||||
BOOST_CHECK_NE( "lorem", view );
|
||||
|
||||
BOOST_CHECK_EQUAL( view, "lorem ipsum" );
|
||||
BOOST_CHECK_NE( view, "lorem" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(plusOperator) {
|
||||
std::string total = "lorem ipsum";
|
||||
std::string lhs = "lorem";
|
||||
std::string ws = " ";
|
||||
std::string rhs = "ipsum";
|
||||
|
||||
string_view lhs_view( lhs );
|
||||
string_view rhs_view( rhs );
|
||||
|
||||
BOOST_CHECK_EQUAL( total, lhs_view + ws + rhs_view );
|
||||
BOOST_CHECK_EQUAL( lhs + ws, lhs_view + ws );
|
||||
BOOST_CHECK_EQUAL( ws + rhs, ws + rhs_view );
|
||||
}
|
||||
Reference in New Issue
Block a user