2

My c++ program needs a folder path and I like to input from cmake configuration. For example, my c++ program is

int main(){
std::string pretrained_binary_proto("/home/Softwares/Libraries/caffe-master/models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel");
}

I like to set this folder path using cmake.

/home/Softwares/Libraries/caffe-master/models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel

In my CMakeLists.txt, I have

set(CAFFE_MODEL_PATH         "/home/nyan/Softwares/Libraries/caffe-master/models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel")

But I don't see that CAFFE_MODEL_PATH in my ccmake.. configuration. Then how can I include that path to my program?

4

1 回答 1

2

“简单”的方式:

add_definitions(-DCAFFE_MODEL_PATH=\"${CAFFE_MODEL_PATH}\")

然后CAFFE_MODEL_PATH在代码中使用常量。


如果您有许多这样的定义,则更首选的方式是:

  1. 使用. yourproject-config.h.cmake_#cmakedefine CAFFE_MODEL_PATH
  2. 利用configure_file(yourproject-config.h.cmake yourproject-config.h)
  3. 不要忘记include_directorties(${CMAKE_CURRENT_BINARY_PATH})
  4. #include "yourproject-config.h"无论何时何地,您都需要访问您的常量。
于 2017-02-13T05:25:12.513 回答