cmake build problem
Created by: dzhwinter
I want to know how to write cmake script to build target. I was keep going the wrong way when I include protobuf header file.
for example, I just write a TestCase for Parameter.h, I have to include the ParameterConfig.pb.h.
#include <gtest/gtest.h>
#include "paddle/parameter/Parameter.h"
#include "ParameterConfig.pb.h"
#include "TrainerConfig.pb.h"
TEST(Parameter, testConfig) { paddle::ParameterConfig config;
config.set_name("test");
config.set_learning_rate(0.1);
std::string data; config.SerializeToString(&data);
EXPECT_TRUE(false) << data;
paddle::ParameterConfig ans;
ans.ParseFromString(data);
CHECK_EQ(ans.name, "test"); CHECK_EQ(ans.learning_rate, 0.1);
}
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
initMain(argc, argv);
return RUN_ALL_TESTS();
}
Then a write the cmake script in this way.
solution 1.
add_executable(test_parameter test_parameter.cpp)
target_link_libraries(test_parameter gen_cpp_proto)
solution 2.
add_dependencies(test_Parameter gen_cpp_proto)
add_test(NAME test_Parameter
COMMAND test_Parameter
) # add_simple_unittest(test_parameter)
however, it complain me about the third_party include header error, I can't fix it.
Building CXX object paddle/parameter/tests/CMakeFiles/test_parameter.dir/test_parameter.cpp.o
In file included from /home/work/dongzhihong/github/Paddle/dzhPaddle/paddle/utils/Logging.h:25:0,
from /home/work/dongzhihong/github/Paddle/dzhPaddle/paddle/math/Matrix.h:21,
from /home/work/dongzhihong/github/Paddle/dzhPaddle/paddle/parameter/Parameter.h:27,
from /home/work/dongzhihong/github/Paddle/dzhPaddle/paddle/parameter/tests/test_parameter.cpp:2:
/home/work/dongzhihong/github/Paddle/dzhPaddle/paddle/parameter/tests/test_parameter.cpp: In member function ‘virtual void Parameter_testConfig_Test::TestBody
()’:
/home/work/dongzhihong/github/Paddle/dzhPaddle/third_party/install/glog/include/glog/logging.h:745:48: error: no matching function for call to ‘GetReferenceab
leValue(<unresolved overloaded function type>)’
google::GetReferenceableValue(val1), \
^
/home/work/dongzhihong/github/Paddle/dzhPaddle/third_party/install/glog/include/glog/logging.h:764:3: note: in expansion of macro ‘CHECK_OP_LOG’
CHECK_OP_LOG(name, op, val1, val2, google::LogMessageFatal)
^
/home/work/dongzhihong/github/Paddle/dzhPaddle/third_party/install/glog/include/glog/logging.h:788:30: note: in expansion of macro ‘CHECK_OP’
#define CHECK_EQ(val1, val2) CHECK_OP(_EQ, ==, val1, val2)