Skip to content

Commit 768b5bf

Browse files
authored
add cmake install target (#22)
1 parent d3e2815 commit 768b5bf

File tree

5 files changed

+75
-47
lines changed

5 files changed

+75
-47
lines changed

.github/workflows/cmake.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Configure CMake
2525
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
2626
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
27-
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
27+
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DVALVEFILEVDF_ENABLE_TESTING=ON -DVALVEFILEVDF_ENABLE_FUZZING=ON
2828

2929
- name: Build
3030
# Build your program with the given configuration

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
build/
21
.vs/
32
.vscode/
3+
install/
4+
build/
45
out/
6+
Testing/

CMakeLists.txt

+65-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,75 @@
1-
cmake_minimum_required (VERSION 3.6)
2-
project (vdf-Parser)
1+
cmake_minimum_required (VERSION 3.23)
2+
3+
project(
4+
ValveFileVDF
5+
VERSION 1.0.0
6+
DESCRIPTION "parses valve's vdf file format"
7+
HOMEPAGE_URL "https://github.com/TinyTinni/ValveFileVDF"
8+
LANGUAGES CXX C)
9+
10+
option(VALVEFILEVDF_ENABLE_TESTING OFF)
11+
option(VALVEFILEVDF_ENABLE_FUZZING OFF)
12+
13+
if (VALVEFILEVDF_ENABLE_FUZZING)
14+
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC" AND NOT APPLE)
15+
set(VALVEFILEVDF_ENABLE_FUZZING ON)
16+
else()
17+
set(VALVEFILEVDF_ENABLE_FUZZING OFF)
18+
message("Fuzzing not supported. Fuzzing gets disabled.")
19+
endif()
20+
endif()
321

422
add_library(ValveFileVDF INTERFACE)
523
add_library(ValveFileVDF::ValveFileVDF ALIAS ValveFileVDF)
6-
target_include_directories(ValveFileVDF INTERFACE "include")
24+
target_sources(ValveFileVDF
25+
PUBLIC FILE_SET HEADERS
26+
BASE_DIRS "include"
27+
FILES
28+
"include/vdf_parser.hpp"
29+
)
730

8-
include(CTest)
9-
add_subdirectory(./tests)
31+
#############################
32+
## Install
33+
34+
set_target_properties(ValveFileVDF PROPERTIES PUBLIC_HEADER "include/vdf_parser.hpp")
35+
36+
include(GNUInstallDirs)
37+
install(TARGETS ValveFileVDF
38+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
39+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
40+
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
41+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
42+
)
1043

11-
## add fuzzing, if supported
44+
include(CMakePackageConfigHelpers)
1245

13-
set(ENABLE_FUZZING OFF)
14-
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC" AND NOT APPLE)
15-
set(ENABLE_FUZZING ON)
46+
47+
write_basic_package_version_file(
48+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
49+
VERSION ${PROJECT_VERSION}
50+
COMPATIBILITY SameMajorVersion
51+
)
52+
53+
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
54+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
55+
INSTALL_DESTINATION cmake
56+
)
57+
58+
install(FILES
59+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
60+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
61+
DESTINATION cmake
62+
)
63+
64+
65+
###################################
66+
# Tests
67+
include(CTest)
68+
if (${VALVEFILEVDF_ENABLE_TESTING})
69+
add_subdirectory(./tests)
1670
endif()
1771

18-
if (${ENABLE_FUZZING})
72+
73+
if (${VALVEFILEVDF_ENABLE_FUZZING})
1974
add_subdirectory(fuzzing)
2075
endif()

Config.cmake.in

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@PACKAGE_INIT@
2+
3+
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
4+
5+
check_required_components(@PROJECT_NAME@)

tests/CMakeLists.txt

+1-35
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,3 @@
1-
set (CMAKE_CXX_STANDARD 17)
2-
3-
##find_package(Catch2 QUIET)
4-
##if (NOT TARGET Catch2::Catch)
5-
## include(ExternalProject)
6-
## find_package(Git REQUIRED)
7-
##
8-
## set(BRANCH "master")
9-
## if (MSVC_VERSION LESS 1900)
10-
## set(BRANCH "Catch1.x") #catch2 needs C++11
11-
## endif()
12-
##
13-
## ExternalProject_Add(
14-
## catch
15-
## PREFIX ${CMAKE_BINARY_DIR}/catch
16-
## GIT_REPOSITORY https://github.com/philsquared/Catch.git
17-
## GIT_TAG ${BRANCH}
18-
## TIMEOUT 10
19-
## UPDATE_COMMAND ${GIT_EXECUTABLE} pull
20-
## CONFIGURE_COMMAND ""
21-
## BUILD_COMMAND ""
22-
## INSTALL_COMMAND ""
23-
## LOG_DOWNLOAD ON
24-
## )
25-
## ExternalProject_Get_Property(catch source_dir)
26-
##
27-
## add_library(Catch INTERFACE)
28-
## set(INCLUDE_POSTFIX "catch2/")
29-
## if (MSVC_VERSION LESS 1900)
30-
## set(INCLUDE_POSTFIX "")
31-
## endif()
32-
## target_include_directories(Catch INTERFACE "${source_dir}/single_include/${INCLUDE_POSTFIX}")
33-
## add_dependencies(Catch catch)
34-
## add_library(Catch2::Catch ALIAS Catch)
35-
##endif()
361

372
set(SRCS
383
"main.cpp"
@@ -45,6 +10,7 @@ set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT t
4510
set_property(TARGET tests PROPERTY COMPILE_WARNING_AS_ERROR ON)
4611
add_definitions("-DSOURCE_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"" "-DCATCH_AMALGAMATED_CUSTOM_MAIN")
4712
target_compile_definitions(tests PRIVATE "-D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS" "-D_LIBCPP_DISABLE_DEPRECATION_WARNINGS")
13+
target_compile_features(tests PUBLIC cxx_std_17)
4814
target_link_libraries(tests PRIVATE ValveFileVDF)
4915

5016
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")

0 commit comments

Comments
 (0)