Skip to content

Commit

Permalink
Merge branch 'master' of github.com:DerThorsten/cpp_cookiecutter
Browse files Browse the repository at this point in the history
  • Loading branch information
DerThorsten committed Jul 18, 2019
2 parents ba14c90 + 1be2c08 commit a2e7f29
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 32 deletions.
10 changes: 1 addition & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Features
Current features include:
* Readme on `readthedocs.org <https://cpp-cookiecutter.readthedocs.io/en/latest/>`_
* Modern C++ 14
* Build system with modernized yet not modern CMake (this is a major todo)
* Build system with modern CMake
* `preconfigured conda recipe included <https://cpp-cookiecutter.readthedocs.io/en/latest/conda_recipe.html>`_
* Rendered projects have pre-configured CI scripts for: travis-ci circleci and azure-pipelines
* Rendering of projects itself is tested on several continuous integration plattforms as `travis-ci <https://travis-ci.org/DerThorsten/cpp_cookiecutter>`_ `circleci <https://circleci.com/gh/DerThorsten/cpp_cookiecutter/tree/master>`_ and `azure-pipelines <https://dev.azure.com/derthorstenbeier/cpp_cookiecutter/_build/latest?definitionId=1&branchName=master>`_
Expand All @@ -51,14 +51,6 @@ Current features include:



Todos:
--------

Things which need to be done
* Add better documentation how to use the cookiecutter




Usage:
--------
Expand Down
36 changes: 34 additions & 2 deletions tests/test_project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ echo "activate cpptools-dev-requirements conda env"
echo "------------------------------------------------------------"
$SOURCE activate cpptools-dev-requirements || exit 1


echo "------------------------------------------------------------"
echo "setup intall prefix"
echo "------------------------------------------------------------"
INSTALL_PREFIX=$(conda info --base)/envs/cpptools-dev-requirements



echo "------------------------------------------------------------"
echo "create build dir"
echo "------------------------------------------------------------"
Expand All @@ -56,9 +64,9 @@ echo "------------------------------------------------------------"
cd build || exit 1

echo "------------------------------------------------------------"
echo "run cmake"
echo "run cmake with INSTALL_PREFIX=$INSTALL_PREFIX"
echo "------------------------------------------------------------"
cmake .. || exit 1
cmake .. -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX|| exit 1

echo "------------------------------------------------------------"
echo "build project"
Expand Down Expand Up @@ -97,6 +105,30 @@ echo "------------------------------------------------------------"
make docs


echo "------------------------------------------------------------"
echo "make install"
echo "------------------------------------------------------------"
make install


echo "------------------------------------------------------------"
echo "go to toy project"
echo "------------------------------------------------------------"
cd ../../$TEMPLATE_FOLDER/tests/toy_project


echo "------------------------------------------------------------"
echo "run cmake for toy project depending on rendered project"
echo "------------------------------------------------------------"
cmake . || 0


echo "------------------------------------------------------------"
echo "build toy project depending on rendered project"
echo "------------------------------------------------------------"
make || 0


echo "------------------------------------------------------------"
echo "Completed test script successfully"
echo "------------------------------------------------------------"
1 change: 1 addition & 0 deletions tests/toy_project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bld
4 changes: 2 additions & 2 deletions tests/toy_project/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.1)
project (toy_project)

find_package(cpptools)
find_package(cpptools CONFIG REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main INTERFACE cpptools)
target_link_libraries(main PUBLIC cpptools)
7 changes: 7 additions & 0 deletions tests/toy_project/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <cpptools/cpptools.hpp>
#include <xtl/xany.hpp>
#include <xtensor/xarray.hpp>

int main(){

}
41 changes: 29 additions & 12 deletions {{cookiecutter.github_project_name}}/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,23 @@ find_package(xtensor REQUIRED)
SET(INTERFACE_LIB_NAME {{cookiecutter.cmake_interface_library_name}})



file(GLOB_RECURSE ${PROJECT_NAME}_HEADERS ${PROJECT_INCLUDE_DIR}/*.hpp)


add_library(${INTERFACE_LIB_NAME} INTERFACE)

message(STATUS "INSTALL_INTERFACE: ${CMAKE_INSTALL_INCLUDEDIR}")
target_include_directories(${INTERFACE_LIB_NAME} INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)



target_link_libraries(${INTERFACE_LIB_NAME}
INTERFACE xtensor)

target_include_directories(${INTERFACE_LIB_NAME}
INTERFACE $<BUILD_INTERFACE:${PROJECT_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)


# Benchmark
# ============
Expand Down Expand Up @@ -135,20 +142,29 @@ endif()
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets)

# Makes the project importable from the build directory
export(EXPORT ${PROJECT_NAME}-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
set(${PROJECT_NAME}_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE
STRING "install path for ${PROJECT_NAME}Config.cmake")


message(STATUS "DEST ${${PROJECT_NAME}_CMAKECONFIG_INSTALL_DIR}" )


install(TARGETS ${INTERFACE_LIB_NAME}
EXPORT ${INTERFACE_LIB_NAME}-targets)

install(EXPORT ${INTERFACE_LIB_NAME}-targets
FILE ${INTERFACE_LIB_NAME}Targets.cmake
#NAMESPACE ${PROJECT_NAME}::
DESTINATION lib/cmake/${PROJECT_NAME}
)


# install(FILES ${${PROJECT_NAME}_HEADERS}
# DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CPP_ROOT_FOLDER_NAME})
install(DIRECTORY ${PROJECT_INCLUDE_DIR}/${CPP_ROOT_FOLDER_NAME}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

set(${PROJECT_NAME}_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE
STRING "install path for ${PROJECT_NAME}Config.cmake")



configure_package_config_file(${PROJECT_NAME}Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
Expand All @@ -167,6 +183,7 @@ set(CMAKE_SIZEOF_VOID_P ${_${PROJECT_NAME}_CMAKE_SIZEOF_VOID_P})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${${PROJECT_NAME}_CMAKECONFIG_INSTALL_DIR})

install(EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION ${${PROJECT_NAME}_CMAKECONFIG_INSTALL_DIR})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# {{cookiecutter.cmake_project_name}} cmake module
# This module sets the following variables in your project::
#
# {{cookiecutter.cmake_project_name}}_FOUND - true if {{cookiecutter.cmake_project_name}} found on the system
# {{cookiecutter.cmake_project_name}}_INCLUDE_DIRS - the directory containing {{cookiecutter.cmake_project_name}} headers
# {{cookiecutter.cmake_project_name}}_LIBRARY - empty
set(${PN}_INCLUDE_DIR "${INC_DIRS}")


get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(TOP_DIR "${SELF_DIR}/../../../" ABSOLUTE)
SET(INC_DIRS "${TOP_DIR}/include/")





@PACKAGE_INIT@
if(NOT TARGET @PROJECT_NAME@)
find_package(xtensor REQUIRED)
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
get_target_property(@PROJECT_NAME@_INCLUDE_DIRS {{cookiecutter.cmake_interface_library_name}} INTERFACE_INCLUDE_DIRECTORIES)
set_target_properties( {{cookiecutter.cmake_interface_library_name}} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${INC_DIRS}
)
SET(@PROJECT_NAME@_INCLUDE_DIRS ${INC_DIRS})
endif()

0 comments on commit a2e7f29

Please sign in to comment.