Tests only on cmake option

This commit is contained in:
Phuntsok Drak-pa 2019-03-27 15:24:45 +01:00
parent 02702874f6
commit 9192e89241
2 changed files with 27 additions and 15 deletions

View File

@ -1,13 +1,12 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project("GeneticImages" project("GeneticImages"
VERSION 0.1 VERSION 0.1
DESCRIPTION "Recreate reference images with genetic algorithms" DESCRIPTION "Recreate reference images with genetic algorithms"
HOMEPAGE_URL "https://labs.phundrak.fr/phundrak/genetic-images" HOMEPAGE_URL "https://labs.phundrak.fr/phundrak/genetic-images"
LANGUAGES CXX) LANGUAGES CXX)
file(GLOB SRC_FILES "src/*.cc") file(GLOB SRC_FILES "src/*.cc")
file(GLOB TEST_FILES "tests/tests.cc")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
@ -21,25 +20,32 @@ enable_cxx_compiler_flag_if_supported("-O3")
enable_cxx_compiler_flag_if_supported("-flto") enable_cxx_compiler_flag_if_supported("-flto")
# include_directories(<PUBLIC HEADER DIRECTORIES>) # include_directories(<PUBLIC HEADER DIRECTORIES>)
# Main software
set(TGT genetic-image) set(TGT genetic-image)
set(TESTTGT genetic-image-tests)
add_executable(${TGT} ${SRC_FILES}) add_executable(${TGT} ${SRC_FILES})
add_executable(${TESTTGT} ${TEST_FILES})
target_compile_features(${TGT} PRIVATE cxx_std_17) target_compile_features(${TGT} PRIVATE cxx_std_17)
target_compile_features(${TESTTGT} PRIVATE cxx_std_17)
target_include_directories(${TGT} PRIVATE include/genimg) target_include_directories(${TGT} PRIVATE include/genimg)
target_include_directories(${TESTTGT} PRIVATE include/genimg)
target_link_libraries(${TGT} ${CONAN_LIBS} stdc++fs) target_link_libraries(${TGT} ${CONAN_LIBS} stdc++fs)
target_link_libraries(${TESTTGT} ${CONAN_LIBS} stdc++fs)
# Tests
if(TESTS)
set(TESTTGT genetic-image-tests)
file(GLOB TEST_FILES "tests/tests.cc")
add_executable(${TESTTGT} ${TEST_FILES})
target_compile_features(${TESTTGT} PRIVATE cxx_std_17)
target_include_directories(${TESTTGT} PRIVATE include/genimg)
target_link_libraries(${TESTTGT} ${CONAN_LIBS} stdc++fs)
endif()
# OS specific instructions. # OS specific instructions.
if(APPLE) if(APPLE)
elseif(WIN32) elseif(WIN32)
# Windows developer environment specific instructions. # Windows developer environment specific instructions.
if(MINGW) if(MINGW)
elseif(MSYS) elseif(MSYS)
elseif(CYGWIN) elseif(CYGWIN)
endif() endif()
elseif(UNIX) elseif(UNIX)
else() else()
endif() endif()

View File

@ -73,6 +73,12 @@ following line instead of the second line:
#+begin_src shell #+begin_src shell
conan install .. --build missing --profile <your_profile> conan install .. --build missing --profile <your_profile>
#+end_src #+end_src
If you wish to build the projects tests in addition to the project itself, you
can add the option ~-DTESTS=True~ to the first ~cmake~ command to build the
projects tests too.
#+begin_src shell
cmake -DCMAKE_CXX_COMPILER=clang++ -DTESTS=True .. -G Ninja
#+end_src
If you do not wish to build your project with Ninja but with another generator, If you do not wish to build your project with Ninja but with another generator,
such as Unix Makefiles, simply replace ~Ninja~ in the second to last ~cmake~ such as Unix Makefiles, simply replace ~Ninja~ in the second to last ~cmake~