I am able to build a simple application using a MakeFile with the contents…
# specify the compiler
CXX=g++
# specify any compile-time flags
CXXFLAGS=-Wall -g
# specify the build target
TARGET=app.out
# specify the FFTW3 library path
FFTW_DIR=/opt/ohpc/pub/libs/gnu7/openmpi/fftw/3.3.7
# specify the FFTW3 library flags
FFTW_LIB=-lfftw3
# specify any directories containing header files other than /usr/include
INCLUDES=-I$(FFTW_DIR)/include
# specify library paths other than /usr/lib
LFLAGS=-L$(FFTW_DIR)/lib
# define the C++ source files
SRCS=main.cpp
# define the C++ object files
OBJS=$(SRCS:.cpp=.o)
.PHONY: depend clean
all: $(TARGET)
@echo Compilation has been completed successfully.
$(TARGET): $(OBJS)
$(CXX) $(CXXFLAGS) $(INCLUDES) -o $(TARGET) $(OBJS) $(LFLAGS) $(FFTW_LIB)
.cpp.o:
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
clean:
$(RM) *.o *~ $(TARGET)
depend: $(SRCS)
makedepend $(INCLUDES) $^
I would like to get this working using CMake. So I’ve created the following CMakeLists.txt…
cmake_minimum_required(VERSION 3.15)
set(CMAKE_CXX_STANDARD 17)
project(app)
add_executable(app.out
main.cpp
/opt/ohpc/pub/libs/gnu7/openmpi/fftw/3.3.7/include/fftw3.h)
target_link_libraries(app.out /opt/ohpc/pub/libs/gnu7/openmpi/fftw/3.3.7/lib/fftw3)
target_include_directories(app.out PRIVATE /opt/ohpc/pub/libs/gnu7/openmpi/fftw/3.3.7/include)
When I try to make the application now, I get:
Consolidate compiler generated dependencies of target app.out
make[2]: *** No rule to make target '/opt/ohpc/pub/libs/gnu7/openmpi/fftw/3.3.7/lib/fftw3', needed by 'app.out'. Stop.
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/app.out.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
I’m not sure how to add a rule to make fftw3 needed by app.out.