project(GLTB) cmake_minimum_required(VERSION 2.8) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") find_package(Clang) if(UNIX) set(GLTB_NO_ICU 0 CACHE BOOL "Build GLTB without ICU support for Unicode conversion") if(NOT GLTB_NO_ICU) find_package(ICU REQUIRED) include_directories(${ICU_INCLUDE_DIR}) endif() endif() find_path(GLM_INCLUDE_DIR "glm/glm.hpp") if(GLM_INCLUDE_DIR STREQUAL "GLM_INCLUDE_DIR-NOTFOUND") message(STATUS "glm not found") set(USE_GLM 0) else() message(STATUS "glm include dir: ${GLM_INCLUDE_DIR}") set(USE_GLM 1) endif() if(CMAKE_COMPILER_IS_GNUCXX) set(GLTB_BUILD_32_BIT 0 CACHE BOOL "Build GLTB as 32 bit library") if(GLTB_BUILD_32_BIT) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32") endif() # GCC < 4.7 need different command line arguments than later versions execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) if (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7) message(STATUS "GCC Version >= 4.7") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -DLINUX") else() message(STATUS "GCC Version < 4.7") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -pthread -DLINUX") endif() if(USE_GLM EQUAL 1) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_GLM -DGLM_FORCE_SIZE_T_LENGTH -DGLM_ENABLE_EXPERIMENTAL") endif() endif() if(MSVC) set(CMAKE_CXX_FLAGS "/MP /D \"_UNICODE\" /D \"UNICODE\" ${CMAKE_CXX_FLAGS}") if(USE_GLM EQUAL 1) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D\"USE_GLM\" -DGLM_ENABLE_EXPERIMENTAL") endif() endif() if(UNIX) if(GLTB_NO_ICU) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D\"GLTB_NO_ICU\"") endif() endif() if(USE_GLM EQUAL 1) include_directories("${GLM_INCLUDE_DIR}" include) else() include_directories(include) endif() set(SRC_LIST src/colour.cpp src/commandline.cpp src/exception.cpp src/logging.cpp src/memmappedfile.cpp src/mutex.cpp src/numamemory.cpp src/parameterfile.cpp src/path.cpp src/processinfo.cpp src/rng.cpp src/rwlock.cpp src/semaphore.cpp src/sharedlibrary.cpp src/stringconvert.cpp src/systeminfo.cpp src/thread.cpp src/timemeasurement.cpp src/timer.cpp src/workqueue.cpp src/reflection/database.cpp) if(USE_GLM EQUAL 1) set(SRC_LIST ${SRC_LIST} src/colour.cpp) endif() if(WIN32) ## check if target is 64 bit and add atomicvc64.asm to sources if(CMAKE_CL_64) message(STATUS "configuring for MSVC on AMD64") add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/atomicvc64.obj COMMAND ml64 /Zd /Zi /c ${CMAKE_CURRENT_SOURCE_DIR}/src/atomicvc64.asm ${CMAKE_CURRENT_BINARY_DIR}/atomicvc64.obj ) set(SRC_LIST ${SRC_LIST} ${CMAKE_CURRENT_BINARY_DIR}/atomicvc64.obj) endif() endif() file(GLOB_RECURSE HEADER_LIST include/*.h) list(APPEND SRC_LIST ${HEADER_LIST}) add_library(gltb_base STATIC ${SRC_LIST}) if(Clang_FOUND) set(EXTRACTOR_SOURCES tools/reflector/annotation.cpp tools/reflector/annotation.h tools/reflector/basicnodes.h tools/reflector/extractor.cpp tools/reflector/extractor.h tools/reflector/generator.cpp tools/reflector/generator.h tools/reflector/main.cpp tools/reflector/referencelookupvisitor.cpp tools/reflector/referencelookupvisitor.h tools/reflector/typetreenode.h tools/reflector/typetreevisitor.cpp tools/reflector/typetreevisitor.h ) add_executable(gltb_reflector ${EXTRACTOR_SOURCES}) target_include_directories(gltb_reflector PRIVATE tools/reflector) target_link_libraries(gltb_reflector libclang gltb_base) endif() # generated cmake config file for projects depending on this one export(PACKAGE GLTB) include(CMakePackageConfigHelpers) set(INCLUDE_INSTALL_DIR include) set(LIB_INSTALL_DIR lib) configure_package_config_file(cmake/GLTBConfig.cmake.in "${PROJECT_BINARY_DIR}/GLTBConfig.cmake" INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/cmake PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR) # installation targets install(TARGETS gltb_base ARCHIVE DESTINATION lib) install(DIRECTORY include/ DESTINATION include) if(Clang_FOUND) install(TARGETS gltb_reflector RUNTIME DESTINATION bin) endif() install(FILES "${PROJECT_BINARY_DIR}/GLTBConfig.cmake" DESTINATION cmake) # test targets set(GLTB_BUILD_TESTS 0 CACHE BOOL "build GLTB tests") if(GLTB_BUILD_TESTS) find_package(GTest REQUIRED) message(STATUS "building GLTB tests") if(WIN32) set(TEST_LIBRARIES gltb_base ${GTEST_LIBRARIES} DbgHelp.lib) else() set(TEST_LIBRARIES gltb_base ${GTEST_LIBRARIES} ${ICU_LIBRARIES} numa) endif() add_executable(affinetransformationtest tests/affinetransformationtest.cpp) target_link_libraries(affinetransformationtest ${TEST_LIBRARIES}) add_executable(alignedheaptest tests/alignedheaptest.cpp) target_link_libraries(alignedheaptest ${TEST_LIBRARIES}) add_executable(arrayviewtest tests/arrayviewtest.cpp) target_link_libraries(arrayviewtest ${TEST_LIBRARIES}) add_executable(atomictest tests/atomictest.cpp) target_link_libraries(atomictest ${TEST_LIBRARIES}) add_executable(bvhtest tests/bvhtest.cpp) target_link_libraries(bvhtest ${TEST_LIBRARIES}) add_executable(commandlinetest tests/commandlinetest.cpp) target_link_libraries(commandlinetest ${TEST_LIBRARIES}) add_executable(histogramtest tests/histogramtest.cpp) target_link_libraries(histogramtest ${TEST_LIBRARIES}) add_executable(intersectiontest tests/intersectiontest.cpp) target_link_libraries(intersectiontest ${TEST_LIBRARIES}) add_executable(numainfo tests/numainfo.cpp) target_link_libraries(numainfo ${TEST_LIBRARIES}) add_executable(openingconetest tests/openingconetest.cpp) target_link_libraries(openingconetest ${TEST_LIBRARIES}) add_executable(pointkdtreetest tests/pointkdtreetest.cpp) target_link_libraries(pointkdtreetest ${TEST_LIBRARIES}) add_executable(pooltest tests/pooltest.cpp) target_link_libraries(pooltest ${TEST_LIBRARIES}) add_executable(randomdirtest tests/randomdirtest.cpp) target_link_libraries(randomdirtest ${TEST_LIBRARIES}) add_executable(rngtest tests/rngtest.cpp) target_link_libraries(rngtest ${TEST_LIBRARIES}) add_executable(spheretest tests/spheretest.cpp) target_link_libraries(spheretest ${TEST_LIBRARIES}) add_executable(simdtest tests/simdtest.cpp) target_link_libraries(simdtest ${TEST_LIBRARIES}) add_executable(stresstest tests/stresstest.cpp) target_link_libraries(stresstest ${TEST_LIBRARIES}) add_executable(stringconverttest tests/stringconverttest.cpp) target_link_libraries(stringconverttest ${TEST_LIBRARIES}) add_executable(stringutilstest tests/stringutilstest.cpp) target_link_libraries(stringutilstest ${TEST_LIBRARIES}) add_executable(timetest tests/timetest.cpp) target_link_libraries(timetest ${TEST_LIBRARIES}) add_executable(workqueuetest tests/workqueuetest.cpp) target_link_libraries(workqueuetest ${TEST_LIBRARIES}) endif()