From 935c1d139e3f38f9d1ba597108a68c628c453bcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C8=98tefan=20Talpalaru?= Date: Mon, 25 May 2020 02:22:41 +0200 Subject: [PATCH] more CMake options - generic .gitignore entries for CMake projects - generate a pkg-config file --- .gitignore | 26 ++++++++++++++++++++++++ CMakeLists.txt | 18 ++++++++++++++--- DOtherSide.pc.cmake | 14 +++++++++++++ lib/CMakeLists.txt | 48 ++++++++++++++++++++++++++++++--------------- 4 files changed, 87 insertions(+), 19 deletions(-) create mode 100644 DOtherSide.pc.cmake diff --git a/.gitignore b/.gitignore index e65a753..cb9d9ee 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,29 @@ nimcache .idea *.orig doc + +# libraries +*.a +*.so +*.so.* + +# CMake +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps +*_autogen +CMakeDoxyfile.in +CMakeDoxygenDefaults.cmake +DOtherSide.pc + +# binaries +test/TestDynamicQObject + diff --git a/CMakeLists.txt b/CMakeLists.txt index e2410d0..174d006 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 3.2) project(DOtherSide) +option(ENABLE_DOCS "Enable docs" ON) +option(ENABLE_TESTS "Enable tests" ON) +option(ENABLE_DYNAMIC_LIBS "Enable dynamic libraries" ON) +option(ENABLE_STATIC_LIBS "Enable static libraries" ON) + # Add additional source path for cmake list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/) @@ -16,10 +21,17 @@ if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) message(STATUS "Enabling coverage") set(CMAKE_BUILD_TYPE Debug) add_compile_options(-g -O0 --coverage) - add_link_options(--coverage) + add_link_options(--coverage) endif() endif() -add_subdirectory(doc) add_subdirectory(lib) -add_subdirectory(test) + +if(ENABLE_DOCS) + add_subdirectory(doc) +endif() + +if(ENABLE_TESTS) + add_subdirectory(test) +endif() + diff --git a/DOtherSide.pc.cmake b/DOtherSide.pc.cmake new file mode 100644 index 0000000..eb54172 --- /dev/null +++ b/DOtherSide.pc.cmake @@ -0,0 +1,14 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=@CMAKE_INSTALL_PREFIX@ +libdir=@CMAKE_INSTALL_FULL_LIBDIR@ +sharedlibdir=@CMAKE_INSTALL_FULL_LIBDIR@ +includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ + +Name: @PROJECT_NAME@ +Description: C language library for creating bindings for the Qt QML language +Version: @DOTHERSIDE_VERSION@ + +Requires: @PC_REQUIRES@ +Libs: -L${libdir} -lDOtherSide +Cflags: -I${includedir} + diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index f389fee..e89cb9f 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,5 +1,7 @@ project(DOtherSide) +include(GNUInstallDirs) + # Macro for merging common code between static and shared macro(add_target name type) find_package(Qt5 COMPONENTS Core Qml Gui Quick QuickControls2 Widgets) @@ -38,34 +40,48 @@ macro(add_target name type) target_link_libraries(${name} PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Qml Qt5::Quick) + # for DOtherSide.pc + set(PC_REQUIRES "Qt5Core, Qt5Gui, Qt5Widgets, Qt5Qml, Qt5Quick") if (${Qt5QuickControls2_FOUND}) target_link_libraries(${name} PRIVATE Qt5::QuickControls2) + set(PC_REQUIRES "${PC_REQUIRES}, Qt5QuickControls2") endif() endmacro() -# Add shared version -add_target(${PROJECT_NAME} SHARED) set(major 0) set(minor 6) set(patch 4) -set_target_properties(${PROJECT_NAME} -PROPERTIES - SOVERSION "${major}.${minor}" - VERSION "${major}.${minor}.${patch}" -) +set(DOTHERSIDE_VERSION "${major}.${minor}.${patch}") + +# Add shared version +if(ENABLE_DYNAMIC_LIBS) + add_target(${PROJECT_NAME} SHARED) + set_target_properties(${PROJECT_NAME} + PROPERTIES + SOVERSION "${major}.${minor}" + VERSION "${major}.${minor}.${patch}" + ) + install(TARGETS ${PROJECT_NAME} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif(ENABLE_DYNAMIC_LIBS) # Add static version -add_target(${PROJECT_NAME}Static STATIC) +if(ENABLE_STATIC_LIBS) + add_target(${PROJECT_NAME}Static STATIC) + install(TARGETS ${PROJECT_NAME}Static + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif(ENABLE_STATIC_LIBS) # Install directive for header files install(FILES - include/DOtherSide/DOtherSide.h - include/DOtherSide/DOtherSideTypes.h - DESTINATION include/DOtherSide + include/DOtherSide/DOtherSide.h + include/DOtherSide/DOtherSideTypes.h + DESTINATION include/DOtherSide ) -# Install directive for binaries -install(TARGETS ${PROJECT_NAME} - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib -) +# pkg-config file +configure_file(${CMAKE_SOURCE_DIR}/DOtherSide.pc.cmake ${CMAKE_BINARY_DIR}/DOtherSide.pc @ONLY) +install(FILES ${CMAKE_BINARY_DIR}/DOtherSide.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +