0

I'm trying to write a CMakelist.txt for my project but it doesn't seem to find the CSV file that my program reads in. This is what I've tried so far:

# this can be much lower
cmake_minimum_required(VERSION 3.17)

project(monte_carlo)

add_executable(monte_carlo)

file(GLOB_RECURSE ALL_FILES src/*.cpp include/*.h ${CMAKE_CURRENT_SOURCE_DIR}/*.csv)

target_sources(monte_carlo
        PRIVATE
                ${ALL_FILES}
)

target_include_directories(monte_carlo
        PRIVATE
                ${CMAKE_CURRENT_SOURCE_DIR}/include
)

target_compile_features(monte_carlo
        PRIVATE
                cxx_std_17
)

target_compile_options(monte_carlo
        PRIVATE
                $<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra -Wpedantic -ffast-math>
                $<$<CXX_COMPILER_ID:Clang>:-Wall -Wpedantic -ffast-math>
                $<$<CXX_COMPILER_ID:MSVC>:/W4>
)

where I've added ${CMAKE_CURRENT_SOURCE_DIR}/*.csv in an attempt to let the make file find my csv file but this doesn't seem to work. I'm not too keen on how CMAKE works (most of the above I've copy pasted from other places) so if there's something else I'm missing (or something I don't need or should change, or if you just want to explain what I'm actually doing) please feel free to let me know. This is the repo I'm working on:

https://github.com/OscarUngsgard/Cpp-Monte-Carlo-Value-at-Risk-Engine

Where the file I'm trying to read in the main file of my program is riskFactorsnew.csv in the root directory.

Oscar
  • 279
  • 1
  • 10
  • If your program reads the CSV file, you have to place the CSV file in the location that is specified in the C++ code. If your C++ program doesn't specify a path (i.e. only `"riskFactorsnew.csv"`), you'll need to place the CSV file in the *same* directory as your executable. CMake can help achieve this using the approaches in [this](https://stackoverflow.com/questions/34799916/copy-file-from-source-directory-to-binary-directory-using-cmake) post. – Kevin Jun 21 '20 at 15:23
  • Ah I see, thank you. I tried adding this now and it works: ´file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/riskFactorsnew.csv DESTINATION ${CMAKE_CURRENT_BINARY_DIR})´ But it would be better if I could make it more general by having it copy any CSV file in the source directory I think so the user can easily use his own input file. How can I do that? I tried just putting ´${CMAKE_CURRENT_SOURCE_DIR}/*.csv´ but that doesn't seem to work. – Oscar Jun 21 '20 at 15:47
  • 1
    Sorry, I think found the answer by doing this: https://stackoverflow.com/questions/24311402/copy-all-files-with-given-extension-to-output-directory-using-cmake. Thank you again for the help – Oscar Jun 21 '20 at 15:52

0 Answers0