Skip to content

Instantly share code, notes, and snippets.

@Niakr1s
Created March 16, 2019 19:25
Show Gist options
  • Save Niakr1s/37cce0ee7740b9ca03a37a32170d0cd3 to your computer and use it in GitHub Desktop.
Save Niakr1s/37cce0ee7740b9ca03a37a32170d0cd3 to your computer and use it in GitHub Desktop.
simple CMakeLists
cmake_minimum_required(VERSION 3.0.0)
project(main VERSION 0.1.0)
enable_testing()
file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "src/*.cpp")
add_executable(main ${SOURCES})
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED on)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
# don't forget to rename libboost_unit_test_framework-mgw82-mt-x32-1_69.a to libboost_unit_test_framework
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(main ${Boost_LIBRARIES})
file(GLOB_RECURSE TESTS RELATIVE ${CMAKE_SOURCE_DIR} "tests/*.cpp")
add_executable(test_executable ${TESTS})
target_include_directories(test_executable PRIVATE ${BOOST_INCLUDE_DIRS})
target_link_libraries(test_executable ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
add_test(NAME test1 COMMAND test_executable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment