Skip to content

Commit

Permalink
Clean-up CMake code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhuighuy committed Jun 21, 2023
1 parent e40b222 commit f0c10e6
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 166 deletions.
217 changes: 99 additions & 118 deletions CMakeLists.txt

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
- [ ] `mold` with `find_package`.
- [ ] `make_config_defaults.cmake` in `CMake`.
- [ ] `scripts/test.py` script and `CTest` integration.
- [ ] Configure `nanobench` with `vcpkg` and `CMake`.
- [ ] `scripts/benchmark.py` script.
- [x] `scripts/cloc.py` in Python.

### Linting
Expand Down
28 changes: 6 additions & 22 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,14 @@
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

# ------------------------------------------------------------------------------

# Core header-only library.
file(GLOB_RECURSE StormRuler_CXX_SOURCES "Storm/*.hpp")
add_library(StormRuler INTERFACE ${StormRuler_CXX_SOURCES})

# Include directories.
target_include_directories(StormRuler_BASE INTERFACE ".")

# ------------------------------------------------------------------------------

# Configuration file.
storm_configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/Storm/Config.hpp.in"
"${CMAKE_CURRENT_SOURCE_DIR}/Storm/Config.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Storm/ConfigDefault.hpp")

# ------------------------------------------------------------------------------

# Link with the base target.
target_link_libraries(StormRuler INTERFACE StormRuler_BASE)
# Add the core library.
message(STATUS "| Adding StormRuler core library..")
add_subdirectory(./Storm)

# ------------------------------------------------------------------------------
4 changes: 2 additions & 2 deletions source/.gitignore → source/Storm/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Ignore the generated configuration file.
# Default configuration file should be in the repository,
# it is used for non-CMake builds.
Storm/Config.hpp
!Storm/ConfigDefault.hpp
Config.hpp
!ConfigDefault.hpp

# ------------------------------------------------------------------------------
41 changes: 41 additions & 0 deletions source/Storm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (C) 2020-2023 Oleg Butakov
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

# ------------------------------------------------------------------------------

# Core header-only library.
file(GLOB_RECURSE CXX_SOURCES "./*.hpp")
add_library(StormRuler INTERFACE ${CXX_SOURCES})
add_library(StormRuler::StormRuler ALIAS StormRuler)

# ------------------------------------------------------------------------------

# Configuration file.
storm_configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/Config.hpp.in"
"${CMAKE_CURRENT_SOURCE_DIR}/Config.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ConfigDefault.hpp")

# ------------------------------------------------------------------------------

# Link with the base target.
target_link_libraries(StormRuler INTERFACE StormRuler::Base)

# ------------------------------------------------------------------------------
14 changes: 10 additions & 4 deletions source_apps/playground/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

# ------------------------------------------------------------------------------

# Playground application.
file(GLOB CXX_SOURCES "./*.cpp")
add_executable(StormRuler_Playground ${CXX_SOURCES})

# ------------------------------------------------------------------------------

# Link with the main library.
target_link_libraries(StormRuler_Playground StormRuler)
target_link_libraries(StormRuler_Playground PRIVATE StormRuler::StormRuler)

# Something for Visual Studio.
set_target_properties(StormRuler_Playground PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")

# ------------------------------------------------------------------------------
7 changes: 2 additions & 5 deletions source_docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,12 @@ set(DOXYGEN_HTML_EXTRA_STYLESHEET
# ------------------------------------------------------------------------------

# Add the C++ sources and Markdown pages.
file(GLOB_RECURSE MD_SOURCES ./*.md)
list(APPEND StormRuler_Doxygen_INPUTS ${MD_SOURCES})
file(GLOB_RECURSE CXX_SOURCES ../source/*.hpp)
list(APPEND StormRuler_Doxygen_INPUTS ${CXX_SOURCES})
file(GLOB_RECURSE SOURCES "./*.md" "../source/*.hpp" "../source/*.cpp")

# Add the Doxygen target.
message(STATUS "| Adding the Doxygen documentation..")
doxygen_add_docs(StormRuler_Doxygen ALL
USE_STAMP_FILE ${StormRuler_Doxygen_INPUTS}
USE_STAMP_FILE ${SOURCES}
COMMENT "Generate Doxygen documentation")

# ------------------------------------------------------------------------------
26 changes: 13 additions & 13 deletions tests/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,51 +27,51 @@ add_executable(StormRuler_Benchmarks ${CXX_SOURCES})
# ------------------------------------------------------------------------------

# Link with the core library.
target_link_libraries(StormRuler_Benchmarks StormRuler)
target_link_libraries(StormRuler_Benchmarks PRIVATE StormRuler::StormRuler)

# ------------------------------------------------------------------------------

# Find doctest.
find_package(doctest CONFIG REQUIRED)
target_link_libraries(StormRuler_Benchmarks doctest::doctest)
target_link_libraries(StormRuler_Benchmarks PRIVATE doctest::doctest)

# Find nanobench.
# TODO: Something is broken with nanobench + vcpkg + CMake.
#find_package(nanobench CONFIG REQUIRED)
#target_link_libraries(StormRuler_Benchmarks nanobench)
#target_link_libraries(StormRuler_Benchmarks PRIVATE nanobench)

# ------------------------------------------------------------------------------

# Find Armadillo.
find_package(Armadillo CONFIG QUIET)
find_package(Armadillo QUIET)
if(Armadillo_FOUND)
set(STORM_BENCH_ARMADILLO_ENABLED 1)
message(STATUS "| Benchmarks: Armadillo enabled.")
target_link_libraries(StormRuler_Benchmarks ${ARMADILLO_LIBRARIES})
message(STATUS "| | Benchmarks: Armadillo enabled.")
target_link_libraries(StormRuler_Benchmarks PRIVATE ${ARMADILLO_LIBRARIES})
endif()

# Find Blaze.
find_package(blaze CONFIG QUIET)
find_package(blaze QUIET)
if(blaze_FOUND)
set(STORM_BENCH_BLAZE_ENABLED 1)
message(STATUS "| Benchmarks: Blaze enabled.")
target_link_libraries(StormRuler_Benchmarks blaze::blaze)
message(STATUS "| | Benchmarks: Blaze enabled.")
target_link_libraries(StormRuler_Benchmarks PRIVATE blaze::blaze)
endif()

# Find Eigen.
find_package(Eigen3 3.4 NO_MODULE QUIET)
if(Eigen3_FOUND)
set(STORM_BENCH_EIGEN_ENABLED 1)
message(STATUS "| Benchmarks: Eigen enabled.")
target_link_libraries(StormRuler_Benchmarks Eigen3::Eigen)
message(STATUS "| | Benchmarks: Eigen enabled.")
target_link_libraries(StormRuler_Benchmarks PRIVATE Eigen3::Eigen)
endif()

# Find XTensor.
find_package(xtensor QUIET)
if(xtensor_FOUND)
set(STORM_BENCH_XTENSOR_ENABLED 1)
message(STATUS "| Benchmarks: XTensor enabled.")
target_link_libraries(StormRuler_Benchmarks xtensor)
message(STATUS "| | Benchmarks: XTensor enabled.")
target_link_libraries(StormRuler_Benchmarks PRIVATE xtensor)
endif()

# ------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ add_executable(StormRuler_UnitTests ${CXX_SOURCES})
# ------------------------------------------------------------------------------

# Link with the core library.
target_link_libraries(StormRuler_UnitTests StormRuler)
target_link_libraries(StormRuler_UnitTests PRIVATE StormRuler::StormRuler)

# ------------------------------------------------------------------------------

# Find doctest.
find_package(doctest CONFIG REQUIRED)
target_link_libraries(StormRuler_UnitTests doctest::doctest)
target_link_libraries(StormRuler_UnitTests PRIVATE doctest::doctest)

# ------------------------------------------------------------------------------

0 comments on commit f0c10e6

Please sign in to comment.