mirror of
https://github.com/tkem/fsmlite.git
synced 2025-05-09 00:02:52 +08:00
Add CMake support
This commit is contained in:
parent
417c348f22
commit
0d6b217cd3
37
CMakeLists.txt
Normal file
37
CMakeLists.txt
Normal file
@ -0,0 +1,37 @@
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
|
||||
project(
|
||||
fsmlite
|
||||
VERSION 0.7.3
|
||||
DESCRIPTION "fsmlite library"
|
||||
HOMEPAGE_URL "https://github.com/tkem/fsmlite"
|
||||
)
|
||||
|
||||
option(ENABLE_TESTS OFF "Enable test")
|
||||
|
||||
# Make sure that custom modules are found
|
||||
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake/modules)
|
||||
|
||||
# Create an INTERFACE target, ie. header only
|
||||
add_library(${PROJECT_NAME} INTERFACE)
|
||||
# Using a library defined in the same CMake tree should look the same as using an external library.
|
||||
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
INTERFACE
|
||||
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
|
||||
)
|
||||
|
||||
list(APPEND PUBLIC_HEADERS
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/fsm.h"
|
||||
)
|
||||
|
||||
if(ENABLE_TESTS)
|
||||
enable_testing()
|
||||
include(CTest)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
# Add install options
|
||||
include(Install)
|
69
SUPPORT.md
Normal file
69
SUPPORT.md
Normal file
@ -0,0 +1,69 @@
|
||||
# Building
|
||||
|
||||
## Using autotools/Make
|
||||
TBD
|
||||
|
||||
## Using CMake
|
||||
CMake is a cross platform build configuration tool.
|
||||
|
||||
### Configuring
|
||||
To build, you need to first configure for your target platform, be it MSVC, Unix Makefiles, Ninja etc.
|
||||
|
||||
First create a build directory
|
||||
```
|
||||
mkdir build && cd build
|
||||
```
|
||||
|
||||
#### Windows:
|
||||
|
||||
You have different generators depending on your environment. Here we use Visual Studio 2019:
|
||||
```
|
||||
cmake -G "Visual Studio 16 2019" ..
|
||||
```
|
||||
|
||||
#### Linux:
|
||||
On Linux, the default generator is often Unix Makefiles:
|
||||
|
||||
```
|
||||
cmake ..
|
||||
```
|
||||
|
||||
#### Cross-compile using toolchain
|
||||
To cross compile, use a toolchain.
|
||||
|
||||
Example
|
||||
```
|
||||
cmake -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchains/arm-none-eabi.cmake" ..
|
||||
```
|
||||
|
||||
### Building
|
||||
|
||||
```
|
||||
cmake --build .
|
||||
```
|
||||
|
||||
### Installing
|
||||
|
||||
System wide:
|
||||
```
|
||||
cmake --build . --target install
|
||||
```
|
||||
|
||||
Local:
|
||||
```
|
||||
cmake -DCMAKE_INSTALL_PREFIX=install_path ..
|
||||
&& cmake --build . --target install
|
||||
```
|
||||
|
||||
### Testing
|
||||
|
||||
Configure for testing
|
||||
```
|
||||
cmake -DENABLE_TESTS=ON ..
|
||||
```
|
||||
|
||||
If you can run the resulting test binary on the host:
|
||||
```
|
||||
ctest -C Debug|Release
|
||||
```
|
||||
|
6
cmake/fsmliteConfig.cmake.in
Normal file
6
cmake/fsmliteConfig.cmake.in
Normal file
@ -0,0 +1,6 @@
|
||||
get_filename_component(fsmlite_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||
include(CMakeFindDependencyMacro)
|
||||
|
||||
if(NOT TARGET fsmlite::fsmlite)
|
||||
include("${fsmlite_CMAKE_DIR}/fsmliteTargets.cmake")
|
||||
endif()
|
56
cmake/modules/Install.cmake
Normal file
56
cmake/modules/Install.cmake
Normal file
@ -0,0 +1,56 @@
|
||||
# Install
|
||||
if(NOT CMAKE_INSTALL_BINDIR)
|
||||
include(GNUInstallDirs)
|
||||
endif()
|
||||
|
||||
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
|
||||
|
||||
# Install public headers
|
||||
install(
|
||||
FILES ${PUBLIC_HEADERS}
|
||||
DESTINATION "include/${PROJECT_NAME}"
|
||||
)
|
||||
|
||||
# Specify binary destinations for the targets
|
||||
install(
|
||||
TARGETS ${PROJECT_NAME}
|
||||
EXPORT ${PROJECT_NAME}-targets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} # This is for Windows
|
||||
)
|
||||
|
||||
# Export the targets to a script
|
||||
install(
|
||||
EXPORT ${PROJECT_NAME}-targets
|
||||
FILE ${PROJECT_NAME}Targets.cmake
|
||||
NAMESPACE ${PROJECT_NAME}::
|
||||
DESTINATION ${INSTALL_CONFIGDIR}
|
||||
)
|
||||
|
||||
# Create a ConfigVersion.cmake file
|
||||
include(CMakePackageConfigHelpers)
|
||||
write_basic_package_version_file(
|
||||
${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
|
||||
configure_package_config_file(
|
||||
${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
|
||||
${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake INSTALL_DESTINATION
|
||||
${INSTALL_CONFIGDIR}
|
||||
)
|
||||
|
||||
# Install the config, configversion and custom find modules
|
||||
install(
|
||||
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||
DESTINATION ${INSTALL_CONFIGDIR}
|
||||
)
|
||||
|
||||
export(
|
||||
EXPORT ${PROJECT_NAME}-targets
|
||||
FILE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake
|
||||
NAMESPACE ${PROJECT_NAME}::
|
||||
)
|
15
cmake/toolchains/arm-none-eabi.cmake
Normal file
15
cmake/toolchains/arm-none-eabi.cmake
Normal file
@ -0,0 +1,15 @@
|
||||
set(CMAKE_SYSTEM_NAME Generic)
|
||||
set(CMAKE_SYSTEM_PROCESSOR arm)
|
||||
|
||||
set(CMAKE_C_COMPILER "arm-none-eabi-gcc")
|
||||
set(CMAKE_CXX_COMPILER "arm-none-eabi-g++")
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||
|
||||
|
||||
# Generic toolchain, no syscalls
|
||||
set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs" CACHE INTERNAL "")
|
||||
set(CMAKE_CXX_FLAGS "-march=armv7-a")
|
37
tests/CMakeLists.txt
Normal file
37
tests/CMakeLists.txt
Normal file
@ -0,0 +1,37 @@
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
|
||||
project(
|
||||
fsmlite_tests
|
||||
DESCRIPTION "Test application for fsmlite"
|
||||
)
|
||||
|
||||
list(APPEND tests
|
||||
test_basic_row
|
||||
test_mem_fn_row
|
||||
test_notrans
|
||||
test_player
|
||||
test_recursive
|
||||
test_row
|
||||
test_scoped
|
||||
test_shared
|
||||
test_traits
|
||||
)
|
||||
|
||||
macro(add_fsmlite_test NAME)
|
||||
add_executable(${NAME} ${CMAKE_CURRENT_SOURCE_DIR}/${NAME}.cpp)
|
||||
target_link_libraries(${NAME}
|
||||
PRIVATE
|
||||
fsmlite::fsmlite
|
||||
)
|
||||
if (MSVC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.14)
|
||||
target_compile_options(${NAME}
|
||||
PRIVATE
|
||||
/Zc:__cplusplus
|
||||
)
|
||||
endif()
|
||||
add_test(NAME ${PROJECT_NAME}_${NAME} COMMAND ${NAME})
|
||||
endmacro(add_fsmlite_test)
|
||||
|
||||
foreach(test ${tests})
|
||||
add_fsmlite_test(${test})
|
||||
endforeach()
|
Loading…
x
Reference in New Issue
Block a user