Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include missing GNUInstallDirs #105

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
25 changes: 15 additions & 10 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ tasks:
- cmake --build ./test/build --config Release
- cd ./test/build && ctest -C Release --verbose

test_install:
install_release:
cmds:
- task: test_release
- cmake --install ./test/build --config Release --prefix ./install
- task: clean
Copy link
Owner

@aminya aminya Mar 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why clean after installation?

Copy link
Contributor Author

@ClausKlein ClausKlein Mar 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had tests in past, that used libs or header from build directory and not from installed prefix .
This guaranties that nothing is used from build dir after install.
In our case, with code coverage compile options, the installed library contents use the build dir while running test_install project!
That was there reason why I disabled some options.


test_install:
cmds:
- task: install_release
- cmake ./test_install -B ./test_install/build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' -DCMAKE_PREFIX_PATH:STRING={{.CWD}}/install;
- cmake --build ./test_install/build --config Release
- cd ./test_install/build && ctest -C Release --verbose
Expand All @@ -25,13 +30,13 @@ tasks:

lint:
- |
{{if eq OS "windows"}}
powershell -c '$files=(git ls-files --exclude-standard); foreach ($file in $files) { if ((get-item $file).Extension -in ".cpp", ".hpp", ".c", ".cc", ".cxx", ".hxx", ".ixx") { clang-format -i -style=file $file } }'
{{else}}
git ls-files --exclude-standard | grep -E '\.(cpp|hpp|c|cc|cxx|hxx|ixx)$' | xargs clang-format -i -style=file
{{if eq OS "windows"}}
powershell -c '$files=(git ls-files --exclude-standard); foreach ($file in $files) { if ((get-item $file).Extension -in ".cpp", ".hpp", ".c", ".cc", ".cxx", ".hxx", ".ixx") { clang-format -i -style=file $file } }'
{{else}}
git ls-files --exclude-standard | grep -E '\.(cpp|hpp|c|cc|cxx|hxx|ixx)$' | xargs clang-format -i -style=file
{{end}}
- |
{{if eq OS "windows"}}
{{if eq OS "windows"}}
powershell -c '$files=(git ls-files --exclude-standard); foreach ($file in $files) { $item=(get-item $file); if (($item.Name -eq "CMakeLists.txt") -or ($item.Extension -in ".cmake")) { cmake-format --in-place $file; cmake-lint $file --disabled-codes C0103 C0301 R0912 R0915 R0913 --suppress-decorations } }'
{{else}}
git ls-files --exclude-standard | grep -E '(CMakeLists\.txt)|(\.(cmake))$' | xargs cmake-format --in-place | xargs cmake-lint --disabled-codes C0103 C0301 R0912 R0915 R0913 --suppress-decorations
Expand All @@ -41,8 +46,8 @@ tasks:
- npx -y cspell lint --no-progress --show-suggestions

clean: |
{{if eq OS "windows"}}
powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./test/build; rmrf ./test_install/build/; rmrf ./install'
{{else}}
rm -rf ./test/build ./test_install/build/ ./install
{{if eq OS "windows"}}
powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./test/build; rmrf ./test_install/build'
{{else}}
rm -rf ./test/build ./test_install/build
{{end}}
37 changes: 21 additions & 16 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16...3.21)
cmake_minimum_required(VERSION 3.16...3.23)

# set a default CXX standard used by the external tools like clang-tidy, cppcheck, etc.
# You can later set fine-grained standards for each target using `target_compile_features`
Expand Down Expand Up @@ -35,13 +35,12 @@ project_options(
ENABLE_CPPCHECK
ENABLE_CLANG_TIDY
# ENABLE_INCLUDE_WHAT_YOU_USE
ENABLE_COVERAGE
ENABLE_PCH
PCH_HEADERS
${PCH_HEADERS}
ENABLE_DOXYGEN
ENABLE_INTERPROCEDURAL_OPTIMIZATION
ENABLE_NATIVE_OPTIMIZATION
# TODO(CK: should not installed with this option!) ENABLE_COVERAGE
# TBD: ENABLE_PCH
# TBD: PCH_HEADERS ${PCH_HEADERS}
# NO(CK)! To slow! ENABLE_DOXYGEN
# ENABLE_INTERPROCEDURAL_OPTIMIZATION
# ENABLE_NATIVE_OPTIMIZATION
# ENABLE_USER_LINKER
# ENABLE_BUILD_WITH_TIME_TRACE
# ENABLE_UNITY
Expand Down Expand Up @@ -75,11 +74,17 @@ target_link_system_libraries(
enable_testing()
add_test(NAME main COMMAND main)

if(NOT DEFINED CMAKE_INSTALL_INCLUDEDIR)
# NOTE: enable at least one language before including GNUInstallDirs.
include(GNUInstallDirs)
endif()

# Header-only library
add_library(lib INTERFACE)
set(lib_INCLUDE_DIR "include")
target_include_directories(lib INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${lib_INCLUDE_DIR}>"
"$<INSTALL_INTERFACE:./${CMAKE_INSTALL_INCLUDEDIR}>") # TODO(refactor)
ClausKlein marked this conversation as resolved.
Show resolved Hide resolved
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>") # TODO(refactor)
# FIXME(CK: This should not done for INTERFACE libs!)
target_link_libraries(lib INTERFACE project_options project_warnings)
target_link_system_libraries(
lib
Expand All @@ -89,13 +94,13 @@ target_link_system_libraries(

# Library
add_library(lib2 "./src/mylib2/lib.cpp")
set(lib2_INCLUDE_DIR2 "include")
target_include_directories(lib2 PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${lib2_INCLUDE_DIR2}>"
"$<INSTALL_INTERFACE:./${CMAKE_INSTALL_INCLUDEDIR}>") # TODO(refactor)
set(lib2_INCLUDE_DIR "include")
target_include_directories(lib2 PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${lib2_INCLUDE_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>") # TODO(refactor)
target_link_libraries(lib2 PRIVATE project_options project_warnings)
target_link_system_libraries(
lib2
PRIVATE
PUBLIC
fmt::fmt
Eigen3::Eigen)

Expand All @@ -111,9 +116,9 @@ package_project(
INTERFACE_DEPENDENCIES_CONFIGURED
${DEPENDENCIES_CONFIGURED}
INTERFACE_INCLUDES
${lib_INCLUDE_DIR2}
${lib2_INCLUDE_DIR}
PUBLIC_INCLUDES
${lib2_INCLUDE_DIR2})
${lib2_INCLUDE_DIR})

# package separately (for testing)
package_project(
Expand All @@ -136,7 +141,7 @@ package_project(
project_options
project_warnings
PUBLIC_INCLUDES
${lib2_INCLUDE_DIR22})
${lib2_INCLUDE_DIR})

package_project(
NAME
Expand Down
14 changes: 9 additions & 5 deletions test_install/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cmake_minimum_required(VERSION 3.16...3.21)
cmake_minimum_required(VERSION 3.16...3.23)

set(CMAKE_CXX_STANDARD 20)

### Add project_options
include(../src/Index.cmake)
Expand All @@ -7,7 +9,7 @@ run_vcpkg()

project(
anotherproj
VERSION 0.1.0
VERSION 0.2.0
LANGUAGES CXX C)

# Initialize project_options
Expand All @@ -21,11 +23,11 @@ project_options(
# ENABLE_COVERAGE
# ENABLE_PCH
# PCH_HEADERS <Eigen/Dense> <fmt/core.h> <vector> <utility> <string> <string_view>
ENABLE_DOXYGEN
# XXX ENABLE_DOXYGEN
DOXYGEN_THEME
"${CMAKE_CURRENT_LIST_DIR}/css/my_custom_theme.css"
"${CMAKE_CURRENT_LIST_DIR}/css/my_custom_theme_extra.css"
ENABLE_INTERPROCEDURAL_OPTIMIZATION
# ENABLE_INTERPROCEDURAL_OPTIMIZATION
# ENABLE_USER_LINKER
# ENABLE_BUILD_WITH_TIME_TRACE
# ENABLE_UNITY
Expand All @@ -38,16 +40,18 @@ project_options(

# add src, tests, etc here:
add_executable(another_main "./src/another_main.cpp")
target_link_libraries(another_main PRIVATE project_options project_warnings)
#XXX target_link_libraries(another_main PRIVATE project_options project_warnings)

## dependencies
set(DEPENDENCIES_CONFIGURED myproj)
#TODO(CK) set(DEPENDENCIES_CONFIGURED myproj_header_only_lib myproj)

foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED})
find_package(${DEPENDENCY} CONFIG REQUIRED)
endforeach()

target_link_libraries(another_main PRIVATE myproj::lib myproj::lib2)
#TODO(CK) target_link_libraries(another_main PRIVATE myproj_header_only_lib::lib myproj::lib2)

# tests
enable_testing()
Expand Down