[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Proposed CMake change, to allow add_subdirectory(cmocka) from parent project.


Hi,

I wished to add cmocka as a submodule to my project and use it in my CMake
enabled project. However cmocka has a few ${CMAKE_SOURCE_DIR} variables,
referencing the top level project in CMake. This disallows for the
inclusion of the project by add_subdirectory(..)

I propose the following change which will not change the standalone build.


diff --git a/CMakeLists.txt b/CMakeLists.txt
index ac224ff..c8cab13 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,7 +24,7 @@ set(LIBRARY_SOVERSION "0")

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

 # add definitions
diff --git a/CPackConfig.cmake b/CPackConfig.cmake
index 8d427a3..e8b145e 100644
--- a/CPackConfig.cmake
+++ b/CPackConfig.cmake
@@ -7,7 +7,7 @@ set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Unit testing
framework for C with mock ob
 set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README")
 set(CPACK_PACKAGE_VENDOR "Andreas Schneider")
 set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
-set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
+set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")


 ### versions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b5a3c7d..4646c9c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -3,13 +3,13 @@ project(cmocka-library C)
 set(CMOCKA_PLATFORM_INCLUDE CACHE PATH "Path to include directory for
cmocka_platform.h")

 set(CMOCKA_PUBLIC_INCLUDE_DIRS
-    ${CMAKE_SOURCE_DIR}/include
+    ${CMAKE_CURRENT_SOURCE_DIR}/../include
     ${CMOCKA_PLATFORM_INCLUDE}
     CACHE INTERNAL "cmocka public include directories"
 )

 set(CMOCKA_PRIVATE_INCLUDE_DIRS
-    ${CMAKE_BINARY_DIR}
+    "${CMAKE_CURRENT_BINARY_DIR}/.."
 )

 set(CMOCKA_SHARED_LIBRARY



​Best regards,
.
*Kristian Theilgaard*