diff --git a/CMakeLists.txt b/CMakeLists.txt index 0920c7f..c9f5eba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,160 +1,159 @@ cmake_minimum_required(VERSION 2.8.8) # Start project, set version here. project("RoSA") set(ROSA_VERSION_MAJOR 0) set(ROSA_VERSION_MINOR 1) set(ROSA_VERSION_PATCH 0) # Add path for custom modules set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" ) # Package information if( NOT PACKAGE_VERSION ) set(PACKAGE_VERSION "${ROSA_VERSION_MAJOR}.${ROSA_VERSION_MINOR}.${ROSA_VERSION_PATCH}") endif() set(PACKAGE_NAME "Research on Self-Awareness Framework") set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") set(PACKAGE_BUGREPORT "david.juhasz@tuwien.ac.at") #TODO: cpack? # Sanity check we are to make out-of-tree build if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR ) message(FATAL_ERROR "In-source builds are not allowed.") endif() string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) # Set various paths set(ROSA_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(ROSA_MAIN_INCLUDE_DIR ${ROSA_MAIN_SRC_DIR}/include) set(ROSA_MAIN_BIN_DIR ${ROSA_MAIN_SRC_DIR}/bin) set(ROSA_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) set(ROSA_RUNTIME_OUTPUT_INTDIR ${ROSA_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) set(ROSA_LIBRARY_OUTPUT_INTDIR ${ROSA_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib) set(ROSA_TOOLS_BINARY_DIR ${ROSA_RUNTIME_OUTPUT_INTDIR}) set(ROSA_LIBRARY_DIR ${ROSA_LIBRARY_OUTPUT_INTDIR}) set(ROSA_INCLUDE_DIR ${ROSA_BINARY_DIR}/include) # Set build options option(ROSA_INCLUDE_TOOLS "Generate build targets for RoSA tools." ON) option(ROSA_INCLUDE_EXAMPLES "Generate build target for RoSA examples." ON) -option(ROSA_ENABLE_CXX1Y "Compile with C++1y enabled." ON) option(ROSA_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" ) option(ROSA_ENABLE_ASSERTIONS "Enable assertions." OFF) else() option(ROSA_ENABLE_ASSERTIONS "Enable assertions." ON) endif() include(HandleROSAOptions) # Configure the ROSA configuration header file. if( ROSA_LOG_LEVEL ) set(ROSA_LOG_LEVEL_INT ${ROSA_LOG_LEVEL}) else() set(ROSA_LOG_LEVEL_INT -1) endif() macro(to_int_value name) if(${name}) set(${name}_INT 1) else() set(${name}_INT -1) endif() endmacro() to_int_value(ROSA_ENABLE_ASSERTIONS) configure_file( ${ROSA_MAIN_INCLUDE_DIR}/rosa/config/rosa_config.h.cmake ${ROSA_INCLUDE_DIR}/rosa/config/rosa_config.h ) # They are not referenced. See set_output_directory(). set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ROSA_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${ROSA_BINARY_DIR}/lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ROSA_BINARY_DIR}/lib) # Set include directories set(CMAKE_INCLUDE_CURRENT_DIR ON) include_directories(${ROSA_INCLUDE_DIR} ${ROSA_MAIN_INCLUDE_DIR}) # Set extra compiler options for Visual Studio if ( MSVC ) add_definitions(-EHsc) # Use Exception Handling endif() # Set up YCM set(CMAKE_EXPORT_COMPILE_COMMANDS 1) message("Set compilation_database_folder in .ymc_extra_conf.py in the source directory if you want to use YMC.") # Add parts of the project include(AddROSATools) add_subdirectory(lib) if( ROSA_INCLUDE_TOOLS ) add_subdirectory(tools) endif() if( ROSA_INCLUDE_EXAMPLES ) add_subdirectory(examples) endif() #TODO: install? # Print summary set(LOG_LEVEL_STR "none") if(ROSA_LOG_LEVEL) if(${ROSA_LOG_LEVEL} EQUAL 0) set(LOG_LEVEL_STR "ERROR") elseif(${ROSA_LOG_LEVEL} EQUAL 1) set(LOG_LEVEL_STR "WARNING") elseif(${ROSA_LOG_LEVEL} EQUAL 2) set(LOG_LEVEL_STR "INFO") elseif(${ROSA_LOG_LEVEL} EQUAL 3) set(LOG_LEVEL_STR "DEBUG") elseif(${ROSA_LOG_LEVEL} EQUAL 4) set(LOG_LEVEL_STR "TRACE") else() set(LOG_LEVEL_STR "invalid") endif() endif() message(STATUS "\n====================| Build Summary |====================" "\n" "\nRoSA version: ${PACKAGE_VERSION}" "\n" "\nBuild type: ${CMAKE_BUILD_TYPE}" "\nAssertions: ${ROSA_ENABLE_ASSERTIONS}" "\nLog level: ${LOG_LEVEL_STR}" "\n" "\nBuild tools: ${ROSA_INCLUDE_TOOLS}" "\nBuild examples: ${ROSA_INCLUDE_EXAMPLES}" "\n" "\nCC: ${CMAKE_C_COMPILER}" "\nCFLAGS: ${CMAKE_C_FLAGS}" "\nCXX: ${CMAKE_CXX_COMPILER}" "\nCXXFLAGS: ${CMAKE_CXX_FLAGS}" "\nLIBRARIES: ${LD_FLAGS}" "\n" "\nSource directory: ${ROSA_MAIN_SRC_DIR}" "\nBuild directory: ${ROSA_BINARY_DIR}" "\nExecutable path: ${ROSA_TOOLS_BINARY_DIR}" "\nLibrary path: ${ROSA_LIBRARY_DIR}" "\nGenerator: ${CMAKE_GENERATOR}" "\n" "\n===========================================================\n") diff --git a/README.txt b/README.txt index b1b87a8..0c4f9fd 100644 --- a/README.txt +++ b/README.txt @@ -1,62 +1,61 @@ ==================================== Research on Self-Awareness Framework ==================================== Build: ----- The provided CMake project supports only out-of-tree builds, i.e. one needs to create a build directory and run cmake in that using the source directory path as argument. Prerequisites: ------------- Nothing yet. Build options: ------------- Beyond the usual CMake options, the following project-related options are available: * ROSA_INCLUDE_TOOLS, defaults to ON * ROSA_INCLUDE_EXAMPLES, defaults to ON - * ROSA_ENABLE_CXX1Y, defaults to ON * ROSA_ENABLE_PEDANTIC, defaults to ON * ROSA_ENABLE_ASSERTIONS, defaults to ON only for debug builds, and its value is respected only for non-debug builds * ROSA_LOG_LEVEL, defaults to none, use a valid integer value to enable logging ** 0 - ERROR ** 1 - WARNING ** 2 - INFO ** 3 - DEBUG ** 4 - TRACE Set C and C++ compilers with the environment variables CC and CXX, respectively. Use the CMake variable CMAKE_BUILD_TYPE for single-configuration generators to set the type of build: Debug, Release. Using YCM: --------- If you happen to use YMC, just make a copy of the provided ycm_extra_conf.py.template file as .ycm_extra_conf.py in the project directory, and set the following two variables in it: * compilation_database_folder: the absolute path of your build directory * extra_system_include_dirs: any system include directory which might not be search by libclang. See: https://github.com/Valloric/YouCompleteMe/issues/303; use the following command to figure out the used system directories: 'echo | clang -std=c++11 -v -E -x c++ -'. You probably want compile with clang if you use YCM, so run cmake with environment variables CC=clang and CXX=clang++ set. Also note that headers file in the include directory are compiled for YCM with the compiler flags of a corresponding source file in the lib directory, if any. Header files in other locations are supposed to have a corresponding source file in the same directory. If the project's include directory (include/rosa) would be ever changed, then that needs to be also modified in the YCM configuration file. diff --git a/cmake/modules/HandleROSAOptions.cmake b/cmake/modules/HandleROSAOptions.cmake index 6b30861..d71e140 100644 --- a/cmake/modules/HandleROSAOptions.cmake +++ b/cmake/modules/HandleROSAOptions.cmake @@ -1,83 +1,78 @@ # This CMake module is responsible for interpreting the user defined ROSA_ # options and executing the appropriate CMake commands to realize the users' # selections. include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) if( CMAKE_COMPILER_IS_GNUCXX ) set(ROSA_COMPILER_IS_GCC_COMPATIBLE ON) elseif( MSVC ) set(ROSA_COMPILER_IS_GCC_COMPATIBLE OFF) elseif( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) set(ROSA_COMPILER_IS_GCC_COMPATIBLE ON) endif() function(append value) foreach(variable ${ARGN}) set(${variable} "${${variable}} ${value}" PARENT_SCOPE) endforeach(variable) endfunction() function(append_if condition value) if (${condition}) foreach(variable ${ARGN}) set(${variable} "${${variable}} ${value}" PARENT_SCOPE) endforeach(variable) endif() endfunction() # NDEBUG on non-Debug builds append("-DNDEBUG" CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS_MINSIZEREL) # Assertions are always enabled on Debug builds, this is interesting for # non-Debug builds. if( ROSA_ENABLE_ASSERTIONS ) # MSVC doesn't like _DEBUG on release builds. See PR 4379. if( NOT MSVC ) add_definitions( -D_DEBUG ) set(ENABLE_ASSERTIONS "1") else() set(ENABLE_ASSERTIONS "0") endif() # On non-Debug builds we NDEBUG, but in this case we need to undefine it: add_definitions(-UNDEBUG) # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines. foreach (flags_var_to_scrub CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS_MINSIZEREL) string (REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " " "${flags_var_to_scrub}" "${${flags_var_to_scrub}}") endforeach() endif( ROSA_ENABLE_ASSERTIONS ) +#FIXME: Disable RTTI and exceptions, once gen_agent_test2 is cleared up. + if( ROSA_COMPILER_IS_GCC_COMPATIBLE ) append("-Wall -Wextra -Werror" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) append_if(ROSA_ENABLE_PEDANTIC "-pedantic -Wno-long-long" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - # Newer Clang versions cannot parse cstdio in c++1y mode. - if( ROSA_ENABLE_CXX1Y AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - check_cxx_compiler_flag("-std=c++1y" CXX_SUPPORTS_CXX1Y) - append_if(CXX_SUPPORTS_CXX1Y "-std=c++1y" CMAKE_CXX_FLAGS) - if( NOT CMAKE_CXX_FLAGS ) - message(FATAL_ERROR "Your compiler does not support '-std=c++1y' flag, use ROSA_ENABLE_CXX1Y=FALSE.") - endif() + check_cxx_compiler_flag("-std=c++11" CXX_SUPPORTS_CXX11) + if (CXX_SUPPORTS_CXX11) + append("-std=c++11" CMAKE_CXX_FLAGS) else() - check_cxx_compiler_flag("-std=c++11" CXX_SUPPORTS_CXX11) - if (CXX_SUPPORTS_CXX11) - append("-std=c++11" CMAKE_CXX_FLAGS) - else() - message(FATAL_ERROR "RoSA requires C++11 support but the '-std=c++11' flag isn't supported.") - endif() + message(FATAL_ERROR "RoSA requires C++11 support but the '-std=c++11' flag isn't supported.") endif() +else ( ROSA_COMPILER_IS_GCC_COMPATIBLE ) + # FIXME: set the same things as for GCC-compatible compilers endif( ROSA_COMPILER_IS_GCC_COMPATIBLE )