Skip to content

Commit

Permalink
Tidy up the CMake build, add an installation option, tidy up AppVeyor…
Browse files Browse the repository at this point in the history
… using the Ninja CMake generator, and fix _source_group(...)_ usage

Closes #27, #29, #30, #31
  • Loading branch information
demianmnave committed May 14, 2021
1 parent a9d03e6 commit bd57251
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 90 deletions.
20 changes: 3 additions & 17 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,21 @@ version: build-{branch}-#{build}

branches:
only:
- master
# - develop
# - master
- develop

environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
GENERATOR: "Visual Studio 15 2017 Win64"
CONFIG: Release
VCPATH: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community"

- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
GENERATOR: "Visual Studio 16 2019"
CMAKE_ARCH: -A x64
CONFIG: Release
VCPATH: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community"

# - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
# GENERATOR: "Visual Studio 16 2019"
# CMAKE_ARCH: -A x64
# CMAKE_TOOLKIT: -T ClangCl
# CONFIG: Release
# VCPATH: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community"

build_script:
- cmd: call "%VCPATH%\VC\Auxiliary\Build\vcvars64.bat"
- cmd: mkdir build
- cmd: cd build
- cmd: echo Executing cmake -G %GENERATOR% %CMAKE_ARCH% %CMAKE_TOOLKIT%
- cmd: cmake "-G%GENERATOR%" %CMAKE_ARCH% %CMAKE_TOOLKIT% -DCMAKE_CXX_STANDARD=11 -DCML_BUILD_TESTING=ON ..
- cmd: cmake .. -GNinja -DCML_BUILD_TESTING=ON
- cmd: cmake --build . --config "%CONFIG%"

test_script:
Expand Down
55 changes: 28 additions & 27 deletions CML.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
# @@COPYRIGHT@@
#*-------------------------------------------------------------------------

if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
set(_header_group "Header Files\\")
else()
set(_header_group)
endif()

set(main_HEADERS
cml/cml.h
cml/matrix.h
Expand All @@ -17,7 +11,6 @@ set(main_HEADERS
cml/vector.h
cml/version.h
)
source_group("${_header_group}" FILES ${main_HEADERS})

set(common_HEADERS
cml/common/array_size_of.h
Expand All @@ -33,7 +26,6 @@ set(common_HEADERS
cml/common/traits.h
cml/common/type_util.h
)
source_group("${_header_group}common" FILES ${common_HEADERS})

set(common_mpl_HEADERS
cml/common/mpl/are_convertible.h
Expand All @@ -56,7 +48,6 @@ set(common_mpl_HEADERS
cml/common/mpl/type_map.h
cml/common/mpl/type_table.h
)
source_group("${_header_group}common\\mpl" FILES ${common_mpl_HEADERS})

set(scalar_HEADERS
cml/scalar/binary_ops.h
Expand All @@ -66,7 +57,6 @@ set(scalar_HEADERS
cml/scalar/traits.h
cml/scalar/unary_ops.h
)
source_group("${_header_group}scalar" FILES ${scalar_HEADERS})

set(storage_HEADERS
cml/storage/allocated_selector.h
Expand All @@ -78,7 +68,6 @@ set(storage_HEADERS
cml/storage/selectors.h
cml/storage/type_util.h
)
source_group("${_header_group}storage" FILES ${storage_HEADERS})

set(vector_HEADERS
cml/vector/binary_node.h
Expand Down Expand Up @@ -145,14 +134,12 @@ set(vector_HEADERS
cml/vector/writable_vector.h
cml/vector/writable_vector.tpp
)
source_group("${_header_group}vector" FILES ${vector_HEADERS})

set(vector_detail_HEADERS
cml/vector/detail/check_or_resize.h
cml/vector/detail/combined_size_of.h
cml/vector/detail/resize.h
)
source_group("${_header_group}vector\\detail" FILES ${vector_detail_HEADERS})

set(matrix_HEADERS
cml/matrix/array_size_of.h
Expand Down Expand Up @@ -221,7 +208,6 @@ set(matrix_HEADERS
cml/matrix/writable_matrix.h
cml/matrix/writable_matrix.tpp
)
source_group("${_header_group}matrix" FILES ${matrix_HEADERS})

set(matrix_detail_HEADERS
cml/matrix/detail/apply.h
Expand All @@ -237,7 +223,6 @@ set(matrix_detail_HEADERS
cml/matrix/detail/resize.h
cml/matrix/detail/transpose.h
)
source_group("${_header_group}matrix\\detail" FILES ${matrix_detail_HEADERS})

set(quaternion_HEADERS
cml/quaternion/binary_node.h
Expand Down Expand Up @@ -291,7 +276,6 @@ set(quaternion_HEADERS
cml/quaternion/writable_quaternion.h
cml/quaternion/writable_quaternion.tpp
)
source_group("${_header_group}quaternion" FILES ${quaternion_HEADERS})

set(mathlib_HEADERS
cml/mathlib/axis_order.h
Expand All @@ -305,7 +289,6 @@ set(mathlib_HEADERS
cml/mathlib/random_unit.h
cml/mathlib/random_unit.tpp
)
source_group("${_header_group}mathlib" FILES ${mathlib_HEADERS})

set(mathlib_vector_HEADERS
cml/mathlib/vector/angle.h
Expand All @@ -321,7 +304,6 @@ set(mathlib_vector_HEADERS
cml/mathlib/vector/transform.h
cml/mathlib/vector/transform.tpp
)
source_group("${_header_group}mathlib\\vector" FILES ${mathlib_vector_HEADERS})

set(mathlib_matrix_HEADERS
cml/mathlib/matrix/basis.h
Expand All @@ -347,16 +329,13 @@ set(mathlib_matrix_HEADERS
cml/mathlib/matrix/translation.h
cml/mathlib/matrix/translation.tpp
)
source_group("${_header_group}mathlib\\matrix" FILES ${mathlib_matrix_HEADERS})

set(mathlib_quaternion_HEADERS
cml/mathlib/quaternion/basis.h
cml/mathlib/quaternion/basis.tpp
cml/mathlib/quaternion/rotation.h
cml/mathlib/quaternion/rotation.tpp
)
source_group("${_header_group}mathlib\\quaternion"
FILES ${mathlib_quaternion_HEADERS})

set(util_HEADERS
cml/util/matrix_print.h
Expand All @@ -367,7 +346,6 @@ set(util_HEADERS
cml/util/vector_print.h
cml/util/vector_print.tpp
)
source_group("${_header_group}\\util" FILES ${util_HEADERS})

set(all_headers
${main_HEADERS}
Expand All @@ -387,10 +365,33 @@ set(all_headers
${mathlib_quaternion_HEADERS}
)

add_library(cml INTERFACE)
target_compile_options(cml INTERFACE $<$<CXX_COMPILER_ID:MSVC>:/permissive->)
target_compile_features(cml INTERFACE
cxx_reference_qualified_functions
cxx_constexpr
cxx_defaulted_functions
)
target_include_directories(cml INTERFACE $<BUILD_INTERFACE:${CML_ROOT}>)
target_include_directories(cml INTERFACE $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>)

option(CML_ENABLE_DEV
"Enable the cml-dev custom target to see headers to an IDE" OFF)
if(CML_ENABLE_DEV)
add_custom_target(cml-dev SOURCES ${all_headers})
endif()
# Setup a custom target, and use IDE groups for the headers when possible:
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
set(_header_group "Header Files\\")
source_group("${_header_group}" FILES ${main_HEADERS})
source_group("${_header_group}common" FILES ${common_HEADERS})
source_group("${_header_group}common\\mpl" FILES ${common_mpl_HEADERS})
source_group("${_header_group}scalar" FILES ${scalar_HEADERS})
source_group("${_header_group}storage" FILES ${storage_HEADERS})
source_group("${_header_group}vector" FILES ${vector_HEADERS})
source_group("${_header_group}vector\\detail" FILES ${vector_detail_HEADERS})
source_group("${_header_group}matrix" FILES ${matrix_HEADERS})
source_group("${_header_group}matrix\\detail" FILES ${matrix_detail_HEADERS})
source_group("${_header_group}quaternion" FILES ${quaternion_HEADERS})
source_group("${_header_group}mathlib" FILES ${mathlib_HEADERS})
source_group("${_header_group}mathlib\\vector" FILES ${mathlib_vector_HEADERS})
source_group("${_header_group}mathlib\\matrix" FILES ${mathlib_matrix_HEADERS})
source_group("${_header_group}mathlib\\quaternion" FILES ${mathlib_quaternion_HEADERS})
source_group("${_header_group}\\util" FILES ${util_HEADERS})
endif()
add_custom_target(cml-dev SOURCES ${all_headers})
2 changes: 2 additions & 0 deletions CMake/cml-config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include("${CMAKE_CURRENT_LIST_DIR}/cml-targets.cmake")
add_library(cml INTERFACE IMPORTED)
41 changes: 27 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#*-------------------------------------------------------------------------

# Set the minimum CMake version:
cmake_minimum_required(VERSION 3.12.4)
cmake_minimum_required(VERSION 3.15)

# Allow solution folders:
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
Expand All @@ -24,21 +24,14 @@ include(CMLBuildMacros)
# is from the root Boost.CMake CMakeLists.txt file):
cml_version_from_file(
${CML_ROOT}/cml/version.h # Path to version.h
"CML_VERSION" # The macro name to find
CML_VERSION_MAJOR # Parsed major version
CML_VERSION_MINOR # Parsed minor version
CML_VERSION_PATCH # Parsed patch version
CML_VERSION # String MM.mm.pp
"CML_VERSION" # The macro name to find
CML_VERSION_MAJOR # Parsed major version
CML_VERSION_MINOR # Parsed minor version
CML_VERSION_PATCH # Parsed patch version
CML_VERSION # String MM.mm.pp
)
message(STATUS "Building CML ${CML_VERSION}")

# Define the CML interface library and required C++ features:
add_library(cml INTERFACE)
target_compile_features(cml INTERFACE
cxx_reference_qualified_functions # "rvalue reference from *this"
cxx_constexpr
)

# Create the CML interface library:
include(CML.cmake)

Expand All @@ -47,4 +40,24 @@ option(CML_BUILD_TESTING "Build CML tests" OFF)
if(CML_BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
endif()
endif()

# Installation and packaging:
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/cml-config-version.cmake
VERSION ${CML_VERSION}
COMPATIBILITY ExactVersion
)

include(GNUInstallDirs)
install(TARGETS cml DESTINATION ${CMAKE_INSTALL_LIBDIR} EXPORT cml-targets)
install(EXPORT cml-targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cml FILE cml-targets.cmake)
install(DIRECTORY cml DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*")
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/cml-config-version.cmake
CMake/cml-config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cml
)

export(EXPORT cml-targets FILE cml-config.cmake)
32 changes: 0 additions & 32 deletions cml/common/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,4 @@
# define CML_HAS_STRUCTURED_BINDINGS
#endif

#if defined(__GNUC__) && (__GNUC__ > 4 \
|| ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)))

/* Defaulted move constructor supported: */
# define CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR

#elif defined(__clang__)
/* Note: checking for Clang BEFORE checking for Visual Studio, since clang-cl
* defines _MSC_VER.
*/

/* Defaulted move constructor: */
# if ((__clang_major__ >= 4) \
|| ((__clang_major__ >= 3) && (__clang_minor__ >= 5))) \
|| (__apple_build_version__ >= 7000000)

# define CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR
# endif

#elif defined(_MSC_VER)

# if(_MSC_VER < 1914)
/* Apparently, VS2015 does not allow a parameter pack expansion to target non-
* packed parameters.
*/
# define CML_HAS_MSVC_WONKY_PARAMETER_PACK
# endif

#else
#error "Unsupported compiler."
#endif

#endif

0 comments on commit bd57251

Please sign in to comment.