exercism / cpp

Exercism exercises in C++.
https://exercism.org/tracks/cpp
MIT License
257 stars 212 forks source link

"Cannot find source file" when header has file extension .hpp #247

Closed hickford closed 5 years ago

hickford commented 5 years ago

My tooling requires I use extension .hpp rather than .h for header files. This gives an error from cmake.

CMake Error at CMakeLists.txt:27 (add_executable): Cannot find source file:

nucleotide_count.h

Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx

NobbZ commented 5 years ago

Either teach your tooling to accept *.h as well, or change the line that CMake is complaining about to search for hpp. You also need to change the Testfile then to include the hpp.

arcuru commented 5 years ago

@NobbZ is correct, there isn't a reasonable way for us to support both naming conventions.

Thanks

hickford commented 5 years ago

If it helps anyone else, here's a patch for CMakeLists.txt

@@ -26,4 +26,10 @@
+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.hpp)
+    set(exercise_header ${file}.hpp)
+else()
+    set(exercise_header ${file}.h)
+endif()
+
 # Build executable from sources and headers
-add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h)
+add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${exercise_header})

I'd send a pull request but not sure how to update 47 files

NobbZ commented 5 years ago

This wouldn't solve the problem, as you still need to fix the Testsuite manually. And you can not avoid that unless you create some additional compilation there. That again would clutter the testfiles