mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-09 23:34:23 +00:00
CMake enhancements
* Add magic_enum as an interface library * Enable tests and examples only if is top project * Use more modern approach to include directories * Add install target
This commit is contained in:
parent
20568660dd
commit
e10ba181f1
4 changed files with 47 additions and 11 deletions
|
|
@ -2,14 +2,27 @@
|
|||
|
||||
project(magic_enum VERSION "0.4.2" LANGUAGES CXX)
|
||||
|
||||
option(MAGIC_ENUM_OPT_BUILD_EXAMPLES "Build magic_enum examples" ON)
|
||||
option(MAGIC_ENUM_OPT_BUILD_TESTS "Build and perform magic_enum tests" ON)
|
||||
add_library(${PROJECT_NAME} INTERFACE)
|
||||
target_include_directories(${PROJECT_NAME} INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>)
|
||||
|
||||
if(MAGIC_ENUM_OPT_BUILD_EXAMPLES)
|
||||
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||
set(IS_TOPLEVEL_PROJECT TRUE)
|
||||
else ()
|
||||
set(IS_TOPLEVEL_PROJECT FALSE)
|
||||
endif ()
|
||||
|
||||
option(MAGIC_ENUM_OPT_BUILD_EXAMPLES "Build magic_enum examples" ${IS_TOPLEVEL_PROJECT})
|
||||
option(MAGIC_ENUM_OPT_BUILD_TESTS "Build and perform magic_enum tests" ${IS_TOPLEVEL_PROJECT})
|
||||
|
||||
if (MAGIC_ENUM_OPT_BUILD_EXAMPLES)
|
||||
add_subdirectory(example)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
if(MAGIC_ENUM_OPT_BUILD_TESTS)
|
||||
if (MAGIC_ENUM_OPT_BUILD_TESTS)
|
||||
enable_testing()
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
include(install.cmake)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
include(CheckCXXCompilerFlag)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include)
|
||||
|
||||
set(OPTIONS "")
|
||||
|
||||
if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
||||
|
|
@ -21,3 +19,4 @@ add_executable(example
|
|||
example.cpp
|
||||
${CMAKE_SOURCE_DIR}/include/magic_enum.hpp)
|
||||
target_compile_options(example PRIVATE ${OPTIONS})
|
||||
target_link_libraries(example PRIVATE magic_enum)
|
||||
|
|
|
|||
25
install.cmake
Normal file
25
install.cmake
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
include(CMakePackageConfigHelpers)
|
||||
write_basic_package_version_file(
|
||||
${PROJECT_NAME}ConfigVersion.cmake
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
EXPORT ${PROJECT_NAME}Targets
|
||||
PUBLIC_HEADER DESTINATION include
|
||||
INCLUDES DESTINATION include
|
||||
)
|
||||
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||
DESTINATION lib/cmake/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
install(EXPORT ${PROJECT_NAME}Targets
|
||||
NAMESPACE ${PROJECT_NAME}::
|
||||
DESTINATION lib/cmake/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
DESTINATION include
|
||||
)
|
||||
|
|
@ -1,8 +1,5 @@
|
|||
include(CheckCXXCompilerFlag)
|
||||
|
||||
include_directories(3rdparty/Catch2)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include)
|
||||
|
||||
set(SOURCES test.cpp)
|
||||
|
||||
set(OPTIONS "")
|
||||
|
|
@ -28,6 +25,8 @@ endif()
|
|||
function(make_target target std)
|
||||
add_executable(${target} ${SOURCES})
|
||||
target_compile_options(${target} PRIVATE ${OPTIONS})
|
||||
target_include_directories(${target} PRIVATE 3rdparty/Catch2)
|
||||
target_link_libraries(${target} PRIVATE magic_enum)
|
||||
if(std)
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
target_compile_options(${target} PRIVATE /std:${std})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue