Skip to content

Commit

Permalink
quote cmake variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan-rsm-McKenzie committed Jul 31, 2021
1 parent 36dda2c commit 07b67f6
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 106 deletions.
15 changes: 7 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.21)

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang|GNU")
set(CMAKE_CXX_EXTENSIONS OFF)
endif()

Expand All @@ -12,29 +12,28 @@ project(
LANGUAGES CXX
)

if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
if("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
message(FATAL_ERROR "in-source builds are not allowed")
endif()

option(BSA_BUILD_SRC "whether we should build the library itself" ON)
if(BSA_BUILD_SRC)
if("${BSA_BUILD_SRC}")
add_subdirectory(src)
endif()

option(BSA_BUILD_EXAMPLES "whether we should build the examples" OFF)
if(BSA_BUILD_EXAMPLES)
if("${BSA_BUILD_EXAMPLES}")
add_subdirectory(examples)
endif()

include(CTest)
if(BUILD_TESTING)
if("${BUILD_TESTING}")
find_package(Catch2 REQUIRED CONFIG)
include(Catch)

add_subdirectory(tests)
endif()

option(BSA_BUILD_DOCS "whether we should build documentation" OFF)
if(BSA_BUILD_DOCS)
if("${BSA_BUILD_DOCS}")
add_subdirectory(docs)
endif()
50 changes: 25 additions & 25 deletions cmake/FindLZ4.cmake
Original file line number Diff line number Diff line change
@@ -1,87 +1,87 @@
set(TARGET LZ4)

find_package(PkgConfig QUIET MODULE)
if(PkgConfig_FOUND)
pkg_check_modules(PC_${TARGET} QUIET liblz4)
if("${PkgConfig_FOUND}")
pkg_check_modules("PC_${TARGET}" QUIET liblz4)
endif()

find_path(${TARGET}_INCLUDE_DIR
find_path("${TARGET}_INCLUDE_DIR"
NAMES
"lz4.h"
"lz4frame.h"
"lz4hc.h"
PATHS ${PC_${TARGET}_INCLUDE_DIRS}
PATH_SUFFIXES ${TARGET}
PATH_SUFFIXES "${TARGET}"
)

find_library(${TARGET}_LIBRARY_RELEASE
find_library("${TARGET}_LIBRARY_RELEASE"
NAMES "lz4"
PATHS ${PC_${TARGET}_LIBRARY_DIRS}
)
find_library(${TARGET}_LIBRARY_DEBUG
find_library("${TARGET}_LIBRARY_DEBUG"
NAMES "lz4d"
PATHS ${PC_${TARGET}_LIBRARY_DIRS}
)

include(SelectLibraryConfigurations)
select_library_configurations(${TARGET})
select_library_configurations("${TARGET}")

set(${TARGET}_VERSION ${PC_${TARGET}_VERSION})
set("${TARGET}_VERSION" "${PC_${TARGET}_VERSION}")

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(${TARGET}
FOUND_VAR ${TARGET}_FOUND
find_package_handle_standard_args("${TARGET}"
FOUND_VAR "${TARGET}_FOUND"
REQUIRED_VARS
${TARGET}_LIBRARY
${TARGET}_INCLUDE_DIR
VERSION_VAR ${TARGET}_VERSION
"${TARGET}_LIBRARY"
"${TARGET}_INCLUDE_DIR"
VERSION_VAR "${TARGET}_VERSION"
)

if(${TARGET}_FOUND)
set(${TARGET}_LIBRARIES ${${TARGET}_LIBRARY})
set(${TARGET}_INCLUDE_DIRS ${${TARGET}_INCLUDE_DIR})
set(${TARGET}_DEFINITIONS ${PC_${TARGET}_CFLAGS_OTHER})
if("${${TARGET}_FOUND}")
set("${TARGET}_LIBRARIES" ${${TARGET}_LIBRARY})
set("${TARGET}_INCLUDE_DIRS" ${${TARGET}_INCLUDE_DIR})
set("${TARGET}_DEFINITIONS" ${PC_${TARGET}_CFLAGS_OTHER})

if(NOT TARGET ${TARGET}::${TARGET})
add_library(${TARGET}::${TARGET} UNKNOWN IMPORTED)
if(NOT TARGET "${TARGET}::${TARGET}")
add_library("${TARGET}::${TARGET}" UNKNOWN IMPORTED)
endif()

if(${TARGET}_LIBRARY_RELEASE)
set_property(
TARGET ${TARGET}::${TARGET}
TARGET "${TARGET}::${TARGET}"
APPEND
PROPERTY IMPORTED_CONFIGURATIONS RELEASE
)
set_target_properties(
${TARGET}::${TARGET}
"${TARGET}::${TARGET}"
PROPERTIES
IMPORTED_LOCATION_RELEASE "${${TARGET}_LIBRARY_RELEASE}"
)
endif()

if(${TARGET}_LIBRARY_DEBUG)
set_property(
TARGET ${TARGET}::${TARGET}
TARGET "${TARGET}::${TARGET}"
APPEND
PROPERTY IMPORTED_CONFIGURATIONS DEBUG
)
set_target_properties(
${TARGET}::${TARGET}
"${TARGET}::${TARGET}"
PROPERTIES
IMPORTED_LOCATION_DEBUG "${${TARGET}_LIBRARY_DEBUG}"
)
endif()

if(NOT ${TARGET}_LIBRARY_RELEASE AND NOT ${TARGET}_LIBRARY_DEBUG)
set_property(
TARGET ${TARGET}::${TARGET}
TARGET "${TARGET}::${TARGET}"
APPEND
PROPERTY IMPORTED_LOCATION "${${TARGET}_LIBRARY}"
)
endif()

set_target_properties(
${TARGET}::${TARGET}
"${TARGET}::${TARGET}"
PROPERTIES
INTERFACE_COMPILE_OPTIONS "${${TARGET}_DEFINITIONS}"
INTERFACE_INCLUDE_DIRECTORIES "${${TARGET}_INCLUDE_DIRS}"
Expand Down
14 changes: 7 additions & 7 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
set(ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")

find_program(POXY_PATH "poxy")

if(POXY_PATH)
set(DOCS_DIR ${ROOT_DIR}/docs)
set(INCLUDE_DIR ${ROOT_DIR}/include)
set(DOCS_DIR "${ROOT_DIR}/docs")
set(INCLUDE_DIR "${ROOT_DIR}/include")

configure_file(
${DOCS_DIR}/poxy.toml.in
${CMAKE_CURRENT_BINARY_DIR}/poxy.toml
"${DOCS_DIR}/poxy.toml.in"
"${CMAKE_CURRENT_BINARY_DIR}/poxy.toml"
@ONLY
)

add_custom_target(
docs
COMMAND
${POXY_PATH}
"${POXY_PATH}"
"${CMAKE_CURRENT_BINARY_DIR}/poxy.toml"
"--mcss" "${ROOT_DIR}/external/m.css"
VERBATIM
SOURCES
${DOCS_DIR}/poxy.toml.in
"${DOCS_DIR}/poxy.toml.in"
)
else()
message(WARNING "failed to find poxy: docs will not be built")
Expand Down
8 changes: 4 additions & 4 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_library(examples INTERFACE)
add_library(bsa::examples ALIAS examples)
add_library("${PROJECT_NAME}::examples" ALIAS examples)

macro(add_example NAME)
add_executable("example_${NAME}" "${NAME}.cpp")
Expand All @@ -8,14 +8,14 @@ macro(add_example NAME)
set_target_properties(
"example_${NAME}"
PROPERTIES
OUTPUT_NAME ${NAME}
OUTPUT_NAME "${NAME}"
)

target_link_libraries(
"example_${NAME}"
PRIVATE
bsa::bsa
bsa::examples
"${PROJECT_NAME}::${PROJECT_NAME}"
"${PROJECT_NAME}::examples"
)
endmacro()

Expand Down
90 changes: 45 additions & 45 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@
set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
set(ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")

set(INCLUDE_DIR ${ROOT_DIR}/include)
set(INCLUDE_DIR "${ROOT_DIR}/include")
set(HEADER_FILES
${INCLUDE_DIR}/bsa/detail/common.hpp
${INCLUDE_DIR}/bsa/bsa.hpp
${INCLUDE_DIR}/bsa/fo4.hpp
${INCLUDE_DIR}/bsa/fwd.hpp
${INCLUDE_DIR}/bsa/tes3.hpp
${INCLUDE_DIR}/bsa/tes4.hpp
"${INCLUDE_DIR}/bsa/detail/common.hpp"
"${INCLUDE_DIR}/bsa/bsa.hpp"
"${INCLUDE_DIR}/bsa/fo4.hpp"
"${INCLUDE_DIR}/bsa/fwd.hpp"
"${INCLUDE_DIR}/bsa/tes3.hpp"
"${INCLUDE_DIR}/bsa/tes4.hpp"
)

set(SOURCE_DIR ${ROOT_DIR}/src)
set(SOURCE_DIR "${ROOT_DIR}/src")
set(SOURCE_FILES
${SOURCE_DIR}/bsa/detail/common.cpp
${SOURCE_DIR}/bsa/fo4.cpp
${SOURCE_DIR}/bsa/tes3.cpp
${SOURCE_DIR}/bsa/tes4.cpp
"${SOURCE_DIR}/bsa/detail/common.cpp"
"${SOURCE_DIR}/bsa/fo4.cpp"
"${SOURCE_DIR}/bsa/tes3.cpp"
"${SOURCE_DIR}/bsa/tes4.cpp"
)

set(NATVIS_DIR ${ROOT_DIR}/visualizers)
set(NATVIS_DIR "${ROOT_DIR}/visualizers")
set(NATVIS_FILES
${NATVIS_DIR}/bsa_common.natvis
${NATVIS_DIR}/bsa_fo4.natvis
${NATVIS_DIR}/bsa_tes3.natvis
${NATVIS_DIR}/bsa_tes4.natvis
"${NATVIS_DIR}/bsa_common.natvis"
"${NATVIS_DIR}/bsa_fo4.natvis"
"${NATVIS_DIR}/bsa_tes3.natvis"
"${NATVIS_DIR}/bsa_tes4.natvis"
)

source_group(
TREE ${ROOT_DIR}
TREE "${ROOT_DIR}"
FILES
${HEADER_FILES}
${SOURCE_FILES}
${NATVIS_FILES}
)

add_library(
${PROJECT_NAME}
"${PROJECT_NAME}"
STATIC
${HEADER_FILES}
${SOURCE_FILES}
${NATVIS_FILES}
${ROOT_DIR}/.clang-format
${ROOT_DIR}/.editorconfig
"${ROOT_DIR}/.clang-format"
"${ROOT_DIR}/.editorconfig"
)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
add_library("${PROJECT_NAME}::${PROJECT_NAME}" ALIAS "${PROJECT_NAME}")

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

set_target_properties(
${PROJECT_NAME}
"${PROJECT_NAME}"
PROPERTIES
DEBUG_POSTFIX "d"
)

target_compile_features(
${PROJECT_NAME}
"${PROJECT_NAME}"
PUBLIC
cxx_std_20
)

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang|GNU")
target_compile_options(
${PROJECT_NAME}
"${PROJECT_NAME}"
PRIVATE
"-fvisibility=hidden"
)
endif()

target_include_directories(
${PROJECT_NAME}
"${PROJECT_NAME}"
PUBLIC
"$<BUILD_INTERFACE:${INCLUDE_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
PRIVATE
${SOURCE_DIR}
"${SOURCE_DIR}"
)

list(APPEND CMAKE_MODULE_PATH "${ROOT_DIR}/cmake")
Expand All @@ -83,48 +83,48 @@ find_package(LZ4 MODULE REQUIRED)
find_package(ZLIB MODULE REQUIRED)

target_link_libraries(
${PROJECT_NAME}
"${PROJECT_NAME}"
PRIVATE
LZ4::LZ4
ZLIB::ZLIB
)

install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
TARGETS "${PROJECT_NAME}"
EXPORT "${PROJECT_NAME}-targets"
)

install(
EXPORT ${PROJECT_NAME}-targets
NAMESPACE bsa::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
EXPORT "${PROJECT_NAME}-targets"
NAMESPACE "${PROJECT_NAME}::"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

configure_file(
${ROOT_DIR}/cmake/config.cmake.in
${PROJECT_NAME}Config.cmake
"${ROOT_DIR}/cmake/config.cmake.in"
"${PROJECT_NAME}Config.cmake"
@ONLY
)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
)

install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
${ROOT_DIR}/cmake/FindLZ4.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
"${ROOT_DIR}/cmake/FindLZ4.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

install(
DIRECTORY ${INCLUDE_DIR}/bsa
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
DIRECTORY "${INCLUDE_DIR}/bsa"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)

install(
FILES ${NATVIS_FILES}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}"
)
Loading

0 comments on commit 07b67f6

Please sign in to comment.