Skip to content

Commit

Permalink
Replace CMAKE_SOURCE_DIR with PROJECT_SOURCE_DIR instead (JSBSim…
Browse files Browse the repository at this point in the history
…-Team#689).

This allows embedding JSBSim into a higher level repository where JSBSim is not at the highest CMAKE level. This supports use cases such as CMAKE FetchContent.

Resolves JSBSim-Team#684
  • Loading branch information
Aaron-SP authored Jul 29, 2022
1 parent 16bb270 commit 3f939fa
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 41 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if(BUILD_DOCS)
find_package(Doxygen)
if(DOXYGEN_FOUND)
execute_process(COMMAND date "+%d %b %Y" OUTPUT_VARIABLE TODAY OUTPUT_STRIP_TRAILING_WHITESPACE)
configure_file(${CMAKE_SOURCE_DIR}/doc/JSBSim.dox.in
configure_file(${PROJECT_SOURCE_DIR}/doc/JSBSim.dox.in
${CMAKE_BINARY_DIR}/Doxyfile @ONLY)
if(NOT EXISTS ${CMAKE_BINARY_DIR}/documentation/xml)
execute_process(COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile
Expand All @@ -68,7 +68,7 @@ option(BUILD_PYTHON_MODULE "Set to ON to build the Python module for JSBSim" ON)
option(INSTALL_JSBSIM_PYTHON_MODULE "Set to ON to install the Python module for JSBSim" OFF)

if (BUILD_PYTHON_MODULE)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/python/CMakeModules)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/python/CMakeModules)
find_package(Cython)

if (CYTHON_FOUND)
Expand Down Expand Up @@ -111,7 +111,7 @@ endif(BUILD_MATLAB_SFUNCTION)
find_package(CxxTest)

if (CXXTEST_FOUND)
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${PROJECT_SOURCE_DIR}/src)
enable_testing()
add_subdirectory(tests/unit_tests)
endif(CXXTEST_FOUND)
Expand Down Expand Up @@ -239,7 +239,7 @@ endif()
################################################################################

if(WIN32)
configure_file(${CMAKE_SOURCE_DIR}/JSBSim.iss.in JSBSim.iss)
configure_file(${PROJECT_SOURCE_DIR}/JSBSim.iss.in JSBSim.iss)
endif()

################################################################################
Expand Down
36 changes: 18 additions & 18 deletions JSBSim.iss.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ AppPublisherURL=https://github.com/JSBSim-Team/jsbsim
DefaultDirName={sd}\JSBSim
OutputBaseFilename=JSBSim-${PROJECT_VERSION}-$ENV{GITHUB_RUN_NUMBER}-setup
AlwaysShowDirOnReadyPage=yes
LicenseFile=${CMAKE_SOURCE_DIR}\COPYING
LicenseFile=${PROJECT_SOURCE_DIR}\COPYING
WizardStyle=modern
WizardImageStretch=no
WizardImageFile=logos\*.bmp
Expand All @@ -21,24 +21,24 @@ Name: "devfiles\matlab"; Description: "Files to build a JSBSim S-Function for Ma

[Files]
Source: "${CMAKE_BINARY_DIR}\src\JSBSim.exe"; DestDir: "{app}"; Components: JSBSim
Source: "${CMAKE_SOURCE_DIR}\COPYING"; DestDir: "{app}"; DestName: JSBSim-LICENSE.txt; Components: JSBSim
Source: "${CMAKE_SOURCE_DIR}\src\simgear\xml\COPYING"; DestDir: "{app}"; DestName: libexpat-LICENSE.txt; Components: JSBSim
Source: "${CMAKE_SOURCE_DIR}\src\GeographicLib\LICENSE.txt"; DestDir: "{app}"; DestName: GeographicLib-LICENSE.txt; Components: JSBSim
Source: "${PROJECT_SOURCE_DIR}\COPYING"; DestDir: "{app}"; DestName: JSBSim-LICENSE.txt; Components: JSBSim
Source: "${PROJECT_SOURCE_DIR}\src\simgear\xml\COPYING"; DestDir: "{app}"; DestName: libexpat-LICENSE.txt; Components: JSBSim
Source: "${PROJECT_SOURCE_DIR}\src\GeographicLib\LICENSE.txt"; DestDir: "{app}"; DestName: GeographicLib-LICENSE.txt; Components: JSBSim
Source: "${CMAKE_BINARY_DIR}\utils\aeromatic++\aeromatic.exe"; DestDir: "{app}\aeromatic++"; Components: aeromatic
Source: "${CMAKE_BINARY_DIR}\msvcp*.dll"; DestDir: "{app}"; Components: JSBSim aeromatic
Source: "${CMAKE_SOURCE_DIR}\aircraft\*.xml"; DestDir: "{app}\aircraft"; Flags: recursesubdirs; Components: data
Source: "${CMAKE_SOURCE_DIR}\data_output\*.xml"; DestDir: "{app}\data_output"; Components: data
Source: "${CMAKE_SOURCE_DIR}\engine\*.xml"; DestDir: "{app}\engine"; Components: data
Source: "${CMAKE_SOURCE_DIR}\scripts\*.xml"; DestDir: "{app}\scripts"; Components: data
Source: "${CMAKE_SOURCE_DIR}\systems\*.xml"; DestDir: "{app}\systems"; Components: data
Source: "${CMAKE_SOURCE_DIR}\utils\aeromatic++\samples\*.param"; DestDir: "{app}\aeromatic++\samples"; Components: aeromatic/samples
Source: "${PROJECT_SOURCE_DIR}\aircraft\*.xml"; DestDir: "{app}\aircraft"; Flags: recursesubdirs; Components: data
Source: "${PROJECT_SOURCE_DIR}\data_output\*.xml"; DestDir: "{app}\data_output"; Components: data
Source: "${PROJECT_SOURCE_DIR}\engine\*.xml"; DestDir: "{app}\engine"; Components: data
Source: "${PROJECT_SOURCE_DIR}\scripts\*.xml"; DestDir: "{app}\scripts"; Components: data
Source: "${PROJECT_SOURCE_DIR}\systems\*.xml"; DestDir: "{app}\systems"; Components: data
Source: "${PROJECT_SOURCE_DIR}\utils\aeromatic++\samples\*.param"; DestDir: "{app}\aeromatic++\samples"; Components: aeromatic/samples
Source: "${CMAKE_BINARY_DIR}\src\JSBSim.lib"; DestDir: "{app}\lib"; Components: devfiles
Source: "${CMAKE_SOURCE_DIR}\src\*.h"; DestDir: "{app}\include"; Flags: recursesubdirs; Components: devfiles
Source: "${CMAKE_SOURCE_DIR}\src\*.hxx"; DestDir: "{app}\include"; Flags: recursesubdirs; Components: devfiles
Source: "${CMAKE_SOURCE_DIR}\matlab\*.cpp"; DestDir: "{app}\matlab"; Components: devfiles\matlab
Source: "${CMAKE_SOURCE_DIR}\matlab\*.h"; DestDir: "{app}\matlab"; Components: devfiles\matlab
Source: "${PROJECT_SOURCE_DIR}\src\*.h"; DestDir: "{app}\include"; Flags: recursesubdirs; Components: devfiles
Source: "${PROJECT_SOURCE_DIR}\src\*.hxx"; DestDir: "{app}\include"; Flags: recursesubdirs; Components: devfiles
Source: "${PROJECT_SOURCE_DIR}\matlab\*.cpp"; DestDir: "{app}\matlab"; Components: devfiles\matlab
Source: "${PROJECT_SOURCE_DIR}\matlab\*.h"; DestDir: "{app}\matlab"; Components: devfiles\matlab
Source: "${CMAKE_BINARY_DIR}\matlab\JSBSimSimulinkCompile.m"; DestDir: "{app}\matlab"; Components: devfiles\matlab
Source: "${CMAKE_SOURCE_DIR}\matlab\TestJSBSim.m"; DestDir: "{app}\matlab"; Components: devfiles\matlab
Source: "${CMAKE_SOURCE_DIR}\matlab\ex737cruise.slx"; DestDir: "{app}\matlab"; Components: devfiles\matlab
Source: "${CMAKE_SOURCE_DIR}\matlab\README.md"; DestDir: "{app}\matlab"; Components: devfiles\matlab
Source: "${CMAKE_SOURCE_DIR}\matlab\LICENSE.txt"; DestDir: "{app}\matlab"; Components: devfiles\matlab
Source: "${PROJECT_SOURCE_DIR}\matlab\TestJSBSim.m"; DestDir: "{app}\matlab"; Components: devfiles\matlab
Source: "${PROJECT_SOURCE_DIR}\matlab\ex737cruise.slx"; DestDir: "{app}\matlab"; Components: devfiles\matlab
Source: "${PROJECT_SOURCE_DIR}\matlab\README.md"; DestDir: "{app}\matlab"; Components: devfiles\matlab
Source: "${PROJECT_SOURCE_DIR}\matlab\LICENSE.txt"; DestDir: "{app}\matlab"; Components: devfiles\matlab
2 changes: 1 addition & 1 deletion doc/python/sphinx/conf.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ html_static_path = []
# 'searchbox.html']``.
#
# html_sidebars = {}
html_logo = "${CMAKE_SOURCE_DIR}/doc/logo_JSBSIM_globe.png"
html_logo = "${PROJECT_SOURCE_DIR}/doc/logo_JSBSIM_globe.png"


# -- Options for HTMLHelp output ---------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion julia/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ set(CMAKE_CXX_STANDARD 14)
find_package(JlCxx) # May modify CMAKE_CXX_STANDARD thus called after set(CMAKE_CXX_STANDARD ...)

if(Julia_FOUND)
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${PROJECT_SOURCE_DIR}/src)

add_library(JSBSimJL SHARED jsbsimjl.cpp)
target_link_libraries(JSBSimJL libJSBSim JlCxx::cxxwrap_julia)
Expand Down
2 changes: 1 addition & 1 deletion matlab/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if(Matlab_FOUND)

# Build the mex file.
matlab_add_mex(NAME JSBSim_SFunction SRC ${SOURCES} LINK_TO libJSBSim)
target_include_directories(JSBSim_SFunction PUBLIC ${CMAKE_SOURCE_DIR}/src
target_include_directories(JSBSim_SFunction PUBLIC ${PROJECT_SOURCE_DIR}/src
${Matlab_ROOT_DIR}/simulink/include)
set_target_properties(JSBSim_SFunction PROPERTIES CXX_STANDARD 14)

Expand Down
26 changes: 13 additions & 13 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(JSBSIM_PYX ${CMAKE_CURRENT_BINARY_DIR}/jsbsim.pyx)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/jsbsim.pyx.in ${JSBSIM_PYX})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/jsbsim.pxd ${CMAKE_CURRENT_BINARY_DIR}/jsbsim.pxd COPYONLY)
set_source_files_properties(${JSBSIM_PYX} PROPERTIES CYTHON_IS_CXX TRUE
INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/src)
INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}/src)

# Autogenerate the Python module doc strings from Doxygen docs
if(DOXYGEN_FOUND AND BUILD_DOCS)
Expand All @@ -16,9 +16,9 @@ if(DOXYGEN_FOUND AND BUILD_DOCS)
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

# Prepare the sphinx build files
configure_file(${CMAKE_SOURCE_DIR}/doc/python/sphinx/conf.py.in
configure_file(${PROJECT_SOURCE_DIR}/doc/python/sphinx/conf.py.in
${CMAKE_BINARY_DIR}/documentation/conf.py)
file(COPY ${CMAKE_SOURCE_DIR}/doc/python/sphinx/index.rst
file(COPY ${PROJECT_SOURCE_DIR}/doc/python/sphinx/index.rst
DESTINATION ${CMAKE_BINARY_DIR}/documentation)
endif(DOXYGEN_FOUND AND BUILD_DOCS)

Expand All @@ -38,15 +38,15 @@ endif(MSVC)
cmake_policy(SET CMP0051 NEW)
get_target_property(libJSBSim_SOURCE_FILES libJSBSim SOURCES)
get_target_property(libJSBSim_DIRECTORY libJSBSim TARGET_DIRECTORY)
file(RELATIVE_PATH libJSBSim_PATH ${CMAKE_SOURCE_DIR} ${libJSBSim_DIRECTORY})
file(RELATIVE_PATH libJSBSim_PATH ${PROJECT_SOURCE_DIR} ${libJSBSim_DIRECTORY})

file(COPY ${CMAKE_SOURCE_DIR}/README.md DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${CMAKE_SOURCE_DIR}/COPYING DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${CMAKE_SOURCE_DIR}/src/GeographicLib/LICENSE.txt DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${PROJECT_SOURCE_DIR}/README.md DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${PROJECT_SOURCE_DIR}/COPYING DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${PROJECT_SOURCE_DIR}/src/GeographicLib/LICENSE.txt DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt ${CMAKE_CURRENT_BINARY_DIR}/GeographicLib-LICENSE.txt)
file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/COPYING ${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt)

set(SIMGEAR_XML_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src/simgear/xml)
set(SIMGEAR_XML_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src/simgear/xml)
file(COPY ${SIMGEAR_XML_SOURCE_DIR}/COPYING DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/COPYING ${CMAKE_CURRENT_BINARY_DIR}/libexpat-LICENSE.txt)
configure_file(${SIMGEAR_XML_SOURCE_DIR}/xmltok_impl.c
Expand All @@ -60,10 +60,10 @@ endforeach()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/JSBSim.py ${CMAKE_CURRENT_BINARY_DIR}/JSBSim COPYONLY)

# Duplicate data files (i.e. aircraft, engines, etc.)
file(COPY ${CMAKE_SOURCE_DIR}/aircraft DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data)
file(COPY ${CMAKE_SOURCE_DIR}/engine DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data)
file(COPY ${CMAKE_SOURCE_DIR}/systems DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data)
file(COPY ${CMAKE_SOURCE_DIR}/scripts DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data)
file(COPY ${PROJECT_SOURCE_DIR}/aircraft DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data)
file(COPY ${PROJECT_SOURCE_DIR}/engine DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data)
file(COPY ${PROJECT_SOURCE_DIR}/systems DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data)
file(COPY ${PROJECT_SOURCE_DIR}/scripts DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data)

# Copy each source file
foreach(OBJECT ${libJSBSim_SOURCE_FILES})
Expand All @@ -74,7 +74,7 @@ foreach(OBJECT ${libJSBSim_SOURCE_FILES})
string(SUBSTRING ${OBJECT} 17 ${TARGET_LENGTH} TARGET)
get_target_property(TARGET_SOURCE_FILES ${TARGET} SOURCES)
get_target_property(TARGET_SOURCE_DIRECTORY ${TARGET} TARGET_DIRECTORY)
file(RELATIVE_PATH TARGET_PATH ${CMAKE_SOURCE_DIR} ${TARGET_SOURCE_DIRECTORY})
file(RELATIVE_PATH TARGET_PATH ${PROJECT_SOURCE_DIR} ${TARGET_SOURCE_DIRECTORY})
file(MAKE_DIRECTORY ${TARGET_PATH})
foreach(_FILE ${TARGET_SOURCE_FILES})
configure_file(${TARGET_SOURCE_DIRECTORY}/${_FILE} ${TARGET_PATH}/${_FILE} COPYONLY)
Expand Down
4 changes: 2 additions & 2 deletions python/fpectl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ else()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/fpectl_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/fpectl_config.h)
set(SETUP_PY ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in ${SETUP_PY})
execute_process(COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/python/findModuleFileName.py fpectl OUTPUT_VARIABLE FPECTL_MODULE_NAME)
execute_process(COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/python/findModuleFileName.py fpectl OUTPUT_VARIABLE FPECTL_MODULE_NAME)
set(FPECTL_PYTHON_MODULE ${CMAKE_BINARY_DIR}/tests/${FPECTL_MODULE_NAME})

add_custom_command(OUTPUT ${FPECTL_PYTHON_MODULE}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/fpectlmodule.h ${CMAKE_CURRENT_SOURCE_DIR}/fpectlmodule.cpp ${CMAKE_SOURCE_DIR}/python/ExceptionManagement.h
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/fpectlmodule.h ${CMAKE_CURRENT_SOURCE_DIR}/fpectlmodule.cpp ${PROJECT_SOURCE_DIR}/python/ExceptionManagement.h
COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} build_ext -b ${CMAKE_BINARY_DIR}/tests
COMMENT "Building fpectl module...")

Expand Down
2 changes: 1 addition & 1 deletion python/setup.py.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This script has been automatically built from ${CMAKE_SOURCE_DIR}/python/setup.py.in
# This script has been automatically built from ${PROJECT_SOURCE_DIR}/python/setup.py.in
#
# Copyright (c) 2014-2022 Bertrand Coconnier
#
Expand Down

0 comments on commit 3f939fa

Please sign in to comment.