Skip to content

Commit

Permalink
Modernize cmake
Browse files Browse the repository at this point in the history
* Able to use as subfolder
* Able to install (and import again in cmake)
* Able to disable tests
* Able to disable samples
  • Loading branch information
Erroneous1 committed Aug 2, 2018
1 parent 1537543 commit 3866386
Showing 1 changed file with 39 additions and 10 deletions.
49 changes: 39 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
cmake_minimum_required (VERSION 2.8.0)
project (utf8cpp)
include_directories ("${PROJECT_SOURCE_DIR}/source")
cmake_minimum_required (VERSION 3.0.2)
project (utf8cpp VERSION 2.3.5 LANGUAGES CXX)

add_executable(smoke ${PROJECT_SOURCE_DIR}/test_drivers/smoke_test/test.cpp)
add_executable(negative ${PROJECT_SOURCE_DIR}/test_drivers/negative/negative.cpp)
add_executable(utf8reader ${PROJECT_SOURCE_DIR}/test_drivers/utf8reader/utf8reader.cpp)
option(UTF8_TESTS "Enable tests for UTF8-CPP" On)
option(UTF8_SAMPLES "Enable building samples for UTF8-CPP" On)

add_executable(docsample ${PROJECT_SOURCE_DIR}/samples/docsample.cpp)
add_library(utf8cpp INTERFACE)
target_include_directories(utf8cpp INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/source>"
$<INSTALL_INTERFACE:include/utf8cpp>
)
add_library(utf8::cpp ALIAS utf8cpp)

enable_testing()
add_test(smoke_test smoke)
add_test(negative_test negative ${PROJECT_SOURCE_DIR}/test_data/negative/utf8_invalid.txt)
if(WIN32 AND NOT CYGWIN)
set(DEF_INSTALL_CMAKE_DIR CMake)
else()
set(DEF_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/utf8cpp)
endif()

install(DIRECTORY source/ DESTINATION include/utf8cpp)
install(TARGETS utf8cpp EXPORT utf8cppConfig)
install(EXPORT utf8cppConfig DESTINATION ${DEF_INSTALL_CMAKE_DIR})

if(UTF8_SAMPLES)
add_executable(utf8reader ${PROJECT_SOURCE_DIR}/test_drivers/utf8reader/utf8reader.cpp)
add_executable(docsample ${PROJECT_SOURCE_DIR}/samples/docsample.cpp)

target_link_libraries(utf8reader PRIVATE utf8::cpp)
target_link_libraries(docsample PRIVATE utf8::cpp)
endif()

if(UTF8_TESTS)
add_executable(smoke ${PROJECT_SOURCE_DIR}/test_drivers/smoke_test/test.cpp)
add_executable(negative ${PROJECT_SOURCE_DIR}/test_drivers/negative/negative.cpp)

target_link_libraries(smoke PRIVATE utf8::cpp)
target_link_libraries(negative PRIVATE utf8::cpp)

enable_testing()
add_test(smoke_test smoke)
add_test(negative_test negative ${PROJECT_SOURCE_DIR}/test_data/negative/utf8_invalid.txt)
endif()

0 comments on commit 3866386

Please sign in to comment.