mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
docs: add guide on integrating CMake (#2410)
Taken from TheAlgorithms/C#1163
This commit is contained in:
parent
18f6cef2ad
commit
582cdc7cc4
@ -134,7 +134,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
```
|
||||
|
||||
#### New File Name guidelines
|
||||
#### File Name guidelines
|
||||
|
||||
- Use lowercase words with ``"_"`` as a separator
|
||||
- For instance
|
||||
@ -148,7 +148,7 @@ my_new_cpp_class.cpp is correct format
|
||||
- File name validation will run on Docker to ensure validity.
|
||||
- If an implementation of the algorithm already exists and your version is different from that implemented, please use incremental numeric digit as a suffix. For example: if `median_search.cpp` already exists in the `search` folder, and you are contributing a new implementation, the filename should be `median_search2.cpp`. For a third implementation, `median_search3.cpp`, and so on.
|
||||
|
||||
#### New Directory guidelines
|
||||
#### Directory guidelines
|
||||
|
||||
- We recommend adding files to existing directories as much as possible.
|
||||
- Use lowercase words with ``"_"`` as separator ( no spaces or ```"-"``` allowed )
|
||||
@ -162,6 +162,40 @@ some_new_fancy_category is correct
|
||||
- Filepaths will be used to dynamically create a directory of our algorithms.
|
||||
- Filepath validation will run on GitHub Actions to ensure compliance.
|
||||
|
||||
##### Integrating CMake in a new directory
|
||||
|
||||
In case a new directory is 100% required, `CMakeLists.txt` file in the root directory needs to be updated, and a new `CMakeLists.txt` file needs to be created within the new directory.
|
||||
|
||||
An example of how your new `CMakeLists.txt` file should look like. Note that if there are any extra libraries/setup required, you must include that in this file as well.
|
||||
|
||||
```cmake
|
||||
# If necessary, use the RELATIVE flag, otherwise each source file may be listed
|
||||
# with full pathname. The RELATIVE flag makes it easier to extract an executable's name
|
||||
# automatically.
|
||||
|
||||
file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp )
|
||||
foreach( testsourcefile ${APP_SOURCES} )
|
||||
string( REPLACE ".cpp" "" testname ${testsourcefile} ) # File type. Example: `.cpp`
|
||||
add_executable( ${testname} ${testsourcefile} )
|
||||
|
||||
set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX)
|
||||
if(OpenMP_CXX_FOUND)
|
||||
target_link_libraries(${testname} OpenMP::OpenMP_CXX)
|
||||
endif()
|
||||
install(TARGETS ${testname} DESTINATION "bin/<foldername>") # Folder name. Do NOT include `<>`
|
||||
|
||||
endforeach( testsourcefile ${APP_SOURCES} )
|
||||
```
|
||||
|
||||
The `CMakeLists.txt` file in the root directory should be updated to include the new directory.\
|
||||
Include your new directory after the last subdirectory. Example:
|
||||
|
||||
```cmake
|
||||
...
|
||||
add_subdirectory(divide_and_conquer)
|
||||
add_subdirectory(<foldername>)
|
||||
```
|
||||
|
||||
#### Commit Guidelines
|
||||
|
||||
- It is recommended to keep your changes grouped logically within individual commits. Maintainers find it easier to understand changes that are logically spilled across multiple commits. Try to modify just one or two files in the same directory. Pull requests that span multiple directories are often rejected.
|
||||
|
Loading…
Reference in New Issue
Block a user