mp/CMakeLists.txt

61 lines
2.1 KiB
CMake
Raw Normal View History

2019-07-02 14:35:02 +00:00
cmake_minimum_required(VERSION 3.0)
get_filename_component(project_name ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(${project_name})
set(EXTENSION "cpp")
set(CMAKE_CXX_STANDARD 14)
set(FLAGS_ANY "-Wall -Wextra -Winline")
set(FLAGS_DEBUG "-DDEBUG -O0 -pg")
set(FLAGS_RELEASE "-DNDEBUG -O2")
set(EXAMPLESDIRS mp et)
set(INCLUDE_DIRS "")
set(LIBRARIES "-lpthread")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS_ANY}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAGS_ANY} ${FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${FLAGS_ANY} ${FLAGS_RELEASE}")
## Examples
foreach(examplesdir ${EXAMPLESDIRS})
set(examplesfulldir examples/${examplesdir})
set(examplespath ${CMAKE_CURRENT_SOURCE_DIR}/${examplesfulldir})
file(GLOB examples RELATIVE ${examplespath} ${examplespath}/*)
if(examples)
foreach(child ${examples})
set(example_bin_filename "")
set(example "")
if(IS_DIRECTORY ${examplespath}/${child})
set(example_bin_filename ${child})
set(example ${examplesdir}_${example_bin_filename})
file(GLOB_RECURSE example_src ${examplespath}/${child}/*.${EXTENSION})
else()
get_filename_component(extension ${child} EXT)
if(${extension} MATCHES "^.${EXTENSION}$")
get_filename_component(example_name ${child} NAME_WE)
set(example_bin_filename ${example_name})
set(example ${examplesdir}_${example_bin_filename})
set(example_src ${examplespath}/${child})
endif()
endif()
if(example)
if(example_src)
message(STATUS "+ Example: ${examplesdir}/${example}")
add_executable(${example} ${example_src})
target_include_directories(${example} PUBLIC ${SRCDIRS} ${LIBSDIRS} ${INCLUDE_DIRS})
target_link_libraries(${example} ${LIBRARIES} ${USER_LIBRARIES})
set_target_properties(${example} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${examplesfulldir})
set_target_properties(${example} PROPERTIES OUTPUT_NAME ${example_bin_filename})
else()
message(WARNING "! Example ${example}: no sources")
endif()
endif()
endforeach()
endif()
endforeach()