Browse Source

CMake build system

ObjPtr
Michael Uleysky 9 years ago
parent
commit
ebc4f236db
  1. 44
      CMakeLists.txt
  2. 11
      cmake/modules/BuildModule.cmake
  3. 43
      src/CMakeLists.txt
  4. 4
      src/Makefile
  5. 2
      src/parser/grammatical.y
  6. 2
      src/parser/lexical.l

44
CMakeLists.txt

@ -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)

11
cmake/modules/BuildModule.cmake

@ -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()

43
src/CMakeLists.txt

@ -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)

4
src/Makefile

@ -31,11 +31,11 @@ $(DEPENDS): ../include/grammatical.h ../include/lexical.h
parser/grammatical.d: ../include/lexical.h
parser/lexical.cpp: parser/lexical.l
cd parser && flex lexical.l
flex -o $@ --header-file=../include/lexical.h $<
[ -f ../include/lexical.h ] && touch ../include/lexical.h
parser/grammatical.cpp: parser/grammatical.y
cd parser && bison grammatical.y
bison -o $@ --defines=../include/grammatical.h $<
[ -f ../include/grammatical.h ] && touch ../include/grammatical.h
../include/grammatical.h: parser/grammatical.y parser/grammatical.cpp

2
src/parser/grammatical.y

@ -1,6 +1,4 @@
%language "c"
%output "grammatical.cpp"
%defines "../../include/grammatical.h"
%param {yyscan_t scanner}
%define api.prefix {conf}
%define api.pure full

2
src/parser/lexical.l

@ -2,8 +2,6 @@
%option warn
%option yylineno
%option noyywrap
%option header-file="../../include/lexical.h"
%option outfile="lexical.cpp"
%option prefix="conf"
%option extra-type="struct lexical_extra*"
%option bison-bridge

Loading…
Cancel
Save