Template-gint-library/CMakeLists.txt

47 lines
1.9 KiB
CMake

# libexample: build system
cmake_minimum_required(VERSION 3.16)
project(libexample VERSION 1.0 LANGUAGES C)
# Libraries that libexample depends on
find_package(Gint 2.1 REQUIRED)
# Turn include/example/config.h.in into a proper config.h where the @VAR@ have
# been replaced; this is how version numbers are maintained. libexample_VERSION
# is set to "1.0" by the project() command.
# Note that the input (config.h.in) is relative to the source dir, but the
# output (config.h) is in the build dir, so it doesn't pollute the Git repo.
configure_file(include/example/config.h.in include/example/config.h)
# Target name is "example", output file is "libexample.a" (by default)
add_library(example STATIC src/add.c src/version.c)
# Find headers in the following directories:
# -> The include subfolder of the source
# -> The include subfolder of the build files (for config.h)
# PUBLIC means that users of this library will also look here, but there are no
# users in the current project, so it doesn't matter. (The actual flags for
# library users are in FindLibExample.cmake.)
target_include_directories(example PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/include"
"${CMAKE_CURRENT_BINARY_DIR}/include")
# After building, install the target (that is, libexample.a) in the compiler
install(TARGETS example
DESTINATION "${FXSDK_COMPILER_INSTALL}")
# Also install the headers (our include folder gets merged with the existing
# one in the compiler's install folder). Only install files matching *.h to
# exclude config.h.in.
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include"
DESTINATION "${FXSDK_COMPILER_INSTALL}"
FILES_MATCHING PATTERN "*.h")
# Install config.h from the build dir
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/example/config.h"
DESTINATION "${FXSDK_COMPILER_INSTALL}/include/example")
# Install FindLibExample.cmake so that users can do find_package(LibExample)
install(FILES cmake/FindLibExample.cmake
DESTINATION "${FXSDK_CMAKE_MODULE_PATH}")