cmake: Redesign CMakeLists.txt: Remove generators

Remove CMakeLists.txt generator scripts from build phase. Replaced with
CMake's GLOB that can re-run every time the build is invoked. We can
also drop the Python dependency now.

Removed header installs which will be redesigned in future commits.
parent 414ce8df
......@@ -44,10 +44,6 @@ docs/userGuide/command_doc.tex
# doxygen output directory
/apidoc
# CMakeList.txt files are generated
**/CMakeLists.txt
CMakeLists.txt
# CLion files
.idea/
......
......@@ -103,7 +103,6 @@ build:doc:
- apk add --no-cache doxygen graphviz cmake ninja python3
script:
- mkdir -p build && cd build
- ../CMake/generate.py -wm
- cmake -DBUILD_TYPE=Snapshot -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DDOXYGEN_ONLY=1 -GNinja ..
- ninja doxygen
artifacts:
......@@ -119,7 +118,6 @@ build:doc:
image: gitlab.fit.cvut.cz:5000/algorithms-library-toolkit/ci-docker-images/alt-builder:latest
before_script:
- mkdir -p build && pushd build
- ../CMake/generate.py -wm
- cmake -DBUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. -GNinja
- popd
allow_failure: true # TODO: Remove
......
function(alt_module name)
if (NOT IS_DIRECTORY ${CMAKE_SOURCE_DIR}/${NAME})
message(FATAL "${name} is not a directory")
endif()
add_subdirectory(${name})
endfunction()
function(alt_executable name)
add_executable(${name} "")
alt__add_target(${name} "${ARGN}")
install(TARGETS ${name} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endfunction()
function(alt_library name)
add_library(${name} SHARED "")
alt__add_target(${name} "${ARGN}")
set_target_properties(${name} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)
install(TARGETS ${name} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endfunction()
function(alt_testing name)
cmake_parse_arguments(ARGUMENTS "" "" "DEPENDS;INCLUDES;TEST_INCLUDES;TEST_DEPENDS" ${ARGN})
alt__unittests(${name} "${ARGUMENTS_TEST_DEPENDS}" "${ARGUMENTS_TEST_INCLUDES}")
endfunction()
function(alt__add_target name)
cmake_parse_arguments(ARGUMENTS "" "" "DEPENDS;INCLUDES;TEST_INCLUDES;TEST_DEPENDS" ${ARGN})
# message("Registering target ${name} (dependencies: ${ARGUMENTS_DEPENDS}) (includes: ${ARGUMENTS_INCLUDES}) (test-includes: ${ARGUMENTS_TEST_INCLUDES})")
target_include_directories(${name}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src
PRIVATE ${ARGUMENTS_INCLUDES}
)
target_link_libraries(${name}
PUBLIC ${ARGUMENTS_DEPENDS}
)
file(GLOB_RECURSE PROJECT_SOURCES LIST_DIRECTORIES false CONFIGURE_DEPENDS src/*)
target_sources(${name} PRIVATE "${PROJECT_SOURCES}")
if (BUILD_TESTING)
alt__unittests(${name} "${ARGUMENTS_TEST_DEPENDS}" "${ARGUMENTS_TEST_INCLUDES}")
endif()
endfunction()
function(alt__unittests name depends includes)
# message(STATUS "Adding unittests ${name} (depends: ${depends}) (includes: ${includes})")
set(test_executable "test_${name}")
add_executable(${test_executable} "")
file(GLOB_RECURSE TEST_SOURCES LIST_DIRECTORIES false CONFIGURE_DEPENDS test-src/*)
target_sources(${test_executable} PRIVATE "${TEST_SOURCES}")
target_link_libraries(${test_executable}
PRIVATE catch2
PRIVATE ${depends}
)
if(TARGET ${name})
get_target_property(target_type ${name} TYPE)
if (NOT (target_type STREQUAL "EXECUTABLE"))
target_link_libraries(${test_executable}
PRIVATE ${name}
)
endif()
endif()
target_include_directories(${test_executable}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test-src
PRIVATE ${CMAKE_BINARY_DIR}/test-src
PRIVATE ${includes}
)
catch_discover_tests(
${test_executable}
TEST_PREFIX "[${test_executable}]"
)
endfunction()
[Versioning]
; Promote version with release
major = 0
minor = 0
patch = 0
[General]
ProjectConfFile: project.conf
PathToSources: ..
PathToTemplates: ./templates/
[Groups]
cli
gui
[CMake:Categories]
; projects and their templates
; project must belong in one of these categories
root: CMakeLists_root.txt
executable: CMakeLists_bin.txt
library: CMakeLists_lib.txt
testing: CMakeLists_itest.txt
[CMake:Sources]
; where to find sources, relative to {PROJECT_DIR}
ExcludeSources: .txx .cxx .hxx
InstallSources: .hpp .h .hxx EMPTY
SourcesDir: src
TestSourcesDir: test-src
; ----------------------------------------------------------
; system dependencies:
; if projects depends on one of these probably want to specify what should be passed inside target_* in cmake
[CMake:Deps:xml2]
include: PUBLIC ${LIBXML2_INCLUDE_DIR}
link: ${LIBXML2_LIBRARIES}
find: LibXml2 REQUIRED
[CMake:Deps:threads]
link: ${CMAKE_THREAD_LIBS_INIT}
find: Threads REQUIRED
[CMake:Deps:Qt5Widgets]
link: Qt5::Widgets
include: ${Qt5Widgets_INCLUDE_DIRS}
find: Qt5 5.7 REQUIRED COMPONENTS Core Widgets
[CMake:Deps:Qt5Xml]
link: Qt5::Xml
include:${Qt5Xml_INCLUDE_DIRS}
find: Qt5 5.7 REQUIRED COMPONENTS Core Xml
[CMake:Deps:graphviz]
link: ${GRAPHVIZ_LIBRARIES}
include: ${GRAPHVIZ_INCLUDE_DIRS}
find: Graphviz REQUIRED
[CMake:Deps:json]
link: ${jsoncpp_LIBRARIES}
include: ${jsoncpp_INCLUDE_DIR}
find: jsoncpp REQUIRED
[CMake:Deps:readline]
link: ${READLINE_LIBRARY}
include: ${READLINE_INCLUDE_DIR}
find: Readline REQUIRED
[CMake:Deps:tclap]
include: ${Tclap_INCLUDE_DIR}
find: Tclap REQUIRED
[CMake:Deps:stdc++fs]
link: stdc++fs
This diff is collapsed.
#ifndef __CONFIGURE_TESTS_HPP_
#define __CONFIGURE_TESTS_HPP_
#define CMAKE_CURRENT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@"
#define CMAKE_CURRENT_BINARY_DIR "@CMAKE_CURRENT_BINARY_DIR@"
#endif /* __CONFIGURE_TESTS_HPP_ */
#ifndef __TEST_FILES_HPP_
#define __TEST_FILES_HPP_
#define TEST_FILES_BASEDIR "${TEST_FILES_BASEDIR}"
#endif /* __TEST_FILES_HPP_ */
project({project_name}
VERSION {alib_version}
LANGUAGES CXX)
set(PROJECT_NAME {project_name})
{find_packages}
set(SOURCE_FILES
{source_files}
)
# Add executable target
add_executable(${{PROJECT_NAME}} ${{SOURCE_FILES}})
# Include directories
target_include_directories(${{PROJECT_NAME}}
PUBLIC ${{CMAKE_CURRENT_SOURCE_DIR}}/src # anything that depends on this should include src also, hence public
{include_paths}
${{CMAKE_BINARY_DIR}}/generated
)
# Target link libraries
target_link_libraries(${{PROJECT_NAME}} {target_libs})
# Install
install(TARGETS ${{PROJECT_NAME}} RUNTIME DESTINATION ${{CMAKE_INSTALL_BINDIR}})
project({project_name}
VERSION {alib_version}
LANGUAGES CXX)
set(PROJECT_NAME_TEST test-{project_name})
{cmake_options}
{find_packages_tests}
set(SOURCE_FILES_TEST
{source_files_test}
)
set( TEST_FILES_BASEDIR ${{CMAKE_SOURCE_DIR}}/examples2 )
configure_file (
${{CONFIGURE_HEADERS_SRC_DIR}}/testfiles.hpp.in
${{CONFIGURE_HEADERS_DST_DIR}}/testfiles_basedir.hpp
)
add_executable(${{PROJECT_NAME_TEST}} ${{SOURCE_FILES_TEST}})
target_link_libraries(${{PROJECT_NAME_TEST}} {target_test_libs} catch2)
# Include dependencies directories
target_include_directories(${{PROJECT_NAME_TEST}}
PUBLIC ${{CMAKE_CURRENT_SOURCE_DIR}}/test-src # anything that depends on this should include src also, hence public
{include_test_paths}
${{CMAKE_BINARY_DIR}}/generated
)
include(Catch)
catch_discover_tests(
${{PROJECT_NAME_TEST}}
TEST_SPEC "[integration]"
TEST_PREFIX "[integration] "
)
project({project_name}
VERSION {alib_version}
LANGUAGES CXX)
set(PROJECT_NAME {project_name})
{cmake_options}
{find_packages}
set(SOURCE_FILES
{source_files}
)
# Add library target
add_library(${{PROJECT_NAME}} SHARED ${{SOURCE_FILES}})
# Target link libraries
target_link_libraries(${{PROJECT_NAME}} LINK_PUBLIC {target_libs})
# Include dependencies directories
target_include_directories(${{PROJECT_NAME}}
PUBLIC ${{CMAKE_CURRENT_SOURCE_DIR}}/src # anything that depends on this should include src also, hence public
{include_paths}
${{CMAKE_BINARY_DIR}}/generated
)
set_target_properties(${{PROJECT_NAME}} PROPERTIES
VERSION ${{PROJECT_VERSION}}
SOVERSION ${{PROJECT_VERSION_MAJOR}}
)
# Install
install(TARGETS ${{PROJECT_NAME}} LIBRARY DESTINATION ${{CMAKE_INSTALL_LIBDIR}})
FOREACH(HEADER {include_files})
get_filename_component(DIR ${{HEADER}} DIRECTORY)
STRING(REGEX REPLACE "^src" "" DIR ${{DIR}})
INSTALL(FILES ${{HEADER}} DESTINATION ${{CMAKE_INSTALL_INCLUDEDIR}}/algorithms-library/${{DIR}})
ENDFOREACH(HEADER)
########################################################################################################################
# tests
set(CMAKE_AUTOMOC OFF)
set(CMAKE_AUTOUIC OFF)
set(PROJECT_NAME_TEST test-{project_name})
{find_packages_tests}
set(SOURCE_FILES_TEST
{source_files_test}
)
add_executable(${{PROJECT_NAME_TEST}} ${{SOURCE_FILES_TEST}})
target_link_libraries(${{PROJECT_NAME_TEST}} ${{PROJECT_NAME}} {target_test_libs} catch2)
# Include dependencies directories
target_include_directories(${{PROJECT_NAME_TEST}}
PUBLIC ${{CMAKE_CURRENT_SOURCE_DIR}}/test-src # anything that depends on this should include src also, hence public
{include_test_paths}
)
enable_testing()
add_test(NAME "[unit]${{PROJECT_NAME}}"
COMMAND $<TARGET_FILE:${{PROJECT_NAME_TEST}}>
)
cmake_minimum_required(VERSION 3.7)
cmake_minimum_required(VERSION 3.12)
project(alib2
VERSION {alib_version}
LANGUAGES NONE)
project(algorithms_library_toolkit
VERSION 0.0.0
LANGUAGES CXX)
set(CMAKE_MODULE_PATH ${{CMAKE_SOURCE_DIR}}/CMake/Modules)
set(CONFIGURE_HEADERS_SRC_DIR ${{CMAKE_SOURCE_DIR}}/CMake/headers)
set(CONFIGURE_HEADERS_DST_DIR ${{CMAKE_BINARY_DIR}}/generated)
include_directories(${{CONFIGURE_HEADERS_DST_DIR}})
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules)
set(CONFIGURE_HEADERS_SRC_DIR ${CMAKE_SOURCE_DIR}/CMake/headers)
set(CONFIGURE_HEADERS_DST_DIR ${CMAKE_BINARY_DIR})
include_directories(${CONFIGURE_HEADERS_DST_DIR})
set(CMAKE_COLOR_MAKEFILE ON)
# set(CMAKE_VERBOSE_MAKEFILE ON) # use VERBOSE=1 target
# Immediately fail if not UNIX
# TODO: Add suport for other platforms. Check MacOS
if (NOT UNIX)
message(FATAL_ERROR "Unavailable if not Unix")
endif ()
# If not specified whether Debug or Release, select debug. Fail if invalid.
# cmake -DBUILD_TYPE={{Release,Snapshot,Debug}}
# cmake -DBUILD_TYPE={Release,Snapshot,Debug}
if (NOT BUILD_TYPE)
set(BUILD_TYPE Debug)
endif()
string(TOLOWER ${{BUILD_TYPE}} BUILD_TYPE)
string(TOLOWER ${BUILD_TYPE} BUILD_TYPE)
if(BUILD_TYPE MATCHES "release")
set(CMAKE_BUILD_TYPE Release CACHE STRING "cmake internal build type" FORCE)
......@@ -32,42 +29,58 @@ elseif(BUILD_TYPE MATCHES "snapshot")
elseif(BUILD_TYPE MATCHES "debug")
set(CMAKE_BUILD_TYPE Debug CACHE STRING "cmake internal build type" FORCE)
else()
message(FATAL_ERROR "Unsupported build type (${{BUILD_TYPE}}). Valid values: Release | Snapshot | Debug ")
message(FATAL_ERROR "Unsupported build type (${BUILD_TYPE}). Valid values: Release | Snapshot | Debug ")
endif()
message("[Build type] ${BUILD_TYPE} (cmake internal: ${CMAKE_BUILD_TYPE})")
message("[Build type] ${{BUILD_TYPE}} (cmake internal: ${{CMAKE_BUILD_TYPE}})")
include(alt)
include(versioning)
include(CompilerFlags)
include(Install)
if(DEFINED ENV{{CMAKE_BUILD_PARALLEL_LEVEL}})
message("[Parallel run] Build: $ENV{{CMAKE_BUILD_PARALLEL_LEVEL}} threads by default")
# testing
include(CTest)
if(BUILD_TESTING)
include(Catch)
add_subdirectory(contrib/catch2)
configure_file(
${CMAKE_SOURCE_DIR}/CMake/headers/configure_tests.hpp.in
${CMAKE_BINARY_DIR}/configure_tests.hpp
)
alt_module(alib2integrationtest)
endif()
if(DEFINED ENV{{CTEST_PARALLEL_LEVEL}})
message("[Parallel run] Test: $ENV{{CTEST_PARALLEL_LEVEL}} threads by default")
# docs
if(BUILD_DOCS)
include(Doxygen)
endif()
# set modules
set(ALIB_MODULES {alib_modules})
message("[ALT] Building ${PROJECT_NAME} ${PROJECT_VERSION}")
# versioning
include(versioning)
alt_module(alib2std)
alt_module(alib2measure)
alt_module(alib2abstraction)
alt_module(alib2common)
alt_module(alib2xml)
# doxygen
include(Doxygen)
if (DOXYGEN_ONLY)
return()
endif()
alt_module(alib2str)
alt_module(alib2data)
alt_module(alib2algo)
alt_module(alib2elgo)
alt_module(alib2algo_experimental)
alt_module(alib2data_experimental)
alt_module(alib2graph_data)
alt_module(alib2graph_algo)
enable_language(CXX)
alt_module(alib2raw)
# compile options based on compiler/build_type. Also add sanitizer support
include(CompilerFlags)
alt_module(alib2aux)
alt_module(alib2dummy)
# install paths
include(Install)
# testing
enable_testing()
add_subdirectory(contrib/catch2)
alt_module(alib2cli)
alt_module(alib2str_cli_integration)
alt_module(alib2raw_cli_integration)
alt_module(aql2)
foreach (module ${{ALIB_MODULES}})
add_subdirectory(${{module}})
endforeach ()
alt_module(alib2gui)
alt_module(agui2)
project(alt-agui VERSION ${CMAKE_PROJECT_VERSION})
alt_executable(agui2
DEPENDS alib2algo alib2aux alib2data alib2str alib2gui
)
[General]
category: executable
groups: gui
[Dependencies]
project: alib2algo alib2aux alib2data alib2str alib2gui
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
project(alt-libabstraction VERSION ${CMAKE_PROJECT_VERSION})
alt_library(alib2abstraction DEPENDS alib2std)
[General]
category: library
[Dependencies]
project: alib2std
project(alt-libalgo VERSION ${CMAKE_PROJECT_VERSION})
find_package(LibXml2 REQUIRED)
alt_library(alib2algo
DEPENDS alib2str alib2std alib2common alib2data alib2xml LibXml2::LibXml2
TEST_DEPENDS LibXml2::LibXml2
)
[General]
category: library
[Dependencies]
project: alib2data alib2xml alib2common alib2abstraction alib2measure alib2std
system: xml2
[TestDependencies]:
project: alib2str
project(alt-libalgo_experimental VERSION ${CMAKE_PROJECT_VERSION})
find_package(LibXml2 REQUIRED)
alt_library(alib2algo_experimental
DEPENDS alib2algo alib2data_experimental alib2data alib2xml alib2common alib2abstraction alib2measure alib2std alib2elgo
TEST_DEPENDS LibXml2::LibXml2
)
[General]
category: library
[Dependencies]
project: alib2algo alib2data_experimental alib2data alib2xml alib2common alib2abstraction alib2measure alib2std alib2elgo
system: xml2
[TestDependencies]
project: alib2str
project(alt-libaux VERSION ${CMAKE_PROJECT_VERSION})
find_package(LibXml2 REQUIRED)
alt_library(alib2aux
DEPENDS alib2str alib2graph_data alib2data alib2xml alib2common alib2abstraction alib2measure alib2std
TEST_DEPENDS LibXml2::LibXml2
)
[General]
category: library
[Dependencies]
project: alib2str alib2graph_data alib2data alib2xml alib2common alib2abstraction alib2measure alib2std
system: xml2
project(alt-libcli VERSION ${CMAKE_PROJECT_VERSION})
find_package(LibXml2 REQUIRED)
alt_library(alib2cli
DEPENDS alib2xml alib2common alib2abstraction alib2measure alib2std
TEST_DEPENDS LibXml2::LibXml2 stdc++fs
)
[General]
category: library
[Dependencies]
project: alib2xml alib2common alib2abstraction alib2measure alib2std
system: xml2 stdc++fs
project(alt-libcommon VERSION ${CMAKE_PROJECT_VERSION})
alt_library(alib2common DEPENDS alib2std alib2abstraction)
[General]
category: library
[Dependencies]
project: alib2abstraction alib2measure alib2std
project(alt-libdata VERSION ${CMAKE_PROJECT_VERSION})
find_package(LibXml2 REQUIRED)
# TODO: Make LibXml2 interface
alt_library(alib2data
DEPENDS alib2std alib2common alib2xml LibXml2::LibXml2
TEST_DEPENDS LibXml2::LibXml2
)
[General]
category: library
[Dependencies]
project: alib2xml alib2common alib2abstraction alib2measure alib2std
system: xml2
project(alt-libdata_experimental VERSION ${CMAKE_PROJECT_VERSION})
find_package(LibXml2 REQUIRED)
alt_library(alib2data_experimental
DEPENDS alib2data alib2xml alib2common alib2abstraction alib2measure alib2std
TEST_DEPENDS LibXml2::LibXml2
)
[General]
category: library
[Dependencies]
project: alib2data alib2xml alib2common alib2abstraction alib2measure alib2std
system: xml2
project(alt-libdummy VERSION ${CMAKE_PROJECT_VERSION})
find_package(LibXml2 REQUIRED)
alt_library(alib2dummy
DEPENDS alib2xml alib2common alib2abstraction alib2measure alib2std alib2data alib2algo
TEST_DEPENDS LibXml2::LibXml2
)
[General]
category: library
[Dependencies]
project: alib2xml alib2common alib2abstraction alib2measure alib2std alib2data alib2algo
system: xml2
project(alt-libelgo VERSION ${CMAKE_PROJECT_VERSION})
find_package(LibXml2 REQUIRED)
alt_library(alib2elgo
DEPENDS alib2algo alib2std alib2common alib2data alib2xml LibXml2::LibXml2
TEST_DEPENDS LibXml2::LibXml2
)
[General]
category: library
[Dependencies]
project: alib2algo alib2data alib2xml alib2common alib2abstraction alib2measure alib2std
system: xml2
[TestDependencies]
project: alib2str
project(alt-libgraph_algo VERSION ${CMAKE_PROJECT_VERSION})
find_package(LibXml2 REQUIRED)
alt_library(alib2graph_algo
DEPENDS alib2graph_data alib2xml alib2common alib2abstraction alib2measure alib2std
TEST_DEPENDS LibXml2::LibXml2
)
[General]
category: library
[Dependencies]
project: alib2graph_data alib2xml alib2common alib2abstraction alib2measure alib2std
system: xml2
project(alt-libgraph_data VERSION ${CMAKE_PROJECT_VERSION})
find_package(LibXml2 REQUIRED)
alt_library(alib2graph_data
DEPENDS alib2xml alib2common alib2abstraction alib2measure alib2std
TEST_DEPENDS LibXml2::LibXml2
)
[General]
category: library
[Dependencies]
project: alib2xml alib2common alib2abstraction alib2measure alib2std
system: xml2
project(alt-libgui VERSION ${CMAKE_PROJECT_VERSION})
find_package(LibXml2 REQUIRED)
find_package(Qt5 5.7 REQUIRED COMPONENTS Core Widgets Xml)
find_package(Graphviz REQUIRED)
find_package(jsoncpp REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
alt_library(alib2gui
DEPENDS alib2str alib2xml alib2common alib2abstraction alib2measure alib2std Qt5::Widgets Qt5::Xml ${GRAPHVIZ_LIBRARIES} ${jsoncpp_LIBRARIES}
INCLUDES ${GRAPHVIZ_INCLUDE_DIRS} ${jsoncpp_INCLUDE_DIR}
TEST_DEPENDS alib2aux alib2algo
)
[General]
category: library
groups: gui
[Dependencies]
project: alib2str alib2xml alib2common alib2abstraction alib2measure alib2std
system: xml2 Qt5Widgets Qt5Xml graphviz json
[TestDependencies]
project: alib2algo alib2aux
[CMake]
CMAKE_AUTOMOC: ON
CMAKE_AUTOUIC: ON
;Compatibility with cmake 3.7 (autogen)
CMAKE_INCLUDE_CURRENT_DIR: ON
project(alt-testing VERSION ${CMAKE_PROJECT_VERSION})
alt_testing(alib2integrationtest
TEST_DEPENDS alib2cli alib2str alib2std alib2common alib2algo alib2data alib2elgo alib2aux stdc++fs catch2
)
[General]
category: testing
groups: cli
[TestDependencies]
project: alib2cli alib2str alib2std alib2common alib2algo alib2data alib2elgo alib2aux
system: stdc++fs
#include "TestFiles.hpp"
#include "testfiles_basedir.hpp"
#include <exception/CommonException.h>
#if __has_include(<filesystem>)
#include <filesystem>
#else
#include <experimental/filesystem>
#define filesystem experimental::filesystem
#endif
#include "configure_tests.hpp"
using namespace std::literals;