我正在用c ++编写一段代码。程序应该从CSV文件中读取数据,然后在将其写入另一个CSV输出文件之前进行一些处理。当我用以下代码编译它时,我的程序正确读入文件。
make version1.cc
然而,当我尝试用我的CMakeLists.txt编译它时,它甚至都没有去寻找文件。我这么做了,但没有成功:
add_custom_command(
OUTPUT Output.csv
COMMAND version1 ${CMAKE_CURRENT_SOURCE_DIR}/Input.csv ${CMAKE_CURRENT_BINARY_DIR}/Output.csv
DEPENDS version1 ${CMAKE_CURRENT_SOURCE_DIR}/Input.csv
)
add_executable(version1 version1.cc Output.csv)
我也试过以下,仍然没有运气:
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)
SET(MY_CSV_PATH "${CMAKE_CURRENT_SOURCE_DIR}/House1-July-Complete.csv")
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/version1.cc ${CMAKE_CURRENT_BINARY_DIR}/version1.cc @ONLY)
答案 0 :(得分:1)
长话短说:
add_executable(version1 version1.cc)
set(input_csv ${CMAKE_CURRENT_SOURCE_DIR}/Input.csv)
set(output_csv ${CMAKE_CURRENT_BINARY_DIR}/Output.csv)
add_custom_command(
OUTPUT ${output_csv}
COMMAND version1 ${input_csv} ${output_csv}
DEPENDS version1 ${input_csv}
)
add_custom_target(process_csv
ALL # means that this custom target is also included in the ALL target
DEPENDS ${output_csv}
)
然后应该调用make
,make all
或make process_csv
。