I am new to cmake and am trying to build my fortran project with an external library that has been added as a git submodule to my project repository. The external project has a CMakeLists.txt file and can be built using CMake. However, I am having hard time trying to build my project with it.
....
include_directories(${CMAKE_SOURCE_DIR}/external/{package}/include)
add_executable(myproject ${SUBROUTINES} ${MODULES} ${libraries})
# Link to the library
target_link_libraries(myproject PUBLIC package)
# Link libraries
# target_link_libraries(myprojtect ${libraries} package)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)
I use simple use {package} in my fortran code to reference the package. However, when I try to build with CMake I get the following error:
~/myproject/src/mymodule.f90(4): error #7002: Error in opening the compiled module file. Check INCLUDE paths.
I did but even then my target compilation fails as the module in my project is not ablet find the external package. How do I link my target explicitly with an external library compiled with cmake?
If you’ve done add_subdirectory then the external library should have been defined as a target in CMake and you use target_link_libraries to make your target link against the external library.