From 98900c813d6b037a3931c60836a1df0405e1d6c5 Mon Sep 17 00:00:00 2001 From: Magnus Lundborg Date: Wed, 22 May 2013 14:58:40 +0200 Subject: Added building options and bin subdirectories Options to determine whether to build examples (on) and compression tests (off). Place binaries in subdirectories. diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e32141..496a830 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,9 @@ include_directories(${CMAKE_SOURCE_DIR}/include) option(BUILD_FORTRAN "Build Fortran compatible library and examples for testing" OFF) +option(BUILD_TNG_EXAMPLES "Build examples showing usage of the TNG API" ON) +option(BUILD_COMPRESSION_TESTS "Build tests of the TNG compression library" OFF) + option(USE_OPENMP "Try to use the OpenMP library (if available)" ON) if(USE_OPENMP) find_package(OpenMP) diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 303035e..bee72c9 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -1,4 +1,6 @@ -add_subdirectory(compression) +if(BUILD_COMPRESSION_TESTS) + add_subdirectory(compression) +endif() if(NOT OPENMP_FOUND) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") @@ -21,37 +23,45 @@ if(HAVE_INTTYPES_H) set_target_properties(tng_testing PROPERTIES COMPILE_DEFINITIONS USE_STD_INTTYPES_H=1) endif() -if(OPENMP_FOUND) - add_executable(md_openmp md_openmp.c) - target_link_libraries(md_openmp tng_io ${OpenMP_LIBS}) - if(UNIX) - target_link_libraries(md_openmp m) - endif() -endif() +set_property(TARGET tng_testing PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests) -add_executable(tng_io_read_pos tng_io_read_pos.c) -target_link_libraries(tng_io_read_pos tng_io) -if(UNIX) -target_link_libraries(tng_io_read_pos m) -endif() +if(BUILD_TNG_EXAMPLES) + if(OPENMP_FOUND) + add_executable(md_openmp md_openmp.c) + target_link_libraries(md_openmp tng_io ${OpenMP_LIBS}) + if(UNIX) + target_link_libraries(md_openmp m) + endif() + set_property(TARGET md_openmp PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples) + endif() -add_executable(tng_parallel_read tng_parallel_read.c) -target_link_libraries(tng_parallel_read tng_io) -if(UNIX) -target_link_libraries(tng_parallel_read m) -endif() + add_executable(tng_io_read_pos tng_io_read_pos.c) + target_link_libraries(tng_io_read_pos tng_io) + if(UNIX) + target_link_libraries(tng_io_read_pos m) + endif() + set_property(TARGET tng_io_read_pos PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples) -if(BUILD_FORTRAN) - # This does not work due to a bug in CMake. Remove lines below if no fortran compiler is found. - enable_language(Fortran OPTIONAL) - if(${CMAKE_Fortran_COMPILER_WORKS}) - get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME) - if (Fortran_COMPILER_NAME STREQUAL "gfortran") - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fcray-pointer ${OpenMP_C_FLAGS} -std=legacy") + add_executable(tng_parallel_read tng_parallel_read.c) + target_link_libraries(tng_parallel_read tng_io) + if(UNIX) + target_link_libraries(tng_parallel_read m) endif() - if(OPENMP_FOUND) - add_executable(md_openmp_f md_openmp.f) - target_link_libraries(md_openmp_f tng_io ${OpenMP_LIBS}) + set_property(TARGET tng_parallel_read PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples) + + if(BUILD_FORTRAN) + # This does not work due to a bug in CMake. Remove lines below if no fortran compiler is found. + enable_language(Fortran OPTIONAL) + if(${CMAKE_Fortran_COMPILER_WORKS}) + get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME) + if (Fortran_COMPILER_NAME STREQUAL "gfortran") + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fcray-pointer ${OpenMP_C_FLAGS} -std=legacy") + endif() + if(OPENMP_FOUND) + add_executable(md_openmp_f md_openmp.f) + target_link_libraries(md_openmp_f tng_io ${OpenMP_LIBS}) + endif() + endif() + set_property(TARGET md_openmp_f PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples) endif() - endif() -endif() +endif() \ No newline at end of file diff --git a/src/tests/compression/CMakeLists.txt b/src/tests/compression/CMakeLists.txt index 930bcfc..1325474 100644 --- a/src/tests/compression/CMakeLists.txt +++ b/src/tests/compression/CMakeLists.txt @@ -24,6 +24,7 @@ list(APPEND gen${number}_build_definitions GEN) list(APPEND gen${number}_build_definitions TESTPARAM="test${number}.h") set_target_properties(test_tng_compress_gen${number} PROPERTIES COMPILE_DEFINITIONS "${gen${number}_build_definitions}") add_dependencies(test_tng_compress_gen${number} test${number}.h) +set_property(TARGET test_tng_compress_gen${number} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/compression_tests) add_executable(test_tng_compress_read${number} testsuite.c) target_link_libraries(test_tng_compress_read${number} tng_compress) @@ -33,14 +34,15 @@ endif() list(APPEND read${number}_build_definitions TESTPARAM="test${number}.h") set_target_properties(test_tng_compress_read${number} PROPERTIES COMPILE_DEFINITIONS "${read${number}_build_definitions}") add_dependencies(test_tng_compress_read${number} test${number}.h) +set_property(TARGET test_tng_compress_read${number} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/compression_tests) endwhile() if(UNIX) -file(COPY test_tng_compress_write.sh DESTINATION ${CMAKE_BINARY_DIR}/bin) -file(COPY test_tng_compress_read.sh DESTINATION ${CMAKE_BINARY_DIR}/bin) +file(COPY test_tng_compress_write.sh DESTINATION ${CMAKE_BINARY_DIR}/bin/compression_tests) +file(COPY test_tng_compress_read.sh DESTINATION ${CMAKE_BINARY_DIR}/bin/compression_tests) endif() if(WIN32) -file(COPY test_tng_compress_write.bat DESTINATION ${CMAKE_BINARY_DIR}/bin) -file(COPY test_tng_compress_read.bat DESTINATION ${CMAKE_BINARY_DIR}/bin) +file(COPY test_tng_compress_write.bat DESTINATION ${CMAKE_BINARY_DIR}/bin/compression_tests) +file(COPY test_tng_compress_read.bat DESTINATION ${CMAKE_BINARY_DIR}/bin/compression_tests) endif() -- cgit v0.10.1