Skip to content

Commit

Permalink
Upgrade CMake structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
iago-lito committed Mar 3, 2022
1 parent 0041cc0 commit 74cb946
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ doc/

singularity.def
Dockerfile

# clang files.
.cache
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "deps/toml++"]
path = src/deps/toml++
path = extern/toml++
url = https://github.com/marzer/tomlplusplus
60 changes: 60 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
cmake_minimum_required(VERSION 3.9..3.22)

project(decx VERSION 0.21.0 LANGUAGES C CXX Fortran)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

# Check C++/Fortran compatibility according to:
# https://enccs.github.io/cmake-workshop/cxx-fortran/
include(FortranCInterface)
fortrancinterface_verify(CXX)
# Some warnings have turned into a hard error since gfortran > 10.
# Ignore and compile anyway (https://forum.abinit.org/viewtopic.php?f=2&t=5205).
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-argument-mismatch")

# Dependencies.
find_package(GSL REQUIRED)
find_package(Boost 1.59.0 REQUIRED)
find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)

# Optimize release build.
if(CMAKE_BUILD_TYPE STREQUAL "Release")

# Inter-procedural optimization.
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED OUTPUT IPO_ERROR)
if(IPO_SUPPORTED)
message(STATUS "IPO / LTO supported..")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
message(STATUS "IPO / LTO enabled for all targets.")
else()
message(STATUS "IPO / LTO not supported: <${IPO_ERROR}>")
endif()

# Optimize for local architecture.
set(flag "-march=native")
foreach(LG IN ITEMS C CXX Fortran)
string(TOLOWER ${LG} lg)
include(Check${LG}CompilerFlag)
cmake_language(
CALL check_${lg}_compiler_flag
${flag} ${LG}_MARCH_NATIVE_SUPPORTED
)
if(${LG}_MARCH_NATIVE_SUPPORTED)
string(APPEND CMAKE_${LG}_FLAGS_RELEASE " ${flag}")
message(STATUS "${LG}: ${flag} enabled for all targets.")
endif()
endforeach()

# -O3 and -DNDebug are automatically passed in release mode.
endif()

# External source code dependencies.
add_subdirectory(extern)

# Main application.
add_subdirectory(src)
2 changes: 1 addition & 1 deletion containerize.bash
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ read -r -d '' COMPILATION_LAYER <<-'EOF'
# Compile
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ../src
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j $(nproc)
#---------------------------------------------------------------------------
EOF
Expand Down
6 changes: 6 additions & 0 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Third-party header library to parse TOML files.
add_library(toml++ INTERFACE)
target_include_directories(
toml++ INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}/toml++/include"
)
File renamed without changes.
37 changes: 5 additions & 32 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,3 @@
cmake_minimum_required(VERSION 3.9.0)
set(CMAKE_CXX_STANDARD 17)

project(decx VERSION 0.21.0 LANGUAGES C CXX Fortran)

# Check C++/Fortran compatibility according to:
# https://enccs.github.io/cmake-workshop/cxx-fortran/
include(FortranCInterface)
fortrancinterface_verify(CXX)
# Some warning have turned into a hard error since gfortran > 10.
# Ignore and compile anyway (https://forum.abinit.org/viewtopic.php?f=2&t=5205).
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-argument-mismatch")

# Dependencies.
find_package(GSL REQUIRED)
find_package(Boost 1.59.0 REQUIRED)
find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)


# Release mode.
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_Fortran_FLAGS_RELEASE "-O3")

# TOML++ is not mainstream enough to have its own FindTOMLPLUSPLUS ¯\(ツ)/¯
# Still, ensure updates with a dedicated git submodule.
include_directories(${PROJECT_SOURCE_DIR}/deps)

add_executable(
decx main.cpp

Expand All @@ -40,21 +12,22 @@ add_executable(
BioGeoTree.cpp
BioGeoTreeTools.cpp
BranchSegment.cpp
config_parsing.cpp
InputReader.cpp
node.cpp
OptimizeBioGeo.cpp
RateMatrixUtils.cpp
RateModel.cpp
Utils.cpp
config_parsing.cpp
node.cpp
superdouble.cpp
tree.cpp
tree_reader.cpp
Utils.cpp
)

target_link_libraries(
decx
decx PRIVATE
${GSL_LIBRARIES}
${BLAS_LIBRARIES}
${LAPACK_LIBRARIES}
toml++
)
2 changes: 1 addition & 1 deletion src/config_parsing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// and handle errors.

#include <iostream>
#include <toml++/toml.hpp>
#include <toml++/toml.h>

namespace config {

Expand Down
1 change: 0 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <iomanip>
#include <ctime>
#include <numeric>
#include <toml++/toml.hpp>

using namespace std;

Expand Down

0 comments on commit 74cb946

Please sign in to comment.