Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set(PROGRAM_NAME filesystem_demonstration_program)
- set(SOURCE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/source)
- #compiler flag settings
- set(BUILD_RELEASE FALSE) #default debug
- set(CPLUSPLUS_11 TRUE)
- set(C_11 TRUE)
- set(STRICT_COMPILE TRUE)
- set(STATIC_COMPILE TRUE)
- set(OPTIMIZE_BUILD_FLAGS TRUE) #will only be used for release. :)
- #boost settings
- set(USING_BOOST_LIBRARY TRUE)
- set(BOOST_LIB_COMPONENTS filesystem system) #change these library filenames if necessary
- set(BOOST_LIB_COMPONENTS_LITERAL libboost_filesystem.a libboost_system.a)
- #ncurses settings
- set(USING_NCURSES_LIBRARY TRUE)
- set(NCURSES_LIB_COMPONENTS ncurses) #change these library filenames if necessary
- set(NCURSES_LIB_COMPONENTS_LITERAL libncurses.a)
- #-------------------------------------------------------------------------------------------------
- #cmake settings:
- #CMAKE_CXX_FLAGS_DEBUG = debug
- #CMAKE_CXX_FLAGS_RELEASE = release
- #CMAKE_CXX_FLAGS = no flags
- if(BUILD_RELEASE) #this makes it easier to switch between release and debug
- set(CMAKE_BUILD_TYPE Release)
- else()
- set(CMAKE_BUILD_TYPE Debug)
- endif()
- set(BUILD_SHARED_LIBS OFF)
- # =================================================================================================
- # =================================================================================================
- # =================================================================================================
- # =================================================================================================
- #sets c++11
- macro(use_cplusplus11)
- set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}\ -std=c++11)
- endmacro(use_cplusplus11)
- #sets c99
- macro(use_c99)
- set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}\ -std=c99)
- endmacro(use_c99)
- #sets c11
- macro(use_c11)
- set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}\ -std=c11)
- endmacro(use_c11)
- #sets strict
- macro(set_strict)
- set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}\ -Wall\ -pedantic\ -Wextra)
- endmacro(set_strict)
- #sets static
- macro(set_static)
- set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}\ -static)
- endmacro(set_static)
- #adds optimization flags
- macro(add_build_optimizations)
- if(BUILD_RELEASE)
- set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}\ -O\ -Os)
- endif()
- endmacro(add_build_optimizations)
- #adds boost library
- macro(add_boost)
- set(Boost_USE_STATIC_LIBS ON)
- set(Boost_USE_MULTITHREADED OFF)
- set(Boost_USE_STATIC_RUNTIME ON)
- set(BOOST_LIBS filesystem system)
- find_package(Boost REQUIRED COMPONENTS ${BOOST_LIB_COMPONENTS})
- if(Boost_FOUND)
- include_directories(${Boost_INCLUDE_DIRS})
- link_directories(${Boost_LIBRARY_DIRS})
- target_link_libraries(${PROGRAM_NAME} ${BOOST_LIB_COMPONENTS_LITERAL})
- else()
- message("FATAL ERROR: boost library not found!")
- endif()
- endmacro(add_boost)
- #adds ncurses library
- macro(add_ncurses)
- set(CURSES_NEED_NCURSES TRUE)
- find_package(Curses 5.9 REQUIRED COMPONENTS ${NCURSES_LIB_COMPONENTS}) #you will need to modify this to add the libraries you need
- if(CURSES_FOUND)
- include_directories(${CURSES_INCLUDE_DIR})
- add_library(CURSES_LIBRARIES STATIC IMPORTED)
- target_link_libraries(${PROGRAM_NAME} ${NCURSES_LIB_COMPONENTS})
- else()
- message("FATAL ERROR: curses library not found!")
- endif()
- endmacro(add_ncurses)
- #adds executable and source files
- macro(add_files)
- file(GLOB_RECURSE CPP_SOURCE RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${SOURCE_FOLDER}/*.cpp" "${SOURCE_FOLDER}/*.hpp")
- add_executable(${PROGRAM_NAME} ${CPP_SOURCE})
- file(GLOB_RECURSE CPP "${SOURCE_FOLDER}/*.cpp" "${SOURCE_FOLDER}/*.hpp")
- link_directories(${CPP})
- endmacro(add_files)
- cmake_minimum_required(VERSION 2.8)
- set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
- project(${PROGRAM_NAME})
- if(STRICT_COMPILE)
- set_strict()
- endif()
- if(OPTIMIZE_BUILD_FLAGS)
- add_build_optimizations()
- endif()
- if(STATIC_COMPILE)
- set_static()
- endif()
- if(CPLUSPLUS_11)
- use_cplusplus11()
- endif()
- if(USING_BOOST_LIBRARY)
- foreach(temp ${BOOST_LIB_COMPONENTS_LITERAL})
- set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}\ -l:${temp})
- endforeach(temp)
- endif()
- if(USING_NCURSES_LIBRARY)
- foreach(temp2 ${NCURSES_LIB_COMPONENTS_LITERAL})
- set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}\ -l:${temp2})
- endforeach(temp2)
- endif()
- add_files()
- if(USING_NCURSES_LIBRARY)
- add_ncurses()
- endif()
- if(USING_BOOST_LIBRARY)
- add_boost()
- endif()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement