[CMake] Include directory issue ... -I are not separated?

Ateljevich, Eli eli at water.ca.gov
Wed Jun 20 11:06:40 EDT 2012


Addendum: I should add that by now I have taken the failure line, put a space in between the two -I components and run it directly in the shell and verified it compiles fine (and without the space it fails as in cmake).


Hi Eric,
Very kind of you to reply. It is true that my example had some detritus from one of the examples that I did not prune. I apologize for the sloppiness and your advice certainly saves me some problems with the linker later. However, it does not change the compile behavior. If I understood you correctly with your advice the new file is:

add_library(Hydro file1.F90 file2.F90 sflux_9c.F90)

include_directories ( $(NETCDF_INC) )


add_executable (mymain mymain.F90 )


target_link_libraries (pmymain Hydro $(NETCDF_LIBRARIES) )


and the failure remains as below with the glued together -I lines:
cd /home/myproj_cmake/build/Hydro && /usr/local/dms/pkg/openmpi/1.4.3-intel12.0/bin/mpif90  -o CMakeFiles/Hydro.dir/sflux_9c.F90.o  -I/home/myproj_cmake/src/Hydro/-I/usr/local/dms/pkg/netcdf/4.1.3-intel12.0-parallel/include   -c /home/myproj_cmake/src/Hydro/sflux_9c.F90

Anything you would recommend? Where does the reference to Hydro even come from? Thanks!


-----Original Message-----
From: Eric Noulard [mailto:eric.noulard at gmail.com] 
Sent: Tuesday, June 19, 2012 10:57 PM
To: Ateljevich, Eli
Cc: cmake at cmake.org
Subject: Re: [CMake] Include directory issue ... -I are not separated?

2012/6/20 Ateljevich, Eli <eli at water.ca.gov>:
> Hi everone. I am getting a funny include flag and I wonder if anyone can help. The project is in Fortran (though I don't think this matters) and the structure can be distilled to:
>
> /myproj
>   /build
>   /src
>      /Hydro
>
> I do the build in /build in linux using "cmake -DCMAKE_Fortran_COMPILER  ../src".
>
> The /src and /src/Hydro CMakeLists.txt are given below and I try to include and link to the external netcdf library which is where I say it is -- I use the same envvar in a GNU makefile system. The library includes are actually needed in only the third file sflux_9c.F90, and it is on this file that the build fails:
>
> cd /home/myproj_cmake/build/Hydro && /usr/local/dms/pkg/openmpi/1.4.3-intel12.0/bin/mpif90  -o CMakeFiles/Hydro.dir/sflux_9c.F90.o  -I/home/myproj_cmake/src/Hydro/-I/usr/local/dms/pkg/netcdf/4.1.3-intel12.0-parallel/include   -c /home/myproj_cmake/src/Hydro/sflux_9c.F90
>
> Could it be because the two -I includes are glued together? Come to think of it, I did nothing to request the  -I/home/myproj_cmake/src/Hydro/ part though I don't object to it. Can someone explain what I am doing wrong or give me a workaround?

I think you misuse some CMake directive, keep reading...

>
> Very grateful,
> Eli
>
> ========= /src
> cmake_minimum_required (VERSION 2.6)
> project(MYPROJ)
> enable_language (Fortran)
>
> # Recurse into module libraries
> add_subdirectory( Hydro )
>
> ========= /src/Hydro
> add_library(Hydro file1.F90 file2.F90 sflux_9c.F90)
>
>
> # Make sure the compiler can find include files from our Hydro library.
> include_directories ( $(NETCDF_INC) )
>
> # Make sure the linker can find the Hydro library once it is built.
> link_directories ( ${SELFE_BINARY_DIR}/Hydro )

This previous one is wrong, link_directories is seldom used for your
own library.
The forthcoming
target_link_libraries (mymain Hydro)
is enough for CMake to find how to link "mymain" to "Hydro" lib.

Try removing this "link_directories" line.

> add_executable ( mymain mymain.F90 )
>
> # Link the executable to the Hydro library.
> target_link_libraries (mymain Hydro $(NETCDF_INC) )

This statement looks wrong as well
NETCDF_INC must a path to an include directory not a path
to a library?
What you probably need is
target_link_libraries (mymain Hydro $(NETCDF_LIBRARY) )

with NETCDF_LIBRARY being the full path to the NETCDF library.

-- 
Erk
Le gouvernement représentatif n'est pas la démocratie --
http://www.le-message.org

--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list