Menu

#14 Fix cmake sub directory builds

Unknown
closed-rejected
None
5
2014-07-24
2009-09-21
Erik Fears
No

If cgreen is added as a sub project of any other project, then the cgreen build fails because it's not settings its project directories in relation to a parent project. CGreen should be using PROJECT_SOURCE_DIR instead of CMAKE_SOURCE_DIR for any relative paths

Index: src/CMakeLists.txt

--- src/CMakeLists.txt (revision 317)
+++ src/CMakeLists.txt (working copy)
@@ -1,11 +1,9 @@
-project(cgreen-library C)
-
find_package(FLEX)

set(CGREEN_PUBLIC_INCLUDE_DIRS
- ${CMAKE_SOURCE_DIR}/include
+ ${PROJECT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}
- ${CMAKE_SOURCE_DIR}
+ ${PROJECT_SOURCE_DIR}
CACHE INTERNAL "cgreen public include directories"
)

Index: CMakeLists.txt

--- CMakeLists.txt (revision 317)
+++ CMakeLists.txt (working copy)
@@ -11,7 +11,7 @@

# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
set(CMAKE_MODULE_PATH
- ${CMAKE_SOURCE_DIR}/cmake/Modules
+ ${PROJECT_SOURCE_DIR}/cmake/Modules
)

# add definitions

Discussion

  • João Henrique F. de Freitas

    • assigned_to: nobody --> joaohf
     
  • João Henrique F. de Freitas

    Hello Erik,

    See the patch below and tell me what you think.

    Your patch don't work because

    # grep PUBLIC_ CMakeCache.txt
    CGREEN_PUBLIC_INCLUDE_DIRS:INTERNAL=/home/joaohf/opensource/cgreen/correcao_cmake/src/include;/home/joaohf/opensource/cgreen/correcao_cmake/src;/home/joaohf/opensource/cgreen/correcao_cmake/src

    PUBLIC_INCLUDE_DIRS has set with cgreen/src/include. I think the correct is cgreen/include.

    === CMakeLists.txt

    --- CMakeLists.txt (revision 328)
    +++ CMakeLists.txt (local)
    @@ -11,7 +11,7 @@

    # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
    set(CMAKE_MODULE_PATH
    - ${CMAKE_SOURCE_DIR}/cmake/Modules
    + ${PROJECT_SOURCE_DIR}/cmake/Modules
    )

    # add definitions
    @@ -34,6 +34,13 @@
    set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
    endif (WIN32)

    +set(CGREEN_PUBLIC_INCLUDE_DIRS
    + ${PROJECT_SOURCE_DIR}/include
    + ${CMAKE_CURRENT_SOURCE_DIR}
    + ${PROJECT_SOURCE_DIR}
    + CACHE INTERNAL "cgreen public include directories"
    +)
    +
    # check subdirectories
    add_subdirectory(doc)
    add_subdirectory(include)
    === src/CMakeLists.txt
    ==================================================================
    --- src/CMakeLists.txt (revision 328)
    +++ src/CMakeLists.txt (local)
    @@ -2,13 +2,6 @@

    find_package(FLEX)

    -set(CGREEN_PUBLIC_INCLUDE_DIRS
    - ${CMAKE_SOURCE_DIR}/include
    - ${CMAKE_CURRENT_SOURCE_DIR}
    - ${CMAKE_SOURCE_DIR}
    - CACHE INTERNAL "cgreen public include directories"
    -)
    -
    set(CGREEN_PRIVATE_INCLUDE_DIRS
    ${CMAKE_BINARY_DIR}
    )

     
  • Thomas Nilefalk

    Thomas Nilefalk - 2014-07-24

    Does not seem to be a problem anymore

     
  • Thomas Nilefalk

    Thomas Nilefalk - 2014-07-24
    • status: open --> closed-rejected
    • Group: --> Unknown
     

Log in to post a comment.

MongoDB Logo MongoDB