Linker errors when compiling a CMake application manually

I have this CMake application defined in a CMakeLists.txt file which compiles perfectly when building with CMake. However, when I try to compile it manually (using mpicc -fopenmp src/main.c) I get linker errors for all the functions I've defined in separate files.

Project file structure :

.
├── CMakeLists.txt
├── libs
│   ├── common
│   │   ├── init
│   │   │   ├── init.c
│   │   │   └── init.h
│   │   ├── palindrome
│   │   │   ├── palindrome.c
│   │   │   └── palindrome.h
│   │   └── print
│   │       ├── print.c
│   │       └── print.h
│   ├── mpi
│   │   ├── main_mpi.c
│   │   └── main_mpi.h
│   ├── openmp
│   │   ├── main_openmp.c
│   │   └── main_openmp.h
│   └── sequential
│       ├── main_sequential.c
│       └── main_sequential.h
├── LICENSE
├── README.md
└── src
    └── main.c

CMakeLists.txt :

cmake_minimum_required(VERSION 3.21)
project(<project-name> C)

set(CMAKE_C_STANDARD 23)

find_package(MPI REQUIRED)
include_directories(SYSTEM ${MPI_INCLUDE_PATH})

find_package(OpenMP REQUIRED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")

add_executable(<project-name> src/main.c libs/common/init/init.c libs/common/init/init.h libs/common/print/print.c libs/common/print/print.h libs/common/palindrome/palindrome.c libs/common/palindrome/palindrome.h libs/sequential/main_sequential.c libs/sequential/main_sequential.h libs/openmp/main_openmp.c libs/openmp/main_openmp.h libs/mpi/main_mpi.c libs/mpi/main_mpi.h)
target_link_libraries(<project-name> ${MPI_C_LIBRARIES})

I have a feeling I need to use the -I argument when compiling but I'm not sure how.

I therefore have 2 questions :

  1. How would I go about compiling it manually while linking libraries under libs/ ?
  2. I'm not a fan of the very long add_executable line (it was generated automatically for me by CLion). Is it possible to split it into multiple lines ? Better yet, is it possible to use wildcards ?
How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum