diff options
Diffstat (limited to '')
-rw-r--r-- | cmake/dists/cmake/Modules/UsePascal.cmake | 100 |
1 files changed, 79 insertions, 21 deletions
diff --git a/cmake/dists/cmake/Modules/UsePascal.cmake b/cmake/dists/cmake/Modules/UsePascal.cmake index e3c3612b..7a7ade08 100644 --- a/cmake/dists/cmake/Modules/UsePascal.cmake +++ b/cmake/dists/cmake/Modules/UsePascal.cmake @@ -11,12 +11,19 @@ # (mostly used for header files). # This information will be appended to a module generated by # add_pascal_module() if a package is specified with the PACKAGE -# option. +# option. +# You can pass additional compiler flags with +# <COMPILER>_FLAGS (for all module types) and +# <COMPILER>_LIBRARY_FLAGS (for libraries only) +# where <COMPILER> must be either FPC or DELPHI. # PASCAL_ADD_PACKAGE( # <name> # [UNITS file1 [...]] # [INCLUDES file1 [...]] # [OBJECT_DIRS dir1 [...]] +# [<COMPILER>_FLAGS ...] +# [<COMPILER>_LIBRARY_FLAGS] +# ) # # - Builds a Pascal module. # The module can be a program, library or unit. The type is either autodetected @@ -46,16 +53,18 @@ # Units/includes used by packages specified by the PACKAGES option do not have to be specified # again with UNITS/INCLUDES. Package sources are not appended to auto-generated project files # for lazarus. +# You can pass additional compiler flags with <COMPILER>_FLAGS where <COMPILER> +# must be one of FPC or DELPHI. # Sets target properties: -# - PASCAL_TYPE: module type (one of PROGRAM/LIBRARY/UNIT) -# - PASCAL_LOCATION: full path of output file (equivalent to LOCATION) +# - PASCAL_TYPE: module type (one of PROGRAM/LIBRARY/UNIT) +# - PASCAL_LOCATION: full path of output file (equivalent to LOCATION) # PASCAL_ADD_MODULE( # <name> # [PROGRAM | LIBRARY | UNIT] # <main_source> # [OUTPUT_NAME name] # [OUTPUT_DIR dir] -# [FLAGS ...] +# [<COMPILER>_FLAGS ...] # [DEPENDS depend [...]] # [UNITS file1 [...]] # [INCLUDES file1 [...]] @@ -79,13 +88,22 @@ include(LazarusGenerator) option(GENERATE_LAZARUS_PROJECTS "Generate lazarus project files (.lpi) for every Pascal target" OFF) function(PASCAL_ADD_PACKAGE name) + # setup a list of property names to copy from the arguments + set(prop_list) + list(APPEND prop_list OBJECT_DIRS) + foreach(comp FPC DELPHI) + list(APPEND prop_list ${comp}_FLAGS ${comp}_LIBRARY_FLAGS) + endforeach(comp) + + # parse arguments set(ARG) parse_arguments(ARG - "UNITS;INCLUDES;OBJECT_DIRS" + "UNITS;INCLUDES;${prop_list}" "" ${ARGN} ) + # transform file paths to absolute paths set(unit_abs_list) foreach(unit ${ARG_UNITS}) get_filename_component(unit_abs ${unit} ABSOLUTE) @@ -97,16 +115,19 @@ function(PASCAL_ADD_PACKAGE name) list(APPEND inc_abs_list ${inc_abs}) endforeach(inc) + # store info in global properties set_property(GLOBAL PROPERTY PASCAL_PKG_${name}_EXISTS TRUE) set_property(GLOBAL PROPERTY PASCAL_PKG_${name}_UNITS "${unit_abs_list}") set_property(GLOBAL PROPERTY PASCAL_PKG_${name}_INCLUDES "${inc_abs_list}") - set_property(GLOBAL PROPERTY PASCAL_PKG_${name}_OBJECT_DIRS "${ARG_OBJECT_DIRS}") + foreach(prop ${prop_list}) + set_property(GLOBAL PROPERTY PASCAL_PKG_${name}_${prop} "${ARG_${prop}}") + endforeach(prop) endfunction(PASCAL_ADD_PACKAGE) macro(PASCAL_ADD_MODULE) set(ARG) - parse_arguments(ARG - "OUTPUT_NAME;OUTPUT_DIR;FLAGS;DEPENDS;UNITS;INCLUDES;OBJECT_DIRS;PACKAGES" + parse_arguments(ARG + "OUTPUT_NAME;OUTPUT_DIR;DEPENDS;UNITS;INCLUDES;OBJECT_DIRS;PACKAGES;FPC_FLAGS;DELPHI_FLAGS" "EXCLUDE_FROM_ALL;REBUILD_ALL" ${ARGN} ) @@ -197,7 +218,7 @@ macro(PASCAL_ADD_MODULE) list(APPEND extra_clean_files ${output}) endif(type STREQUAL PROGRAM) if(type STREQUAL LIBRARY) - set(output "${output_dir}/${PPC_LIBRARY_PREFIX}${output_name}${PPC_LIBRARY_SUFFIX}") + set(output "${output_dir}/${PASCAL_LIBRARY_PREFIX}${output_name}${PASCAL_LIBRARY_SUFFIX}") list(APPEND extra_clean_files ${output}) endif(type STREQUAL LIBRARY) if(type STREQUAL UNIT) @@ -212,6 +233,24 @@ macro(PASCAL_ADD_MODULE) # set working dir set(work_dir ${CMAKE_CURRENT_SOURCE_DIR}) + # assemble pascal compiler flags + set(pflags ${PASCAL_FLAGS}) + if(type STREQUAL LIBRARY) + list(APPEND pflags ${PASCAL_LIBRARY_FLAGS}) + endif(type STREQUAL LIBRARY) + if(CMAKE_BUILD_TYPE STREQUAL Release) + list(APPEND pflags ${PASCAL_FLAGS_RELEASE}) + elseif(CMAKE_BUILD_TYPE STREQUAL Debug) + list(APPEND pflags ${PASCAL_FLAGS_DEBUG}) + elseif(CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo) + list(APPEND pflags ${PASCAL_FLAGS_RELWITHDEBINFO}) + elseif(CMAKE_BUILD_TYPE STREQUAL MinSizeRelDebug) + list(APPEND pflags ${PASCAL_FLAGS_MINSIZEREL}) + endif() + + # set target specific flags + list(APPEND pflags ${ARG_${PASCAL_COMPILER_TYPE}_FLAGS}) + # init unit/include/object dir list set(unit_dirs "") set(inc_dirs "") @@ -219,23 +258,39 @@ macro(PASCAL_ADD_MODULE) # add packages foreach(pkg ${ARG_PACKAGES}) + # check existence set(pkg_exists) get_property(pkg_exists GLOBAL PROPERTY PASCAL_PKG_${pkg}_EXISTS) if(NOT pkg_exists) message(FATAL_ERROR "Unknown pascal package \"${pkg}\". See pascal_add_package().") endif(NOT pkg_exists) + # append package units set(pkg_units) get_property(pkg_units GLOBAL PROPERTY PASCAL_PKG_${pkg}_UNITS) list(APPEND units ${pkg_units}) + # append package includes set(pkg_incs) get_property(pkg_incs GLOBAL PROPERTY PASCAL_PKG_${pkg}_INCLUDES) list(APPEND incs ${pkg_incs}) + # append package object dirs set(pkg_obj_dirs) get_property(pkg_obj_dirs GLOBAL PROPERTY PASCAL_PKG_${pkg}_OBJECT_DIRS) list(APPEND obj_dirs ${pkg_obj_dirs}) + + # append package flags + set(pkg_flags) + get_property(pkg_flags GLOBAL PROPERTY PASCAL_PKG_${pkg}_${PASCAL_COMPILER_TYPE}_FLAGS) + list(APPEND pflags ${pkg_flags}) + + # append package library flags if appropriate + if(type STREQUAL LIBRARY) + set(pkg_lib_flags) + get_property(pkg_lib_flags GLOBAL PROPERTY PASCAL_PKG_${pkg}_${PASCAL_COMPILER_TYPE}_LIBRARY_FLAGS) + list(APPEND pflags ${pkg_lib_flags}) + endif(type STREQUAL LIBRARY) endforeach(pkg ${ARG_PACKAGES}) # add unit/include/object dirs passed as macro parameter @@ -279,8 +334,7 @@ macro(PASCAL_ADD_MODULE) # add *.pas/*.pp of each unit-dir and *.inc of each inc-dir # to the depends list set(depends) - list(APPEND depends ${units}) - list(APPEND depends ${incs}) + list(APPEND depends ${units} ${incs}) # check if we are to add the target to ALL set(custom_target_all "ALL") @@ -290,12 +344,16 @@ macro(PASCAL_ADD_MODULE) # check if even unchanged units should be rebuild if(ARG_REBUILD_ALL) - list(APPEND PFLAGS -B) + # Note that the -B (build all modules) option does not work if not all + # unit-directories the project uses are passed with the -Fu flag. + # Sources in directories not given with -Fu (even if listed in the dpr/lpr file) + # are never recompiled. + # As a safer method clean the unit-output directory instead but keep + # the -B flag for lazarus project files as it does not hurt. + set(unit_out_clean COMMAND ${CMAKE_COMMAND} -E remove_directory ${unit_out_dir}) + list(APPEND pflags -B) endif(ARG_REBUILD_ALL) - # set flags - list(APPEND PFLAGS ${ARG_FLAGS}) - # lower-case project type (just for user info) string(TOLOWER ${type} proj_type_lowcase) @@ -309,12 +367,11 @@ macro(PASCAL_ADD_MODULE) add_custom_command( OUTPUT ${target_timestamp} # delete and create units dir (needed for proper update) -# COMMAND ${CMAKE_COMMAND} -E remove_directory ${unit_out_dir} + ${unit_out_clean} COMMAND ${CMAKE_COMMAND} -E make_directory ${unit_out_dir} # build - COMMAND ${PPC} -# -l- -vi- - ${PFLAGS} + COMMAND ${PASCAL_COMPILER} + ${pflags} ${dir_flag_list} -FU${unit_out_dir} -o${output} @@ -328,7 +385,8 @@ macro(PASCAL_ADD_MODULE) ) # add target - add_custom_target(${target} ${custom_target_all} + add_custom_target(${target} + ${custom_target_all} COMMENT "Checking dependencies of target ${target}" DEPENDS ${target_timestamp} ) @@ -350,7 +408,7 @@ macro(PASCAL_ADD_MODULE) "${ARG_INCLUDES}" "${inc_dirs}" "${obj_dirs}" - "${PFLAGS}" + "${pflags}" ) endif(GENERATE_LAZARUS_PROJECTS) endmacro(PASCAL_ADD_MODULE) |