Skip to content

Commit

Permalink
Rewrite build logic with mordernized CMake format
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitan94 committed Jun 12, 2020
1 parent 014850d commit 42fbc89
Show file tree
Hide file tree
Showing 28 changed files with 749 additions and 17,815 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ jobs:
# access regardless of the host operating system
shell: bash -l {0}

- name: Configure CMake
- name: Configure CMake for tests
shell: bash -l {0}
working-directory: ${{runner.workspace}}/daylight
run: cmake -B build -S . -DCMAKE_BUILD_TYPE=$BUILD_TYPE
run: cmake -Htest -Bbuild/test -DCMAKE_BUILD_TYPE=$BUILD_TYPE

- name: Build
working-directory: ${{runner.workspace}}/daylight
shell: bash -l {0}
run: cmake --build build --config $BUILD_TYPE
run: cmake --build build/test --config $BUILD_TYPE

- name: Run Unit Tests
working-directory: ${{runner.workspace}}/daylight/build
working-directory: ${{runner.workspace}}/daylight/build/test
shell: bash -l {0}
run: ctest --output-on-failure -C $BUILD_TYPE

Expand All @@ -48,4 +48,6 @@ jobs:
shell: bash -l {0}
run: |
pip install sphinx sphinx_rtd_theme numpy numpydoc
cmake --build build --config $BUILD_TYPE --target pydoctest
cmake -Hdocs -Bbuild/docs -DCMAKE_BUILD_TYPE=$BUILD_TYPE
cmake --build build/docs --config $BUILD_TYPE
cmake --build build/docs --target pydoctest --config $BUILD_TYPE
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

83 changes: 69 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,76 @@
cmake_minimum_required(VERSION 3.12)
set(CMAKE_CXX_STANDARD 11)
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

# ---- Project ----

project(libdaylight)
include(cmake/WriteVersionInfo.cmake)
# Get version from VERSION file instead of hardcoding here
# This is so that we can maintain a single version across C++ and Python
execute_process(COMMAND python tools/print_version.py OUTPUT_VARIABLE DAYLIGHT_VERSION)
set(PROJECT_VERSION ${DAYLIGHT_VERSION})

message(${DAYLIGHT_VERSION})

if(NOT DEFINED MSVC)
set(BUILD_SHARED_LIBS ON)
# ---- Include guards ----

if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.")
endif()

enable_testing()
# ---- Dependencies ----
# For more info on CPM dependecies, see https://github.com/TheLartians/CPM.cmake

include(cmake/CPM.cmake)

# PackageProject.cmake will be used to make our target installable
CPMAddPackage(
NAME PackageProject.cmake
GITHUB_REPOSITORY TheLartians/PackageProject.cmake
VERSION 1.3
)

# ---- Add source files ----

# Note: globbing sources is considered bad practice as CMake's generators may not detect new files automatically.
# Keep that in mind when changing files, or explicitly mention them here.
file(GLOB_RECURSE headers CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp")
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")

# ---- Create library ----

add_library(libdaylight ${headers} ${sources})

set_target_properties(libdaylight PROPERTIES
CXX_STANDARD 11
POSITION_INDEPENDENT_CODE ON
PREFIX ""
)

if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()

# being a cross-platform target, we enforce standards conformance on MSVC
target_compile_options(libdaylight PUBLIC "$<$<BOOL:${MSVC}>:/permissive->")

target_include_directories(libdaylight
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
)

# ---- Create an installable target ----
# this allows users to install and find the library via `find_package()`.

# Ensures all git submodules are present
execute_process(COMMAND git submodule update --init --recursive)
# the location where the project's version header will be placed
# should match the project's regular header paths
string(TOLOWER ${PROJECT_NAME}/version.h VERSION_HEADER_LOCATION)

add_subdirectory(libdaylight)
add_subdirectory(capi)
add_subdirectory(tests)
add_subdirectory(vendor/pybind11)
add_subdirectory(pybind)
add_subdirectory(docs)
packageProject(
NAME ${PROJECT_NAME}
VERSION ${PROJECT_VERSION}
BINARY_DIR ${PROJECT_BINARY_DIR}
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
VERSION_HEADER "${VERSION_HEADER_LOCATION}"
DEPENDENCIES ""
)
37 changes: 32 additions & 5 deletions capi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
file(GLOB_RECURSE _sources ${CMAKE_CURRENT_LIST_DIR}/*.cpp)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

add_library(libdaylight_c ${_sources})
set_target_properties(libdaylight_c PROPERTIES PREFIX "")
set_target_properties(libdaylight_c PROPERTIES SUFFIX "-${LIBDAYLIGHT_VERSION}.so")
target_link_libraries(libdaylight_c PRIVATE libdaylight)
project(
daylight_c
LANGUAGES CXX
)

# ---- Dependencies ----

include(../cmake/CPM.cmake)

CPMAddPackage(
NAME libdaylight
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..
)

# ---- Create library ----

file(GLOB_RECURSE headers CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
add_library(daylight_c ${headers} ${sources})
target_link_libraries(daylight_c libdaylight)

set_target_properties(daylight_c PROPERTIES CXX_STANDARD 11)

# being a cross-platform target, we enforce standards conformance on MSVC
target_compile_options(daylight_c PUBLIC "$<$<BOOL:${MSVC}>:/permissive->")

target_include_directories(daylight_c
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
)
1 change: 1 addition & 0 deletions capi/daylight_c.h → capi/include/daylight/daylight_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
extern "C" {
#endif

#include <daylight/Sunclock.hpp>
#include <time.h>

typedef struct Sunclock Sunclock;
Expand Down
3 changes: 1 addition & 2 deletions capi/daylight_c.cpp → capi/source/daylight_c.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "daylight_c.h"
#include <libdaylight/Sunclock.hpp>
#include <daylight/daylight_c.h>

extern "C" {
Sunclock *newSunclock(double const latitude_, double const longitude_,
Expand Down
Loading

0 comments on commit 42fbc89

Please sign in to comment.