-
December 27th, 2023, 03:16 PM
#1
I was trying to "modernise" my CMake files, but it didn't go very well!
I have the following `CMake` file:
Code:
cmake_minimum_required(VERSION 3.19...3.25 FATAL_ERROR)
project(
Turingforge
VERSION 0.1.0
DESCRIPTION "Hardware powered Symbolic Regression library."
HOMEPAGE_URL "https://"
LANGUAGES CXX C
)
#add_compile_options(-Wundef -Wcast-align -Wchar-subscripts -Wnon-virtual-dtor -Wunused-local-typedefs -Wpointer-arith
# -Wwrite-strings -Wformat-security -Wlogical-op -Wenum-conversion -Wdouble-promotion -Wconversion -Wshadow
# -Wno-psabi -Wno-variadic-macros -Wno-long-long -fno-check-new -fno-common -fstrict-aliasing)
#Make sure that custom modules are found
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake)
# Only do these if this is the main project, and not if it is included through add_subdirectory
if(PROJECT_IS_TOP_LEVEL)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
# Ensure -std=c++xx instead of -std=g++xx
set(CMAKE_CXX_EXTENSIONS OFF)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Testing only available if this is the main app
# Note this needs to be done in the main CMakeLists
# since it calls enable_testing, which must be in the
# main CMakeLists.
include(CTest)
# Docs only available if this is the main app
find_package(Doxygen)
if(Doxygen_FOUND)
add_subdirectory(docs)
else()
message(STATUS "Doxygen not found, not building docs")
endif()
endif()
##############################################
# Add subdirectories
add_subdirectory(src)
# The executable code is here
#add_subdirectory(apps)
# Testing only available if this is the main app
# Emergency override TURINGFORGE_CMAKE_BUILD_TESTING provided as well
if ((PROJECT_IS_TOP_LEVEL OR TURINGFORGE_CMAKE_BUILD_TESTING) AND BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
endif()
And additionally the `CMake` file responsible for building the library inside `src/`:
Code:
##############################################
# Find/Install system dependencies
include(FetchContent)
include(ExternalProject)
# Formatting library
FetchContent_Declare(
fmtlib
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 10.1.1)
set(FMT_INSTALL ON)
# Adds fmt::fmt
FetchContent_MakeAvailable(fmtlib)
# Eigen
FetchContent_Declare(
Eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG 3.4.0
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE)
set(EIGEN_BUILD_DOC OFF)
set(BUILD_TESTING OFF)
set(EIGEN_BUILD_PKGCONFIG OFF)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
FetchContent_MakeAvailable(Eigen)
find_package (Eigen3 3.4 REQUIRED NO_MODULE)
# Fast float
FetchContent_Declare(
fast_float
GIT_REPOSITORY https://github.com/fastfloat/fast_float.git
GIT_TAG tags/v6.0.0
GIT_SHALLOW TRUE)
set(FASTFLOAT_INSTALL OFF)
# Adds fast_float
FetchContent_MakeAvailable(fast_float)
# Fast unordered map and set
FetchContent_Declare(
unordered_dense
GIT_REPOSITORY https://github.com/martinus/unordered_dense.git
GIT_TAG tags/v4.3.1
GIT_SHALLOW TRUE)
# Adds unordered_dense::unordered_dense
FetchContent_MakeAvailable(unordered_dense)
# SIMD vector operations
# TODO: Figure out how to install vectorclass using `FetchContent`
FetchContent_Declare(
vectorclass
GIT_REPOSITORY https://github.com/vectorclass/version2.git
GIT_TAG tags/v2.02.01
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(vectorclass)
# Fast hash functions
FetchContent_Declare(
xxhash
GIT_REPOSITORY https://github.com/Cyan4973/xxHash.git
GIT_TAG tags/v0.8.2
GIT_SHALLOW TRUE)
set(XXHASH_BUNDLED_MODE ON)
set(XXH_INLINE_ALL ON)
# Adds xxhash
FetchContent_MakeAvailable(xxHash)
file(GLOB XXHASH_SOURCES ${xxhash_SOURCE_DIR}/*.c)
list(REMOVE_ITEM XXHASH_SOURCES ${xxhash_SOURCE_DIR}/xxhsum.c)
list(REMOVE_ITEM XXHASH_SOURCES ${xxhash_SOURCE_DIR}/xxh_x86dispatch.c)
add_library(xxhash STATIC ${XXHASH_SOURCES})
target_include_directories(xxhash PUBLIC ${xxhash_SOURCE_DIR})
##############################################
# Create target and set properties
file(GLOB_RECURSE HEADER_LIST CONFIGURE_DEPENDS
"${PROJECT_SOURCE_DIR}/include/turing_forge/*/*.hpp"
"${PROJECT_SOURCE_DIR}/include/vstat/*.hpp"
"${PROJECT_SOURCE_DIR}/include/csv/*.hpp"
)
file(GLOB SRC_LIST CONFIGURE_DEPENDS
"${PROJECT_SOURCE_DIR}/src/*/*.cpp"
)
add_library(turingforge
${SRC_LIST}
${HEADER_LIST}
)
#Add an alias so that library can be used inside the build tree, e.g. when testing
add_library(Turingforge::turingforge ALIAS turingforge)
#Set target properties
target_include_directories(turingforge
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include/csv
${CMAKE_CURRENT_SOURCE_DIR}/include/vstat
)
target_compile_features(turingforge PRIVATE cxx_auto_type)
target_compile_options(turingforge PRIVATE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:-Wall -Wextra -pedantic -Werror>)
target_link_libraries(turingforge
PUBLIC
fmt::fmt Eigen3::Eigen unordered_dense::unordered_dense
PRIVATE
xxhash vectorclass fast_float
)
##############################################
# Installation instructions
option(TURINGFORGE_INSTALL "Enable install" ON)
if (TURINGFORGE_INSTALL)
include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/Turingforge)
install(TARGETS turingforge
EXPORT turingforge-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
# This is required so that the exported target has the name Turingforge and not turingforge
set_target_properties(turingforge PROPERTIES EXPORT_NAME Turingforge)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# Export the targets to a script
install(EXPORT turingforge-targets
FILE
TuringforgeTargets.cmake
NAMESPACE
Turingforge::
DESTINATION
${INSTALL_CONFIGDIR}
)
# Create a ConfigVersion.cmake file
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/TuringforgeConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/../cmake/TuringforgeConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/TuringforgeConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)
# Install the config, configversion and custom find modules if any
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/TuringforgeConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/TuringforgeConfigVersion.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)
##############################################
## Exporting from the build tree
#configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/SOMECUSTOM.cmake
# ${CMAKE_CURRENT_BINARY_DIR}/SOMECUSTOM.cmake
# COPYONLY)
export(EXPORT turingforge-targets
FILE ${CMAKE_CURRENT_BINARY_DIR}/TuringforgeTargets.cmake
NAMESPACE Turingforge::)
# Register package in the User Package Registry
export(PACKAGE Turingforge)
# Make sure IDEs put the headers in a nice place
source_group(
TREE "${PROJECT_SOURCE_DIR}/include"
PREFIX "Header Files"
FILES ${HEADER_LIST}
)
endif()
But it's not working that well for me due to a number of reasons. First of all I get these errors from `cmake`:
Code:
CMake Error: install(EXPORT "turingforge-targets" ...) includes target "turingforge" which requires target "unordered_dense" that is not in any export set.
CMake Error: install(EXPORT "turingforge-targets" ...) includes target "turingforge" which requires target "xxhash" that is not in any export set.
CMake Error: install(EXPORT "turingforge-targets" ...) includes target "turingforge" which requires target "fast_float" that is not in any export set.
CMake Error in src/CMakeLists.txt:
export called with target "turingforge" which requires target
"unordered_dense" that is not in any export set.
CMake Error in src/CMakeLists.txt:
export called with target "turingforge" which requires target "xxhash" that
is not in any export set.
CMake Error in src/CMakeLists.txt:
export called with target "turingforge" which requires target "fast_float"
that is not in any export set.
I have no idea what to do about `unordered_dense` since its own `CMake` files have no option about EXPORTING/INSTALLING, but for `fast_float` and `xxhash` I did set the relevant variables as seen in the code above. They make zero difference though and the errors still persist.
Apart from that, I am not sure how to using something like `FetchContent` to pull a codebase that has no `CMake` support like `vectorclass`.
Lastly, after getting away with my old simpler `CMake` file in favour of this one, I can't include anything in my source files. Even things like complain that the "file was not found", but also including things from my own header files with `myproject/core/somefile.hpp` that used to work, not does not any longer.
That's a lot of errors in one single file, but any hints are appreciated.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|