Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize CMake #1524

Merged
merged 28 commits into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
eb29768
Modernize CMake
phcerdan Oct 15, 2020
17bc025
Fix removal of -frounding-math (clang) when CMAKE_CXX_FLAGS is empty
phcerdan Oct 16, 2020
7f37733
Fix INSTALL_INCLUDE_DIR is already absolute
phcerdan Oct 16, 2020
ad80b6a
Allow user to change install folders via `INSTALL_X_DIR_RELATIVE`
phcerdan Oct 16, 2020
36798ee
Modernize DGtalConfig.cmake
phcerdan Oct 16, 2020
196ce2c
Change add_definitions still present in Common.cmake
phcerdan Oct 16, 2020
8398c8a
Add DGTAL_CONFIG_HINTS option.
phcerdan Oct 17, 2020
dc620a8
Move debug and verbose options from Common.cmake to DevelopmentOption…
phcerdan Oct 18, 2020
a416483
Fix check of Foo_DIR for HINTS
phcerdan Oct 18, 2020
9f1b822
Distribute FindFoo.cmake files
phcerdan Oct 19, 2020
59303e5
Adding Catch2 as external deps using Fetch_Content
dcoeurjo Dec 1, 2020
74ea5f6
Adding Catch2 as external deps using Fetch_Content (missing file)
dcoeurjo Dec 1, 2020
da59a04
Adding Catch2 as external deps using Fetch_Content (missing file)
dcoeurjo Dec 1, 2020
07e3abc
Adding Catch2 as external deps using Fetch_Content (missing file)
dcoeurjo Dec 1, 2020
85e08e7
Comment added
dcoeurjo Dec 1, 2020
242c032
Download Catch2 only when testing is on
dcoeurjo Dec 1, 2020
8ca64f5
Download Catch2 only when testing is on (typo)
dcoeurjo Dec 1, 2020
66c4af5
Bumping mandatory cmake version to 3.11
dcoeurjo Dec 1, 2020
d4f52a1
FetchContent_MakeAvailable for cmake >3.11 but <3.14+
dcoeurjo Dec 1, 2020
32ab055
FetchContent_MakeAvailable for cmake >3.11 but <3.14+ (typo)
dcoeurjo Dec 1, 2020
3836f5d
lower case in cmake fetch_content
dcoeurjo Dec 1, 2020
a201cbb
OSX image with xcode10.1
dcoeurjo Dec 2, 2020
c86b448
Changelog entry for Catch2
dcoeurjo Dec 2, 2020
309b81b
CMake: Simplify `add_library(DGtal)` into one command
phcerdan Dec 8, 2020
d84ba9d
Merge branch 'master' into modernize_cmake
dcoeurjo Dec 27, 2020
1e4cba0
Delete FindCOIN3D.cmake
dcoeurjo Dec 27, 2020
9febcfb
Delete FindSOQT.cmake
dcoeurjo Dec 27, 2020
d376074
Update ChangeLog for CMake branch
phcerdan Dec 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ os:
- linux
- osx


osx_image: xcode12

cache:
Expand Down
98 changes: 72 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,122 @@
# Project definition
# -----------------------------------------------------------------------------
project (DGtal)
cmake_minimum_required (VERSION 3.1)
cmake_minimum_required (VERSION 3.11)

# -----------------------------------------------------------------------------
# By default, do not warn when built on machines using only VS Express:
# -----------------------------------------------------------------------------
IF(NOT DEFINED CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS)
SET(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON)
ENDIF()
if(NOT DEFINED CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS)
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON)
endif()

# -----------------------------------------------------------------------------
# Define variables and cmake parameters, and display some information
# -----------------------------------------------------------------------------
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
SET(DGtal_VERSION_MAJOR 1)
SET(DGtal_VERSION_MINOR 2)
SET(DGtal_VERSION_PATCH beta)
SET(DGTAL_VERSION "${DGtal_VERSION_MAJOR}.${DGtal_VERSION_MINOR}.${DGtal_VERSION_PATCH}")
SET(PROJECT_VERSION "${DGtal_VERSION_MAJOR}.${DGtal_VERSION_MINOR}.${DGtal_VERSION_PATCH}")
SET(VERSION ${DGtal_VERSION_MAJOR}.${DGtal_VERSION_MINOR}.${DGtal_VERSION_PATCH})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
set(DGtal_VERSION_MAJOR 1)
set(DGtal_VERSION_MINOR 2)
set(DGtal_VERSION_PATCH beta)
set(DGTAL_VERSION "${DGtal_VERSION_MAJOR}.${DGtal_VERSION_MINOR}.${DGtal_VERSION_PATCH}")
set(PROJECT_VERSION "${DGtal_VERSION_MAJOR}.${DGtal_VERSION_MINOR}.${DGtal_VERSION_PATCH}")
set(VERSION ${DGtal_VERSION_MAJOR}.${DGtal_VERSION_MINOR}.${DGtal_VERSION_PATCH})
# -----------------------------------------------------------------------------
# Common build options/settings
# -----------------------------------------------------------------------------
INCLUDE(Common)
include(Common)

#------------------------------------------------------------------------------
# Add DGtal library
#------------------------------------------------------------------------------

# Include CPP files to add to the library target
#
# each subdir can contain a ModuleSRC.txt file
# with a set command on the variable ${DGTAL_SRC}
#
include(src/DGtal/kernel/ModuleSRC.cmake)
include(src/DGtal/base/ModuleSRC.cmake)
include(src/DGtal/io/ModuleSRC.cmake)
include(src/DGtal/helpers/ModuleSRC.cmake)
## Board dependency
include(src/Board/ModuleSRC.cmake)
## Boost Add-ons
include(src/BoostAddons/ModuleSRC.cmake)

list(TRANSFORM DGTAL_SRC PREPEND "src/")
list(TRANSFORM BOARD_SRC PREPEND "src/")
list(TRANSFORM DGTALIO_SRC PREPEND "src/")

# DGtal Target. Library is added on the top directory to use target_link_libraries for CMake < 3.13
add_library (DGtal ${DGTAL_SRC} ${DGTALIO_SRC} ${BOARD_SRC} )
target_include_directories(DGtal PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src>
# INSTALL_INTERFACE must not contain absolute paths
$<INSTALL_INTERFACE:${INSTALL_INCLUDE_DIR_RELATIVE}>
)

install(TARGETS DGtal
# IMPORTANT: Add the DGtal library to the "export-set"
EXPORT DGtalLibraryDepends
RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT bin
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" COMPONENT shlib
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
#PUBLIC_HEADER DESTINATION "${INSTALL_INCLUDE_DIR}/DGtal"
COMPONENT dev)

# Misc
if( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
# Add -fPIC
set_target_properties(DGtal PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()

# -----------------------------------------------------------------------------
# Development and debug options
# -----------------------------------------------------------------------------
include(DevelopmentOptions)

# -----------------------------------------------------------------------------
# Common build options/settings
# -----------------------------------------------------------------------------
INCLUDE(OSDependentSettings)
include(OSDependentSettings)

# -----------------------------------------------------------------------------
# Check Mandatory Dependencies
# -----------------------------------------------------------------------------
INCLUDE(CheckDGtalDependencies)
include(CheckDGtalDependencies)

# -----------------------------------------------------------------------------
# Check Optional Dependencies
# -----------------------------------------------------------------------------
INCLUDE(CheckDGtalOptionalDependencies)
include(CheckDGtalOptionalDependencies)

# -----------------------------------------------------------------------------
# Debug, Cpack and Ctest settings
# -----------------------------------------------------------------------------
INCLUDE(CpackCtest)
include(CpackCtest)

# -----------------------------------------------------------------------------
# Code coverage
# -----------------------------------------------------------------------------
INCLUDE(CheckCoverage)
include(CheckCoverage)

# -----------------------------------------------------------------------------
# Custom command/targets depending on the cmake generator
# -----------------------------------------------------------------------------
INCLUDE(GeneratorSpecific)

#------------------------------------------------------------------------------
# Add subdirectories
#------------------------------------------------------------------------------
add_subdirectory(${PROJECT_SOURCE_DIR}/src)
include(GeneratorSpecific)

#------------------------------------------------------------------------------
# Examples
#------------------------------------------------------------------------------
INCLUDE(BuildExamples)
include(BuildExamples)

# -----------------------------------------------------------------------------
# Install settings
# -----------------------------------------------------------------------------
INCLUDE(Install)
include(Install)

# -----------------------------------------------------------------------------
# Unzip and install topology Look up Tables.
# -----------------------------------------------------------------------------
INCLUDE(NeighborhoodTablesConfig)
include(NeighborhoodTablesConfig)
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# DGtal 1.2 (dev)

## Changes

- *Project*
- Add azure-pipelines in `wrap` folder to kickstart python wrappings
(Pablo Hernandez-Cerdan [#1529](https://github.com/DGtal-team/DGtal/pull/1529))
Expand Down Expand Up @@ -41,6 +43,10 @@
set for the Board3DTo2D export (David Coeurjolly,
[#1537](https://github.com/DGtal-team/DGtal/pull/1537))

- *Build*
- We now use cmake *Fetch_Content* to download the stable release of
Catch2 (used in our unit-tests) when building the project (David
Coeurjolly [#1524](https://github.com/DGtal-team/DGtal/issues/1524))

# DGtal 1.1

Expand Down
8 changes: 4 additions & 4 deletions cmake/BuildExamples.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
OPTION(BUILD_EXAMPLES "Build examples." ON)
IF (BUILD_EXAMPLES)
option(BUILD_EXAMPLES "Build examples." ON)
if (BUILD_EXAMPLES)
message(STATUS "Build examples ENABLED")
add_subdirectory (${PROJECT_SOURCE_DIR}/examples)
ELSE(BUILD_EXAMPLES)
else()
message(STATUS "Build examples DISABLED (you can activate unit tests with '-DBUILD_EXAMPLES=ON' cmake option)")
ENDIF(BUILD_EXAMPLES)
endif()
message(STATUS "-------------------------------------------------------------------------------")
20 changes: 10 additions & 10 deletions cmake/CheckCoverage.cmake
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# -----------------------------------------------------------------------------
# Coverage brute-froce discovery
# -----------------------------------------------------------------------------
ADD_CUSTOM_TARGET(lcov)
OPTION(WITH_COVERAGE "Enable lcov code coverage." OFF)
IF (WITH_COVERAGE)
MESSAGE(STATUS "Code coverage enabled")
add_custom_target(lcov)
option(WITH_COVERAGE "Enable lcov code coverage." OFF)
if (WITH_COVERAGE)
message(STATUS "Code coverage enabled")
message(STATUS "-------------------------------------------------------------------------------")
SET(DGTAL_PATTERN "*/src/DGtal/*")
ADD_CUSTOM_COMMAND(TARGET lcov
set(DGTAL_PATTERN "*/src/DGtal/*")
add_custom_command(TARGET lcov
COMMAND mkdir -p coverage
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
ADD_CUSTOM_COMMAND(TARGET lcov
COMMAND lcov --directory . --capture --output-file ./coverage/stap_all.info --no-checksum
add_custom_command(TARGET lcov
COMMAND lcov --directory . --capture --output-file ./coverage/stap_all.info --no-checksum
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
ADD_CUSTOM_COMMAND(TARGET lcov
add_custom_command(TARGET lcov
COMMAND lcov --directory . --extract ./coverage/stap_all.info ${DGTAL_PATTERN} --output-file ./coverage/stap.info
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
ENDIF()
endif()
33 changes: 21 additions & 12 deletions cmake/CheckDGtalDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,44 @@
message(STATUS "-------------------------------------------------------------------------------")
message(STATUS "DGtal required dependencies: ")

# -----------------------------------------------------------------------------
# Downloading external deps
# -----------------------------------------------------------------------------
message(STATUS "Downloading external projects")
include(FetchExternalDeps)
message(STATUS "Done.")

# -----------------------------------------------------------------------------
# Looking for boost
# -----------------------------------------------------------------------------
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_FOUND FALSE)
FIND_PACKAGE(Boost 1.50.0 REQUIRED)
find_package(Boost 1.50.0 REQUIRED)
if ( Boost_FOUND )
ADD_DEFINITIONS(${BOOST_DEFINITIONS} -DBOOST_ALL_NO_LIB)
target_compile_definitions(DGtal PUBLIC ${BOOST_DEFINITIONS} -DBOOST_ALL_NO_LIB)
# SYSTEM to avoid warnings from boost.
include_directories(SYSTEM ${Boost_INCLUDE_DIRS} )
SET(DGtalLibInc ${DGtalLibInc} ${Boost_INCLUDE_DIRS})
endif( Boost_FOUND )
target_include_directories(DGtal SYSTEM PUBLIC ${Boost_INCLUDE_DIRS} )
set(DGtalLibInc ${DGtalLibInc} ${Boost_INCLUDE_DIRS})
endif()

# -----------------------------------------------------------------------------
# Looking for zlib
# -----------------------------------------------------------------------------
set(ZLIB_FOUND FALSE)
FIND_PACKAGE(ZLIB REQUIRED)
find_package(ZLIB REQUIRED)
if ( ZLIB_FOUND )
include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS} )
SET(DGtalLibInc ${DGtalLibInc} ${ZLIB_INCLUDE_DIRS})
SET(DGtalLibDependencies ${DGtalLibDependencies} ${ZLIB_LIBRARIES})
endif( ZLIB_FOUND )
target_include_directories(DGtal SYSTEM PUBLIC ${ZLIB_INCLUDE_DIRS} )
set(DGtalLibInc ${DGtalLibInc} ${ZLIB_INCLUDE_DIRS})
target_link_libraries(DGtal PUBLIC ${ZLIB_LIBRARIES})
set(DGtalLibDependencies ${DGtalLibDependencies} ${ZLIB_LIBRARIES})
endif()

# -----------------------------------------------------------------------------
# Setting librt dependency on Linux
# -----------------------------------------------------------------------------
if (UNIX AND NOT(APPLE))
SET(DGtalLibDependencies ${DGtalLibDependencies} -lrt)
if (UNIX AND NOT APPLE)
target_link_libraries(DGtal PUBLIC rt)
set(DGtalLibDependencies ${DGtalLibDependencies} -lrt)
endif()
Loading