Skip to content

Commit df448b0

Browse files
Initial effort to incorporate modern practices in top-level CMakeLists file (#365)
* feat: Initial effort to incorporate modern practices in top-level CMakeLists file - changes minimum cmake required version to 3.13.4 (default from the repos of oldest supported Debian as of June 2023) - adds project description and homepage url - explicitly sets the LANGUAGES keyword in the project() command as recommended in best practice guides - enforces language standard to c++17 - disables compiler-specific extensions that are otherwise enabled by default in CMake - exports the compilation database of the project (compile_commands.json) into CMAKE_BINARY_DIR - adds a custom command to symlink (filesystem agnostically) the compilation database from CMAKE_BINARY_DIR to PROJECT_SOURCE_DIR to be picked up by IDEs and static analysers * fix: update project URL to point to correct location
1 parent 63f4cfd commit df448b0

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,4 @@ _deps
129129
# Executables
130130
*.exe
131131
*.out
132-
*.app
132+
*.app

CMakeLists.txt

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1-
cmake_minimum_required(VERSION 3.0)
2-
project(Sopt CXX)
1+
cmake_minimum_required(VERSION 3.13.4) # CMake 3.13.4 is the currently default in Debian 10 repositories
2+
project(Sopt
3+
DESCRIPTION "Sparse OPTimisation using state-of-the-art convex optimisation algorithms."
4+
HOMEPAGE_URL "http://astro-informatics.github.io/sopt/"
5+
LANGUAGES CXX)
6+
7+
set(CMAKE_CXX_STANDARD 17)
8+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9+
set(CMAKE_CXX_EXTENSIONS OFF)
10+
11+
# https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html
12+
# Enable output of compile commands during generation. If enabled, generates a compile_commands.json file containing the exact compiler calls for all translation units of the project in machine-readable form. This can be consumed by various IDEs and static analysers to provide smarter project diagnostics/completions etc.
13+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
14+
15+
# https://stackoverflow.com/a/67410042
16+
# Create a symlink to compile_commands.json located in CMAKE_BINARY_DIR to the project root (works across filesystems)
17+
execute_process(
18+
COMMAND ${CMAKE_COMMAND} -E create_symlink
19+
${CMAKE_BINARY_DIR}/compile_commands.json
20+
${CMAKE_SOURCE_DIR}/compile_commands.json)
321

422
# Location of extra cmake includes for the project
523
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_files)
@@ -33,11 +51,7 @@ if(tests)
3351
enable_testing()
3452
endif()
3553

36-
# Add c++11 stuff
37-
#include(AddCPP11Flags)
38-
set(CMAKE_CXX_STANDARD 17)
39-
include(CheckCXX11Features)
40-
cxx11_feature_check(REQUIRED unique_ptr override)
54+
4155
include(compilations)
4256

4357
# search/install dependencies

0 commit comments

Comments
 (0)