From efd4e4c59413fe0aac0782395af7dca5ccec6e08 Mon Sep 17 00:00:00 2001 From: aszlig Date: Mon, 11 Jun 2018 02:51:23 +0200 Subject: [PATCH 1/5] Use CMAKE_CURRENT_SOURCE_DIR for the module path We're going to add a top-level CMakeLists.txt, so whenever we use the top-level one the CMAKE_SOURCE_DIR variable is the top-level of the source tree. Subprojects such as libinsane and libinsane-gobject won't find their respective CMake includes because they're located one level deeper. Signed-off-by: aszlig --- libinsane-gobject/CMakeLists.txt | 2 +- libinsane/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libinsane-gobject/CMakeLists.txt b/libinsane-gobject/CMakeLists.txt index eedc5d2..f204f54 100644 --- a/libinsane-gobject/CMakeLists.txt +++ b/libinsane-gobject/CMakeLists.txt @@ -3,7 +3,7 @@ project(Libinsane-gobject) cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -pedantic -Wunused -g -ggdb -O2") set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -pedantic -Wunused -g -ggdb -O2") diff --git a/libinsane/CMakeLists.txt b/libinsane/CMakeLists.txt index daaed9e..cd42050 100644 --- a/libinsane/CMakeLists.txt +++ b/libinsane/CMakeLists.txt @@ -4,7 +4,7 @@ project(Libinsane) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) include(GNUInstallDirs) From d8d4a6dc5fb819a5386665df96bbb93228a44ecc Mon Sep 17 00:00:00 2001 From: aszlig Date: Mon, 11 Jun 2018 02:55:16 +0200 Subject: [PATCH 2/5] Only compile tests if CUnit has been found This also adds the corresponding LDFLAGS and CFLAGS to the test targets and will only compile the tests if pkg-config was able to locate CUnit. Signed-off-by: aszlig --- libinsane/CMakeLists.txt | 56 ++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/libinsane/CMakeLists.txt b/libinsane/CMakeLists.txt index cd42050..791562c 100644 --- a/libinsane/CMakeLists.txt +++ b/libinsane/CMakeLists.txt @@ -138,28 +138,34 @@ endif() # libinsane tests -enable_testing() - -find_program(MEMORYCHECK_COMMAND valgrind) -set(MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes" "--leak-check=full" "--error-exitcode=10") -set(ENV{CTEST_OUTPUT_ON_FAILURE} "1") -MESSAGE(STATUS "Valgrind: ${MEMORYCHECK_COMMAND} ${MEMORYCHECK_COMMAND_OPTIONS}") - -foreach(test ${LIBINSANE_TESTS}) - add_executable(tests_${test} ${LIBINSANE_SRCS} tests/main.c tests/tests_${test}.c) - target_include_directories(tests_${test} PUBLIC include ${LIBINSANE_INCLUDES}) - target_link_libraries(tests_${test} ${LIBINSANE_LIBS} -lcunit) - add_test( - NAME tests_${test} - COMMAND ${CMAKE_BINARY_DIR}/tests_${test} - ) -endforeach(test) -foreach(test ${LIBINSANE_VALGRIND_TESTS}) - add_executable(tests_${test} ${LIBINSANE_SRCS} tests/main.c tests/tests_${test}.c) - target_include_directories(tests_${test} PUBLIC include ${LIBINSANE_INCLUDES}) - target_link_libraries(tests_${test} ${LIBINSANE_LIBS} -lcunit) - add_test( - NAME tests_${test} - COMMAND ${MEMORYCHECK_COMMAND} ${MEMORYCHECK_COMMAND_OPTIONS} -- ${CMAKE_BINARY_DIR}/tests_${test} - ) -endforeach(test) +find_package(PkgConfig) +pkg_check_modules(CUNIT "cunit") +if(CUNIT_FOUND) + enable_testing() + + find_program(MEMORYCHECK_COMMAND valgrind) + set(MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes" "--leak-check=full" "--error-exitcode=10") + set(ENV{CTEST_OUTPUT_ON_FAILURE} "1") + MESSAGE(STATUS "Valgrind: ${MEMORYCHECK_COMMAND} ${MEMORYCHECK_COMMAND_OPTIONS}") + + foreach(test ${LIBINSANE_TESTS}) + add_executable(tests_${test} ${LIBINSANE_SRCS} tests/main.c tests/tests_${test}.c) + target_include_directories(tests_${test} PUBLIC include ${LIBINSANE_INCLUDES}) + target_compile_options(tests_${test} PUBLIC ${CUNIT_CFLAGS}) + target_link_libraries(tests_${test} ${LIBINSANE_LIBS} ${CUNIT_LDFLAGS}) + add_test( + NAME tests_${test} + COMMAND ${CMAKE_BINARY_DIR}/tests_${test} + ) + endforeach(test) + foreach(test ${LIBINSANE_VALGRIND_TESTS}) + add_executable(tests_${test} ${LIBINSANE_SRCS} tests/main.c tests/tests_${test}.c) + target_include_directories(tests_${test} PUBLIC include ${LIBINSANE_INCLUDES}) + target_compile_options(tests_${test} PUBLIC ${CUNIT_CFLAGS}) + target_link_libraries(tests_${test} ${LIBINSANE_LIBS} ${CUNIT_LDFLAGS}) + add_test( + NAME tests_${test} + COMMAND ${MEMORYCHECK_COMMAND} ${MEMORYCHECK_COMMAND_OPTIONS} -- ${CMAKE_BINARY_DIR}/tests_${test} + ) + endforeach(test) +endif(CUNIT_FOUND) From c879ae4e896ebb478aad84cb500a321448d11db4 Mon Sep 17 00:00:00 2001 From: aszlig Date: Mon, 11 Jun 2018 02:57:01 +0200 Subject: [PATCH 3/5] Add a small top-level CMakeLists.txt This is only in preparation to the transition to having one CMakeLists.txt to build the base library and it's GLIB equivalents. The GLIB bindings are only built if CMake was able to locate it. Signed-off-by: aszlig --- CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9c60edd --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.5) + +add_subdirectory(libinsane) + +include("${CMAKE_SOURCE_DIR}/libinsane-gobject/cmake/FindGLib.cmake") + +if(GLIB2_FOUND) +add_subdirectory(libinsane-gobject) +endif(GLIB2_FOUND) From 9a47998a17b3c9453ab81b54ebc561c6f9a65ebe Mon Sep 17 00:00:00 2001 From: aszlig Date: Mon, 11 Jun 2018 03:37:32 +0200 Subject: [PATCH 4/5] gobject: Fix CMake references to libinsane The CMakeLists.txt in libinsane-gobject relies heavily on a specific directory structure and also uses a few workarounds that reference relative paths that might not be there when using our new top-level CMakeLists.txt. However, I've added a few workarounds as well, because right now we want to still support the Makefile that resides in the top-level until the buildbot scripts were adjusted so that they build from the top-level CMakeLists.txt. So for now this links the gobject bindings statically against libinsane, which we don't want to necessarily have in the long term (only optional at least). Signed-off-by: aszlig --- libinsane-gobject/CMakeLists.txt | 42 ++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/libinsane-gobject/CMakeLists.txt b/libinsane-gobject/CMakeLists.txt index f204f54..1eabb25 100644 --- a/libinsane-gobject/CMakeLists.txt +++ b/libinsane-gobject/CMakeLists.txt @@ -83,7 +83,12 @@ add_custom_command( ## Build libinsane_gobject itself add_library(insane_gobject SHARED ${INSANE_GOBJECT_SRCS}) -target_link_libraries(insane_gobject insane ${GLIB2_LIBRARIES}) +if(${CMAKE_CURRENT_SOURCE_DIR} EQUAL ${CMAKE_SOURCE_DIR}) + target_link_libraries(insane_gobject insane ${GLIB2_LIBRARIES}) +else() + # XXX: Statically linked for now until CMake restructuring is done. + target_link_libraries(insane_gobject libinsane_static ${GLIB2_LIBRARIES}) +endif() target_include_directories(insane_gobject PUBLIC include generated) install(TARGETS insane_gobject @@ -113,12 +118,19 @@ set(Libinsane_0_1_gir "libinsane-gobject") set(Libinsane_0_1_gir_INCLUDES GObject-2.0) get_directory_property(_tmp_includes INCLUDE_DIRECTORIES) _list_prefix(_includes _tmp_includes "-I") -set(Libinsane_0_1_gir_CFLAGS - ${_includes} - -L${CMAKE_BINARY_DIR} - -L${CMAKE_CURRENT_SOURCE_DIR}/../libinsane/build - -linsane -) + +# XXX: Only do this workaround if we don't have a top-level CMakeLists.txt +if(${CMAKE_CURRENT_SOURCE_DIR} EQUAL ${CMAKE_SOURCE_DIR}) + set(Libinsane_0_1_gir_CFLAGS + ${_includes} + -L${CMAKE_BINARY_DIR} + -L${CMAKE_CURRENT_SOURCE_DIR}/../libinsane/build + -linsane + ) +else() + set(Libinsane_0_1_gir_CFLAGS ${_includes}) +endif() + set(Libinsane_0_1_gir_LIBS insane_gobject) _list_prefix(_abs_introspection_files introspection_files "${CMAKE_CURRENT_SOURCE_DIR}/") set(Libinsane_0_1_gir_FILES ${_abs_introspection_files}) @@ -141,12 +153,16 @@ file( COPY ${CMAKE_CURRENT_SOURCE_DIR}/doc/gtkdocentities.ent DESTINATION ${CMAKE_BINARY_DIR}/libinsane_gobject/xml ) -# WORKAROUND(JFlesch): -# gtk-doc seems to accept only one LDPATH ? -file( - COPY ${CMAKE_CURRENT_SOURCE_DIR}/../libinsane/build/libinsane.so - DESTINATION ${CMAKE_BINARY_DIR} -) + +# XXX: Only do this workaround if we don't have a top-level CMakeLists.txt +if(${CMAKE_CURRENT_SOURCE_DIR} EQUAL ${CMAKE_SOURCE_DIR}) + # WORKAROUND(JFlesch): + # gtk-doc seems to accept only one LDPATH ? + file( + COPY ${CMAKE_CURRENT_SOURCE_DIR}/../libinsane/build/libinsane.so + DESTINATION ${CMAKE_BINARY_DIR} + ) +endif() gtk_doc_add_module( libinsane_gobject From 52826c7dc0368f8602e907d9eb6b351d4e6d557a Mon Sep 17 00:00:00 2001 From: aszlig Date: Mon, 11 Jun 2018 09:21:46 +0200 Subject: [PATCH 5/5] cmake: Check top-level inclusion via dedicated var Checking whether CMAKE_CURRENT_SOURCE_DIR equals CMAKE_SOURCE_DIR seems to be not very reliable, so let's actually set a variable in the top-level CMakeLists.txt which we can check in the individial projects. Signed-off-by: aszlig --- CMakeLists.txt | 2 ++ libinsane-gobject/CMakeLists.txt | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c60edd..8adb0a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 3.5) +set(HAS_TOPLEVEL_CMAKELISTS TRUE) + add_subdirectory(libinsane) include("${CMAKE_SOURCE_DIR}/libinsane-gobject/cmake/FindGLib.cmake") diff --git a/libinsane-gobject/CMakeLists.txt b/libinsane-gobject/CMakeLists.txt index 1eabb25..3ed85c8 100644 --- a/libinsane-gobject/CMakeLists.txt +++ b/libinsane-gobject/CMakeLists.txt @@ -83,7 +83,7 @@ add_custom_command( ## Build libinsane_gobject itself add_library(insane_gobject SHARED ${INSANE_GOBJECT_SRCS}) -if(${CMAKE_CURRENT_SOURCE_DIR} EQUAL ${CMAKE_SOURCE_DIR}) +if(NOT HAS_TOPLEVEL_CMAKELISTS) target_link_libraries(insane_gobject insane ${GLIB2_LIBRARIES}) else() # XXX: Statically linked for now until CMake restructuring is done. @@ -120,7 +120,7 @@ get_directory_property(_tmp_includes INCLUDE_DIRECTORIES) _list_prefix(_includes _tmp_includes "-I") # XXX: Only do this workaround if we don't have a top-level CMakeLists.txt -if(${CMAKE_CURRENT_SOURCE_DIR} EQUAL ${CMAKE_SOURCE_DIR}) +if(NOT HAS_TOPLEVEL_CMAKELISTS) set(Libinsane_0_1_gir_CFLAGS ${_includes} -L${CMAKE_BINARY_DIR} @@ -155,7 +155,7 @@ file( ) # XXX: Only do this workaround if we don't have a top-level CMakeLists.txt -if(${CMAKE_CURRENT_SOURCE_DIR} EQUAL ${CMAKE_SOURCE_DIR}) +if(NOT HAS_TOPLEVEL_CMAKELISTS) # WORKAROUND(JFlesch): # gtk-doc seems to accept only one LDPATH ? file(