Skip to content

Commit

Permalink
Merge pull request #12 from Guillaumebeuzeboc/dev/package
Browse files Browse the repository at this point in the history
Dev/package
  • Loading branch information
Guillaumebeuzeboc committed Mar 14, 2019
2 parents bef817c + 08a4bd0 commit 7abbc40
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 42 deletions.
25 changes: 0 additions & 25 deletions CMakeLists.txt

This file was deleted.

1 change: 1 addition & 0 deletions CMakeLists.txt
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
# Cmake_multi_repo_template
# Haricot
Test of a mutli repo Cmake based template
Packages can contains C++ and Python code
Tested only on Linux with cmake 3.13.2 and 3.5.1

## Usage

- `./configure`
- `./haricot`
- `cd build/src/mypkg; cpack`
- `cd build; ninja install`
## Features

Top level CMakeLists.txt architecture
The CmakeLists.txt in packages (Subdirectories) are standards (except that they can use extra features)
The CMakeLists.txt in packages (Subdirectories) are standards (except that they can use extra features)

- Build all the packages (subdiretories)
- Export pkg.cmake in order to includes them in another project/package
- Assign a version number
- Install targets/headers in the install directory at the root of the project
- Generate .deb for each packages

## Create a new workspace

You can create a ws that would use haricot. To do that you would just have to create a symbolic link to the TopLevelCMake.txt the setup_local.zsh and to the haricot cmd (use the repo as an example).
You can even combien workspace.

## Add a package (subdirectory)

Expand Down
1 change: 1 addition & 0 deletions haricot
3 changes: 0 additions & 3 deletions setup.zsh

This file was deleted.

1 change: 1 addition & 0 deletions setup.zsh
3 changes: 0 additions & 3 deletions setup_package.zsh

This file was deleted.

2 changes: 1 addition & 1 deletion src/a_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ INIT_PKG()
SETUP_PYTHON_PKG()

include_directories(include ${Boost_INCLUDE_DIR} )
add_library(a_lib
add_library(a_lib SHARED
src/lib.cpp)

target_include_directories(a_lib PUBLIC
Expand Down
1 change: 1 addition & 0 deletions src/a_lib/src/lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ void liba_function()
std::string s("2001-10-9"); //2001-October-09
date d(from_simple_string(s));
std::cout << to_simple_string(d) << std::endl;
std::cout << "this is a_lib" << std::endl;
}
catch(std::exception& e) {
std::cout << " Exception: " << e.what() << std::endl;
Expand Down
10 changes: 10 additions & 0 deletions src/haricot/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
project(haricot)

INIT_PKG()

SETUP_PKG(haricot)

install(DIRECTORY cmake/ DESTINATION share/haricot/cmake COMPONENT HARICOT)
install(FILES haricot setup_install.zsh setup_local.zsh DESTINATION share/haricot COMPONENT HARICOT)
install(FILES setup.zsh DESTINATION . COMPONENT HARICOT)
BUILDDEB()
File renamed without changes.
25 changes: 25 additions & 0 deletions src/haricot/cmake/TopLevelCMake.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.5)
project(workspace)

set(cmd "dirname -z $(realpath CMakeLists.txt)")
execute_process(COMMAND bash -c ${cmd}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE result
OUTPUT_VARIABLE ORIGIN)

include(${ORIGIN}/customMacro.cmake)
include(${ORIGIN}/python.cmake)
set(ROOT_DIR "${CMAKE_SOURCE_DIR}")
set(CMAKE_INSTALL_PREFIX "${ROOT_DIR}/install")
file(MAKE_DIRECTORY ${CMAKE_INSTALL_PREFIX})

PREPARE_PYTHON()

SUBDIRLIST(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR}/src)
SORT_SUBDIRS()
FOREACH(subdir ${SUBDIRS})
message("== Configuration of ${subdir} started")
ADD_SUBDIRECTORY(src/${subdir})
message("== Configuration of ${subdir} finished!")
ENDFOREACH()

File renamed without changes.
11 changes: 6 additions & 5 deletions cmake/customMacro.cmake → src/haricot/cmake/customMacro.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ macro(BUILDDEB)
if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
include(InstallRequiredSystemLibraries)
set(CPACK_SET_DESTDIR true)
set(CPACK_INSTALL_PREFIX "/opt/guillaume")
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_INSTALL_PREFIX "/opt/haricot-pkgs")
set(CPACK_GENERATOR "DEB")
set(CPACK_PACKAGE_DESCRIPTION "${DESCRIPTION}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${SUMMARY}")
Expand All @@ -71,7 +72,7 @@ macro(BUILDDEB)
set(CPACK_OUTPUT_CONFIG_FILE "${PROJECT_BINARY_DIR}/CPackConfig.cmake" )

set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_PACKAGE_SECTION "beuz")
set(CPACK_DEBIAN_PACKAGE_SECTION "haricot-pkgs")
set(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
include(CPack)
Expand Down Expand Up @@ -109,14 +110,14 @@ macro(SETUP_PKG PKG_NAME)
set(${PKG_NAME}_VERSION "${PKG_VERSION}" PARENT_SCOPE)

set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}")
configure_file(${ORIGIN}/cmake/pkg-config.cmake
configure_file(${ORIGIN}/pkg-config.cmake
"${PROJECT_BINARY_DIR}/${PKG_NAME}Config.cmake" @ONLY)

set(CONF_INCLUDE_DIRS "${MAKE_INSTALL_PREFIX}/${PROJECT_NAME}")
configure_file(${ORIGIN}/cmake/pkg-config.cmake
configure_file(${ORIGIN}/pkg-config.cmake
"${PROJECT_BINARY_DIR}/${PKG_NAME}Config.cmake" @ONLY)

configure_file(${ORIGIN}/cmake/ConfigVersion.cmake
configure_file(${ORIGIN}/ConfigVersion.cmake
"${PROJECT_BINARY_DIR}/${PKG_NAME}ConfigVersion.cmake" @ONLY)

install(FILES
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion cmake/python.cmake → src/haricot/cmake/python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ macro(SETUP_PYTHON_PKG)
file(MAKE_DIRECTORY ${CMAKE_PYTHON_BUILD}/${PROJECT_NAME})
set(INIT_PKG_BUILD ${CMAKE_PYTHON_BUILD}/${PROJECT_NAME}/__init__.py)
set(PYTHON_SOURCE_PATH "${PROJECT_SOURCE_DIR}/src")
configure_file(${ORIGIN}/cmake/__init__.py.in ${INIT_PKG_BUILD})
configure_file(${ORIGIN}/__init__.py.in ${INIT_PKG_BUILD})

set(PATH_TO_${PROJECT_NAME}_PY_FILES "${PROJECT_SOURCE_DIR}/src/${PROJECT_NAME}")
install(DIRECTORY ${PATH_TO_${PROJECT_NAME}_PY_FILES} DESTINATION lib/python3/dist-packages COMPONENT ${${PROJECT_NAME}_UPPER})
Expand Down
7 changes: 7 additions & 0 deletions src/haricot/debian.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(MAJOR_VERSION "0")
set(MINOR_VERSION "0")
set(PATCH_VERSION "1")
set(DESCRIPTION "haricot")
set(SUMMARY "haricot deb pkg")
set(VENDOR "beuzeboc")
set(MAINTAINER "[email protected]")
File renamed without changes.
3 changes: 3 additions & 0 deletions src/haricot/setup.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CMAKE_PREFIX_PATH=/opt/haricot-pkgs:${CMAKE_PREFIX_PATH}
PYTHONPATH=/opt/haricot-pkgs/lib/python3/dist-packages:${PYTHONPATH}

2 changes: 1 addition & 1 deletion setup_install.zsh → src/haricot/setup_install.zsh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
MY_SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
CMAKE_PREFIX_PATH=${MY_SCRIPTPATH}/install:${CMAKE_PREFIX_PATH}
PYTHONPATH=/home/beuzeboc/code/tmp/cmake_multi_repo_template/install/lib/python3/dist-packages:${PYTHONPATH}
PYTHONPATH=${MY_SCRIPTPATH}/install/lib/python3/dist-packages:${PYTHONPATH}
3 changes: 3 additions & 0 deletions src/haricot/setup_local.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MY_SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
CMAKE_PREFIX_PATH=${MY_SCRIPTPATH}/build/src:${CMAKE_PREFIX_PATH}
PYTHONPATH=${MY_SCRIPTPATH}/build/python/lib/python3.5/site-packages:${PYTHONPATH}
1 change: 1 addition & 0 deletions src/z_lib/src/lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void libz_function()
std::string s("2001-10-9"); //2001-October-09
date d(from_simple_string(s));
std::cout << to_simple_string(d) << std::endl;
std::cout << "this is z_lib" << std::endl;
}
catch(std::exception& e) {
std::cout << " Exception: " << e.what() << std::endl;
Expand Down

0 comments on commit 7abbc40

Please sign in to comment.