[CMake] Does set_target_properties compile_flags option override include_directories?

Eric Noulard eric.noulard at gmail.com
Wed Mar 30 06:35:39 EDT 2011


2011/3/30 Laura Auton Garcia <darklulu+cmake at gmail.com>:
> Hello all,
> The project I am working on uses pkg-config --cflags option to get the
> include directories of an external project, and I am trying to add the
> output to the compile_flags option used in set_target_properties. As
> well as the pkg-config directory, some other flags are specified and
> well recognized by the IDE we are building the project for (Visual
> Studio).
> The code stands as specified here (run_pkgconfig is a macro):
> RUN_PKGCONFIG("--cflags" "ACE" result LINKER_FLAGS)
> SET(LINKER_FLAGS "${LINKER_FLAGS} -D_CRT_SECURE_NO_WARNINGS
> -DACE_AS_STATIC_LIBS")
> SET_TARGET_PROPERTIES(
>    myproject PROPERTIES
>     COMPILE_FLAGS ${LINKER_FLAGS} )

Did you know that there is a FindPkgConfig.cmake module shipped with CMake?
It may helps you to use PkgConfig.

> pkg-config output: -Ic:/ace/ace_wrappers/include
>
> The LINKER_FLAGS variable is well set to with this content:
> -Ic:/ace/ace_wrappers/include -D_CRT_SECURE_NO_WARNINGS
> -DACE_AS_STATIC_LIBS
>
> Prior to this, some include directories from our own project are added
> using include_directories statement.
> INCLUDE_DIRECTORIES(
>   ${MYPROJECT_DIR_PATH}
>    ${MYPROJECT_DIR_PATH}/component
>    ${MYPROJECT_DIR_PATH}/error
>    ${MYPROJECT_DIR_PATH}/libraries)
>
> The project is then built successfully

You mean CMake successfully generate the project files right?
You did not manage to build your project outside Visual Studio?

> until we open the visual studio
> solution generated. After exploring the C/C++ command line properties
> of the project, it seems that all the include directories but the one
> generated by pkg-config are missing:
>
> /I"c:/ace/ace_wrappers/include" /D "_CRT_SECURE_NO_WARNINGS" /D
> "ACE_AS_STATIC_LIBS"
>
> If I don't add the pkg-config output, then all the directories
> included with include-directories appear to be ok:
>
> /I"C:/git-projects/myproject" /I"C:/git-projects/myproject/component"
> /I"C:/git-projects/myproject/error"
> /I"C:/git-projects/myproject/libraries" /D "_CRT_SECURE_NO_WARNINGS"
> /D "ACE_AS_STATIC_LIBS"
>
> So the question is, does compile-flags option override all the
> directories included with include_directories? If that's the case,
> then how do I add external include directories through pkg-config? I
> am pretty new at cmake so any help will be appreciated.

Not it shouldn't.
Which version of CMake are you using?

Is the "myproject" use in this:

> SET_TARGET_PROPERTIES(
>    myproject PROPERTIES
>     COMPILE_FLAGS ${LINKER_FLAGS} )

a target from add_executable() or add_library() or is it
the name of the project used in project() statement?

May be you can give us more information about your CMakeLists.txt.

-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org


More information about the CMake mailing list