Michael Uleysky
9 years ago
6 changed files with 100 additions and 6 deletions
@ -0,0 +1,44 @@ |
|||||||
|
cmake_minimum_required(VERSION 2.8.5) |
||||||
|
|
||||||
|
project(gmt_makemap CXX) |
||||||
|
|
||||||
|
if(NOT CMAKE_BUILD_TYPE) |
||||||
|
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo" FORCE) |
||||||
|
endif() |
||||||
|
|
||||||
|
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/" CACHE INTERNAL "Location of our custom CMake modules." FORCE) |
||||||
|
|
||||||
|
include_directories(include) |
||||||
|
set(default_options -std=gnu++11 -flto -fvisibility=hidden -Wl,--export-dynamic -Wall) |
||||||
|
add_compile_options(${default_options}) |
||||||
|
|
||||||
|
file(GLOB modules modules/*) |
||||||
|
file(GLOB extramodules extramodules/*) |
||||||
|
|
||||||
|
set(STATIC_MODULES "") |
||||||
|
|
||||||
|
foreach(ext ${modules}) |
||||||
|
if(EXISTS ${ext}/CMakeLists.txt) |
||||||
|
string(REGEX REPLACE .*/ "" modname ${ext}) |
||||||
|
option(MODULE_${modname}_BUILD "Build module ${modname}" ON) |
||||||
|
option(MODULE_${modname}_STATIC "Link module ${modname} statically in gmt_makemap" ON) |
||||||
|
mark_as_advanced(FORCE MODULE_${modname}_STATIC) |
||||||
|
if(MODULE_${modname}_BUILD) |
||||||
|
add_subdirectory(modules/${modname}) |
||||||
|
endif() |
||||||
|
endif() |
||||||
|
endforeach(ext) |
||||||
|
|
||||||
|
foreach(ext ${extramodules}) |
||||||
|
if(EXISTS ${ext}/CMakeLists.txt) |
||||||
|
string(REGEX REPLACE .*/ "" modname ${ext}) |
||||||
|
option(MODULE_${modname}_BUILD "Build module ${modname}" ON) |
||||||
|
option(MODULE_${modname}_STATIC "Link module ${modname} statically in gmt_makemap" ON) |
||||||
|
mark_as_advanced(FORCE MODULE_${modname}_STATIC) |
||||||
|
if(MODULE_${modname}_BUILD) |
||||||
|
add_subdirectory(extramodules/${modname}) |
||||||
|
endif() |
||||||
|
endif() |
||||||
|
endforeach(ext) |
||||||
|
|
||||||
|
add_subdirectory(src) |
@ -0,0 +1,11 @@ |
|||||||
|
set(moddir ${CMAKE_CURRENT_SOURCE_DIR}) |
||||||
|
include(${moddir}/ModuleSetup.cmake OPTIONAL) |
||||||
|
file(GLOB srcs *.cpp) |
||||||
|
if(MODULE_${modname}_STATIC) |
||||||
|
set(STATIC_MODULES ${STATIC_MODULES} ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE) |
||||||
|
else() |
||||||
|
include_directories(${MODULE_ADDITIONAL_INCLUDES}) |
||||||
|
add_library(${modname} MODULE ${srcs} ${MODULE_ADDITIONAL_SOURCES}) |
||||||
|
target_link_libraries(${modname} ${MODULE_ADDITIONAL_LIBRARIES}) |
||||||
|
endif() |
||||||
|
|
@ -0,0 +1,43 @@ |
|||||||
|
cmake_minimum_required(VERSION 2.8.5) |
||||||
|
|
||||||
|
set(EXENAME makemap) |
||||||
|
|
||||||
|
find_package(FLEX REQUIRED) |
||||||
|
find_package(BISON REQUIRED) |
||||||
|
|
||||||
|
find_library(dl dl) |
||||||
|
find_library(pthread pthread) |
||||||
|
|
||||||
|
if(NOT dl) |
||||||
|
message(FATAL_ERROR "libdl not found!") |
||||||
|
endif() |
||||||
|
|
||||||
|
if(NOT pthread) |
||||||
|
message(FATAL_ERROR "libpthread not found!") |
||||||
|
endif() |
||||||
|
|
||||||
|
file(GLOB srcs *.cpp) |
||||||
|
BISON_TARGET(GParser parser/grammatical.y ${CMAKE_CURRENT_BINARY_DIR}/grammatical.cpp) |
||||||
|
FLEX_TARGET(LScanner parser/lexical.l ${CMAKE_CURRENT_BINARY_DIR}/lexical.cpp COMPILE_FLAGS "--header-file=${CMAKE_CURRENT_BINARY_DIR}/lexical.h") |
||||||
|
set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES lexical.h) |
||||||
|
|
||||||
|
set(MODULES_SOURCES "") |
||||||
|
set(MODULES_LIBS "") |
||||||
|
|
||||||
|
foreach(moddir ${STATIC_MODULES}) |
||||||
|
include(${moddir}/ModuleSetup.cmake OPTIONAL) |
||||||
|
file(GLOB modsrcs ${moddir}/*.cpp) |
||||||
|
set(MODULES_SOURCES ${MODULES_SOURCES} ${modsrcs} ${MODULE_ADDITIONAL_SOURCES}) |
||||||
|
set(MODULES_LIBS ${MODULES_LIBS} ${MODULE_ADDITIONAL_LIBRARIES}) |
||||||
|
include_directories(${MODULE_ADDITIONAL_INCLUDES}) |
||||||
|
endforeach() |
||||||
|
|
||||||
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}) |
||||||
|
add_executable(${EXENAME} ${srcs} ${FLEX_LScanner_OUTPUTS} ${BISON_GParser_OUTPUTS} ${MODULES_SOURCES}) |
||||||
|
|
||||||
|
# Workaround. BISON_TARGET makes header with extension .hpp, but we use extension .h |
||||||
|
set_source_files_properties(init.cpp PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/grammatical.h) |
||||||
|
add_custom_command(OUTPUT grammatical.h COMMAND cp grammatical.hpp grammatical.h DEPENDS grammatical.hpp WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) |
||||||
|
|
||||||
|
target_link_libraries(${EXENAME} ${dl} ${pthread} ${MODULES_LIBS}) |
||||||
|
set_target_properties(${EXENAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) |
Loading…
Reference in new issue