Skip to content

Commit

Permalink
Use modern features of CMake (restored Jan Comans patch 2f98a5d)
Browse files Browse the repository at this point in the history
Target objetcs allow fine tuning of the build process and will be used to address #73 and hopefully to allow the compilation of Python tests without recurring to Ninja.
  • Loading branch information
bcoconni committed Nov 1, 2018
1 parent 0376337 commit 7064b29
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 77 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 2.8.7)
cmake_minimum_required (VERSION 2.8.8)

################################################################################
# Project description #
Expand All @@ -24,6 +24,7 @@ endif()
# Build JSBSim libs and exec #
################################################################################

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_subdirectory(src)

################################################################################
Expand Down
56 changes: 14 additions & 42 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@ else()
set(CMAKE_CXX_STANDARD 11)
endif()

################################################################################
# Macros definition. #
################################################################################

macro(add_full_path_name name file_list)
foreach(file_name ${file_list})
list(APPEND files_with_path "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}")
endforeach()
set(JSBSIM_${name} ${files_with_path} PARENT_SCOPE)
endmacro()

macro(propagate_source_files name subelement)
set(JSBSIM_${name}_${subelement}_SRC ${JSBSIM_${subelement}_SRC} PARENT_SCOPE)
set(JSBSIM_${name}_${subelement}_HDR ${JSBSIM_${subelement}_HDR} PARENT_SCOPE)
endmacro()

################################################################################
# Init the list of libraries that JSBSim links with #
################################################################################
Expand Down Expand Up @@ -65,7 +49,7 @@ add_definitions("-DJSBSIM_VERSION=\"${PROJECT_VERSION}${VERSION_MESSAGE}\"")

set(STATIC_LIBNAME_SUFFIX)
if(MSVC AND BUILD_SHARED_LIBS)
set(STATIC_LIBNAME_SUFFIX "static")
set(STATIC_LIBNAME_SUFFIX "static")
endif()

add_subdirectory(initialization)
Expand All @@ -74,10 +58,7 @@ add_subdirectory(math)
add_subdirectory(models)
add_subdirectory(simgear)

if(NOT EXPAT_FOUND)
add_definitions("-DHAVE_EXPAT_CONFIG_H")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/simgear/xml)
else()
if(EXPAT_FOUND)
include_directories(${EXPAT_INCLUDE_DIRS})
set(JSBSIM_LINK_LIBRARIES ${EXPAT_LIBRARIES} ${JSBSIM_LINK_LIBRARIES})
endif()
Expand All @@ -88,18 +69,18 @@ set(SOURCES FGFDMExec.cpp
FGJSBBase.cpp)

add_library(libJSBSim ${HEADERS} ${SOURCES}
${JSBSIM_INITIALISATION_HDR} ${JSBSIM_INITIALISATION_SRC}
${JSBSIM_MODELS_ATMOSPHERE_HDR} ${JSBSIM_MODELS_ATMOSPHERE_SRC}
${JSBSIM_MODELS_FLIGHT_CONTROL_HDR} ${JSBSIM_MODELS_FLIGHT_CONTROL_SRC}
${JSBSIM_MODELS_PROPULSION_HDR} ${JSBSIM_MODELS_PROPULSION_SRC}
${JSBSIM_MODELS_HDR} ${JSBSIM_MODELS_SRC}
${JSBSIM_MATH_HDR} ${JSBSIM_MATH_SRC}
${JSBSIM_INPUT_OUTPUT_HDR} ${JSBSIM_INPUT_OUTPUT_SRC}
${JSBSIM_SIMGEAR_PROPS_HDR} ${JSBSIM_SIMGEAR_PROPS_SRC}
${JSBSIM_SIMGEAR_XML_HDR} ${JSBSIM_SIMGEAR_XML_SRC}
${JSBSIM_SIMGEAR_MAGVAR_HDR} ${JSBSIM_SIMGEAR_MAGVAR_SRC}
${JSBSIM_SIMGEAR_MISC_HDR} ${JSBSIM_SIMGEAR_MISC_SRC}
${JSBSIM_SIMGEAR_IOSTREAMS_HDR} ${JSBSIM_SIMGEAR_IOSTREAMS_SRC}
$<TARGET_OBJECTS:Init>
$<TARGET_OBJECTS:Atmosphere>
$<TARGET_OBJECTS:FlightControl>
$<TARGET_OBJECTS:Propulsion>
$<TARGET_OBJECTS:Models>
$<TARGET_OBJECTS:Math>
$<TARGET_OBJECTS:InputOutput>
$<TARGET_OBJECTS:Properties>
$<TARGET_OBJECTS:Xml>
$<TARGET_OBJECTS:Magvar>
$<TARGET_OBJECTS:Misc>
$<TARGET_OBJECTS:IOStreams>
)

set_target_properties (libJSBSim PROPERTIES
Expand Down Expand Up @@ -127,15 +108,6 @@ else()
COMPONENT devel
# For Mac
FRAMEWORK DESTINATION "/Library/Frameworks")
# If JSBSim is built as a static library on an x86_64 *nix platform, the code
# must be compiled with the -fPIC flag otherwise the compiler will complain:
# relocation R_X86_64_32S against `a local symbol' can not be used when making
# a shared object; recompile with -fPIC
# See http://www.cmake.org/pipermail/cmake/2007-May/014350.html
if (UNIX AND (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64"
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64"))
set_target_properties(libJSBSim PROPERTIES COMPILE_FLAGS "-fPIC")
endif()
endif()

################################################################################
Expand Down
3 changes: 1 addition & 2 deletions src/initialization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ set(HEADERS FGInitialCondition.h
FGTrim.h
FGTrimAxis.h)

add_full_path_name(INITIALISATION_SRC "${SOURCES}")
add_full_path_name(INITIALISATION_HDR "${HEADERS}")
add_library(Init OBJECT ${HEADERS} ${SOURCES})

install(FILES ${HEADERS} DESTINATION include/JSBSim/initialization COMPONENT devel)
3 changes: 1 addition & 2 deletions src/input_output/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ set(HEADERS FGGroundCallback.h
FGInputSocket.h
FGUDPInputSocket.h)

add_full_path_name(INPUT_OUTPUT_SRC "${SOURCES}")
add_full_path_name(INPUT_OUTPUT_HDR "${HEADERS}")
add_library(InputOutput OBJECT ${HEADERS} ${SOURCES})

install(FILES ${HEADERS} DESTINATION include/JSBSim/input_output COMPONENT devel)
3 changes: 1 addition & 2 deletions src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ set(HEADERS FGColumnVector3.h
FGTemplateFunc.h
FGFunctionValue.h)

add_full_path_name(MATH_SRC "${SOURCES}")
add_full_path_name(MATH_HDR "${HEADERS}")
add_library(Math OBJECT ${HEADERS} ${SOURCES})

install(FILES ${HEADERS} DESTINATION include/JSBSim/math COMPONENT devel)
7 changes: 1 addition & 6 deletions src/models/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ set(HEADERS FGAerodynamics.h
FGAccelerations.h
FGFCSChannel.h)

add_full_path_name(MODELS_SRC "${SOURCES}")
add_full_path_name(MODELS_HDR "${HEADERS}")

propagate_source_files(MODELS ATMOSPHERE)
propagate_source_files(MODELS FLIGHT_CONTROL)
propagate_source_files(MODELS PROPULSION)
add_library(Models OBJECT ${HEADERS} ${SOURCES})

install(FILES ${HEADERS} DESTINATION include/JSBSim/models COMPONENT devel)
3 changes: 1 addition & 2 deletions src/models/atmosphere/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ set(HEADERS FGMSIS.h
FGStandardAtmosphere.h
FGWinds.h)

add_full_path_name(ATMOSPHERE_SRC "${SOURCES}")
add_full_path_name(ATMOSPHERE_HDR "${HEADERS}")
add_library(Atmosphere OBJECT ${HEADERS} ${SOURCES})

install(FILES ${HEADERS} DESTINATION include/JSBSim/models/atmosphere COMPONENT devel)
3 changes: 1 addition & 2 deletions src/models/flight_control/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ set(HEADERS FGDeadBand.h
FGWaypoint.h
FGDistributor.h)

add_full_path_name(FLIGHT_CONTROL_SRC "${SOURCES}")
add_full_path_name(FLIGHT_CONTROL_HDR "${HEADERS}")
add_library(FlightControl OBJECT ${HEADERS} ${SOURCES})

install(FILES ${HEADERS} DESTINATION include/JSBSim/models/flight_control COMPONENT devel)
3 changes: 1 addition & 2 deletions src/models/propulsion/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ set(HEADERS FGElectric.h
FGTransmission.h
FGRotor.h)

add_full_path_name(PROPULSION_SRC "${SOURCES}")
add_full_path_name(PROPULSION_HDR "${HEADERS}")
add_library(Propulsion OBJECT ${HEADERS} ${SOURCES})

install(FILES ${HEADERS} DESTINATION include/JSBSim/models/propulsion COMPONENT devel)
6 changes: 0 additions & 6 deletions src/simgear/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,4 @@ add_subdirectory(io/iostreams)

set(JSBSIM_SIMGEAR_HDR compiler.h)

propagate_source_files(SIMGEAR MAGVAR)
propagate_source_files(SIMGEAR MISC)
propagate_source_files(SIMGEAR PROPS)
propagate_source_files(SIMGEAR XML)
propagate_source_files(SIMGEAR IOSTREAMS)

install(FILES ${JSBSIM_SIMGEAR_HDR} DESTINATION include/JSBSim/simgear COMPONENT devel)
3 changes: 1 addition & 2 deletions src/simgear/io/iostreams/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ set(SOURCES sgstream.cxx)

set(HEADERS sgstream.hxx)

add_full_path_name(IOSTREAMS_SRC "${SOURCES}")
add_full_path_name(IOSTREAMS_HDR "${HEADERS}")
add_library(IOStreams OBJECT ${HEADERS} ${SOURCES})

install(FILES ${HEADERS} DESTINATION include/JSBSim/simgear/io/iostreams COMPONENT devel)
3 changes: 1 addition & 2 deletions src/simgear/magvar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ set(SOURCES coremag.cxx)

set(HEADERS coremag.hxx)

add_full_path_name(MAGVAR_SRC "${SOURCES}")
add_full_path_name(MAGVAR_HDR "${HEADERS}")
add_library(Magvar OBJECT ${HEADERS} ${SOURCES})

install(FILES ${HEADERS} DESTINATION include/JSBSim/simgear/magvar COMPONENT devel)
3 changes: 1 addition & 2 deletions src/simgear/misc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ set(SOURCES sg_path.cxx strutils.cxx)

set(HEADERS stdint.hxx sg_path.hxx strutils.hxx)

add_full_path_name(MISC_SRC "${SOURCES}")
add_full_path_name(MISC_HDR "${HEADERS}")
add_library(Misc OBJECT ${HEADERS} ${SOURCES})

install(FILES ${HEADERS} DESTINATION include/JSBSim/simgear/misc COMPONENT devel)
3 changes: 1 addition & 2 deletions src/simgear/props/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ set(SOURCES props.cxx propertyObject.cxx)

set(HEADERS props.hxx propertyObject.hxx)

add_full_path_name(PROPS_SRC "${SOURCES}")
add_full_path_name(PROPS_HDR "${HEADERS}")
add_library(Properties OBJECT ${HEADERS} ${SOURCES})

install(FILES ${HEADERS} DESTINATION include/JSBSim/simgear/props COMPONENT devel)
6 changes: 4 additions & 2 deletions src/simgear/xml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ set(SOURCES easyxml.cxx)
set(HEADERS easyxml.hxx)

if(NOT EXPAT_FOUND)
add_definitions("-DHAVE_EXPAT_CONFIG_H")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/simgear/xml)

list(APPEND SOURCES xmlparse.c
xmltok.c
xmlrole.c)
Expand All @@ -22,7 +25,6 @@ if(NOT EXPAT_FOUND)
expat_config.h)
endif()

add_full_path_name(XML_SRC "${SOURCES}")
add_full_path_name(XML_HDR "${HEADERS}")
add_library(Xml OBJECT ${HEADERS} ${SOURCES})

install(FILES ${HEADERS} DESTINATION include/JSBSim/simgear/xml COMPONENT devel)

0 comments on commit 7064b29

Please sign in to comment.