I used awk for quite a long time, but not his brother sed. A couple of days ago I want to insert two lines for a CMake file in a specific position and find a perfect answer: here.
Now I could add two lines by using:
sed -i '/^enable_language/i set(CMAKE_CUDA_ARCHITECTURES 86)\nset(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)' \ cmake/public/cuda.cmake
The CMake file changed from:
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_C_COMPILER}") endif() enable_language(CUDA) set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD}) set(CMAKE_CUDA_STANDARD_REQUIRED ON)
to
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_C_COMPILER}") endif() set(CMAKE_CUDA_ARCHITECTURES 86) set(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc) enable_language(CUDA) set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD}) set(CMAKE_CUDA_STANDARD_REQUIRED ON)