I have a project with the following architecture:
. ├── CMakeLists.txt ├── include │ └── Core │ ├── FiniteStateMachine.h │ └── IFiniteStateMachine.h ├── source │ └── Core │ └── FiniteStateMachine.cpp └── tests ├── Core │ └── FiniteStateMachine_tests.cpp └── main_tests.cpp To compile in CLion, I wrote the file CMakeLists.txt, but the file turned out to be super crooked.
cmake_minimum_required(VERSION 3.8) get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) project(${PROJECT_NAME} CXX) if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include) list(APPEND PATH_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/include) FILE(GLOB_RECURSE HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*) endif() FILE(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/source/*) include_directories(${PATH_INCLUDES}) add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS}) project(${PROJECT_NAME}_test CXX) if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include) list(APPEND PATH_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/include) FILE(GLOB_RECURSE TEST_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*) endif() FILE(GLOB_RECURSE TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/source/* ${CMAKE_CURRENT_SOURCE_DIR}/tests/*) add_executable(${PROJECT_NAME} ${TEST_SOURCES} ${TEST_HEADRES}) target_link_libraries(${PROJECT_NAME} gtest gmock pthread) Immediately make a reservation that I had no business with CMake before, but I was apparently banned in Google, please do not scold too much!)
Can anyone share their experience as with such an architecture of a project should CMake be used?
For testing, I use GTest (gmock), it is desirable that these libraries are not downloaded from GitHub, but located on the user's computer.
Also, for the future, I would like to be able to exclude some files from certain assemblies (let's say for testing) (also for an example: main.cpp (when building a binary, not a library)) because they can initialize objects that need " to lock "in the case of testing (roughly speaking various singletons, etc.)
Thanks a lot in advance!